Gradle常见配置结点如下:
android DSL –领域特定语言(domain-specific languages,简称DSL)
defaultConfig{} 默认配置,是ProductFlavor类型。它共享给其他ProductFlavor使用splits{ } Splits类型
android { } 配置了用于 android 构建的所有参数。这是Android DSL的入口。
默认情况下,只需要配置编译目标,以及build-tools的版本。它通过compileSdkVersion和buildtoolsVersion属性来完成。
apply plugin: 'com.android.application' //说明当前module的类型,是应用程序还是依赖库,com.android.application为应用程序,com.android.library为依赖库 android { //编译的SDK版本 compileSdkVersion 24 //编译的Tools版本(编译工具的版本) 其中包括了打包工具aapt、dx等等,这个工具的目录位于..sdk_path/build-tools/XX.XX.XX buildToolsVersion "24.0.1" //android 6.0(api 23) SDK,不再提供org.apache.http.*(只保留几个类) 但是项目中用到了,如何解决? useLibrary 'org.apache.http.legacy' dexOptions { //在dexOptions中有一个字段用来增加java堆内存大小: javaMaxHeapSize "4g" preDexLibraries = false } //默认配置 defaultConfig { //应用程序的包名 applicationId "com.crs.demo" //支持的最低版本14 minSdkVersion 14 //支持的目标版本22 targetSdkVersion 22 //版本号 versionCode 1 //版本名 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" //原生 ndk { abiFilters 'armeabi' } } // java版本 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } //签名配置 signingConfigs { //发行版本签名配置 release { //密钥文件路径 storeFile file("fk.keystore") //密钥文件密码 storePassword "123" //key别名 keyAlias "xunpige" //key密码 keyPassword "123" } //debug版本签名配置 debug { storeFile file("fk.keystore") storePassword "123" keyAlias "xunpige" keyPassword "123" } } //build类型 buildTypes { //发行版 release { //混淆开启 minifyEnabled true //指定混淆规则文件 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' //设置软件签名信息 signingConfig signingConfigs.signConfig } //调试版 debug { signingConfig signingConfigs.signConfig // 配置debug包的签名 } } //为了解决:多个jar包里包含了同样的文件(NOTICE.txt),导致打包时出现相互覆盖问题。 packagingOptions { exclude 'META-INF/NOTICE.txt' exclude 'META-INF/LICENSE.txt' } sourceSets { main { resources.srcDirs = ['src/main/java'] } } // 产品风格配置 productFlavors { xiaomi {} _360 {} baidu {} wandoujia {} //...添加其它渠道 } productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL: name] } lintOptions { //执行lint检查,有任何的错误或者警告提示,都会终止构建,我们可以将其关掉。 abortOnError false } } dependencies { //编译lib目录下的.jar文件 compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:24.0.0' compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha3' testCompile 'junit:junit:4.12' //网络请求框架 compile 'com.squareup.okhttp:okhttp:2.4.0' //数据解析json框架 compile 'com.google.code.gson:gson:2.7' }