转载自:
Android Gradle配置
编译加速
在gradle.properties
中配置
1 org.gradle.configureondemand=true #demand2 org.gradle.daemon=true #单独的守护进程3 org.gradle.parallel=true #串行编译4 org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 #内存设置
build.gradle
中添加
1 lintOptions { 2 disable 'InvalidPackage', 'ContentDescription' 3 abortOnError false 4 } 5 6 dexOptions { 7 jumboMode = true 8 preDexLibraries = false 9 javaMaxHeapSize "4g"10 }
只支持特定abi
abiFilters
配置,可配合Product flavors
使用。
1 ndk {2 abiFilters "armeabi", "x86"3 }
依赖库版本管理
在项目工程build.gradle
中统一定义
1 ext { 2 // Sdk and tools 3 minSdkVersion = 10 4 targetSdkVersion = 22 5 compileSdkVersion = 23 6 buildToolsVersion = '23.0.2' 7 8 // App dependencies 9 supportVersion = '23.4.0'10 }
在模块工程build.gradle
使用
1 android { 2 compileSdkVersion rootProject.ext.compileSdkVersion 3 buildToolsVersion rootProject.ext.buildToolsVersion 4 } 5 6 dependencies { 7 // App's dependencies, including test 8 compile "com.android.support:appcompat-v7:$rootProject.supportVersion" 9 compile "com.android.support:cardview-v7:$rootProject.supportVersion"10 compile "com.android.support:design:$rootProject.supportVersion"11 compile "com.android.support:recyclerview-v7:$rootProject.supportVersion"12 compile "com.android.support:support-v4:$rootProject.supportVersion"13 }
依赖库多版本解决
1 configurations.all {2 resolutionStrategy.force "com.android.support:support-v4:$rootProject.supportVersion"3 }
签名信息
项目中添加sign.properties
1 keystore=[path to]\release.keystore2 keystore.password=*********3 keyAlias=***********4 keyPassword=********
在build.gradle
读取文件并设置签名信息
1 if(new File(project.property("sign.properties")).exists()) { 2 3 Properties props = new Properties() 4 props.load(new FileInputStream(file(project.property("sign.properties")))) 5 6 signingConfigs { 7 release { 8 storeFile file(props['keystore']) 9 storePassword props['keystore.password']10 keyAlias props['keyAlias']11 keyPassword props['keyPassword']12 }13 }14 }