Gradle for Android(一)基本配置、依赖管理
来源:互联网 发布:汽车导航一体机端口 编辑:程序博客网 时间:2024/04/30 11:21
Gradle是一种基于Groovy的动态DSL,而Groovy语言是一种基于jvm的动态语言。这里只分享实际开发中会用到的场景,您不需要去学习Groovy语言,知道Java的您是很容易阅读Groovy语言的。
系列博客涉及的知识点有:Gradle基本配置、依赖管理、全局设置、自定义BuildConfig、混淆、多渠道打包、配置签名信息、单元测试,是不是迫不及待了啊,快来学习学习。
基本配置
新建项目,目录结构如下:
app/build.gradle
初始化的Gradle配置:
apply plugin: 'com.android.application'android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.wuxiaolong.gradle4android" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }}dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.2.1' compile 'com.android.support:design:23.2.1'}
apply plugin: ‘com.android.application’,表示该module是一个app module,应用了com.android.application插件,如果是一个android library,那么这里写apply plugin: ‘com.android.library’compileSdkVersion:基于哪个SDK编译,这里是API LEVELbuildToolsVersion:基于哪个构建工具版本进行构建的。defaultConfig:默认配置,如果没有其他的配置覆盖,就会使用这里的。applicationId:配置包名的versionCode:版本号versionName:版本名称buildTypes是构建类型,常用的有release和debug两种,可以在这里面启用混淆,启用zipAlign以及配置签名信息等。dependencies:不属于Android专有的配置了,它定义了该module需要依赖的jar,aar,jcenter库信息。
gradle-wrapper.properties
声明了gradle的目录与下载路径以及当前项目使用的gradle版本,这些默认的路径我们一般不会更改的
12345
distributionBase=GRADLE_USER_HOMEdistributionPath=wrapper/distszipStoreBase=GRADLE_USER_HOMEzipStorePath=wrapper/distsdistributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
根目录的build.gradle
定义在这个工程下的所有模块的公共属性
123456789101112131415161718192021
buildscript { repositories { jcenter()//使用jcenter库 } dependencies { classpath 'com.android.tools.build:gradle:1.5.0'// 依赖android提供的1.5.0的gradle build // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }}//为所有的工程的repositories配置为jcentersallprojects { repositories { jcenter() }}task clean(type: Delete) { delete rootProject.buildDir}
setting.gradle
包含哪些模块,比如有app和library:
1
include ':app',':library'
依赖管理
本地依赖
jar
默认情况下,新建的Android项目会有一个lib文件夹
1234
dependencies { compile fileTree(dir: 'libs', include: ['*.jar'])//即添加所有在libs文件夹中的jar //compile files('libs/WuXiaolong.jar')//不需要这样一个个去写了}
so包
用c或者c++写的library会被叫做so包,Android插件默认情况下支持native包,你需要把.so文件放在对应的文件夹中
1234567891011
app ├── AndroidManifest.xml └── jniLibs ├── armeabi │ └── WuXiaolong.so ├── armeabi-v7a │ └── WuXiaolong.so ├── mips │ └── WuXiaolong.so └── x86 └── WuXiaolong.so
aar文件
library库输出文件是.aar文件,在library工程build/output/aar/下
直接依赖library
1234
dependencies { compile project(':library名字') compile project(':libraries:library名字')//多个library,libraries是文件夹名字 }
依赖.aar文件
创建一个aars文件夹,然后把.aar文件拷贝到该文件夹里面,然后添加该文件夹作为依赖库:
12345
repositories { flatDir { dirs 'aars' }}
或者:
123
dependencies { compile(name:'libraryname', ext:'aar')}
远程仓库
123
dependencies {compile 'com.wuxiaolong.pullloadmorerecyclerview:library:1.0.4'}
0 0
- Gradle for Android(一)基本配置、依赖管理
- Gradle for Android(一)基本配置、依赖管理
- Gradle for Android(一)基本配置、依赖管理
- Gradle for Android(一)基本配置、依赖管理
- Gradle for Android-管理依赖
- Gradle for Android 依赖管理
- Gradle for Android(三)——依赖管理(一)
- Gradle For Android (一) 基础定义与依赖管理篇
- Gradle的基本配置和依赖管理
- Gradle for Android 第三篇( 依赖管理 )
- Gradle for Android 第三篇( 依赖管理 )
- Gradle for Android 第三篇( 依赖管理 )
- Gradle for Android 第三篇( 依赖管理 )
- Gradle for Android 第三章:依赖管理
- Gradle for Android 第三篇( 依赖管理 )
- Gradle for Android 第三篇( 依赖管理 )
- Gradle for Android 第三篇( 依赖管理 )
- Gradle for Android 第三篇( 依赖管理 )
- 整数的分划问题
- 光棍节的快乐
- Python dic 方法汇总
- PHP---Final关键字
- 最小生成树算法—Prim和克鲁斯卡尔
- Gradle for Android(一)基本配置、依赖管理
- svn上传个别文件被拒原因
- 给UITextView 头部插入视图
- STM32——库函数开发小结
- 对于json数据中的图片处理和图片缓存
- 404、500、502等HTTP状态码介绍
- CUDA编程(二) CUDA初始化与核函数
- DL训练遇到不收敛情况分析
- 遇到的问题