码迷,mamicode.com
首页 > 移动开发 > 详细

Android Gradle 配置 [转]

时间:2016-08-19 06:12:57      阅读:324      评论:0      收藏:1      [点我收藏+]

标签:

转载自:http://pybeta.com/2016/06/about-gradle/

Android Gradle配置

编译加速

gradle.properties中配置

1 org.gradle.configureondemand=true               #demand
2 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.keystore
2 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 }

 

Android Gradle 配置 [转]

标签:

原文地址:http://www.cnblogs.com/aegealee/p/5747798.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!