android Studio 加快编译速度(2017-06-21版)
来源:互联网 发布:酒吧烟花在淘宝怎么买 编辑:程序博客网 时间:2024/06/17 18:24
加快Android studio编译速度的建议,长期进行整理 如下:
1. 使用最新的Android gradle插件
Google tools team一直致力于加快Android studio的编译速度,因此最好使用最新的Android Gradle Plugin:
buildscript { repositories { google() } dependencies { classpath ‘com.android.tools.build.gradle:3.0.0-alpha3’ }}
2. 避免使用multidex
我们知道当方法书超过64k时,需要配置multidex,但是如果我们的工程minSdkVersion 设置为 20 或更低值,那么构建时间会大大增加,因为构建系统必须就哪些类必须包括在主 DEX 文件中以及哪些类可以包括在辅助 DEX 文件中作出复杂的决策。
这种情况下可以利用 productFlavors(一个开发定制和一个发布定制,具有不同的 minSdkVersion值)创建两个构建变型。
android { defaultConfig { ... multiDexEnabled true } productFlavors { dev { // Enable pre-dexing to produce an APK that can be tested on // Android 5.0+ without the time-consuming DEX build processes. minSdkVersion 21 } prod { // The actual minSdkVersion for the production version. minSdkVersion 14 } } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }}dependencies { compile 'com.android.support:multidex:1.0.1'}
3. 减少打包的资源文件
在开发模式下,可以只打包需要的资源,不必适配所有的资源文件:
productFlavors { dev { minSdkVersion 21 //only package english translations, and xxhdpi resources resConfigs (“en”, “xxhdpi”) }}
4. 禁用 PNG 处理
PNG优化在默认情况下是打开的,我们可以在开发模式下禁用:
android { if (project.hasProperty(‘devBuild’)){ aaptOptions.cruncherEnabled = false }}
5. 使用Instant run
Instant Run在android studio 3.0中有了很多的改进,可以尝试使用。
6. 不要随便修改配置
Gradle使用非常灵活,但是如果不正确的使用反而会降低编译速度。比如:
//this is BAD! 这种做法会导致每次编译 manifest文件都需要被修改,造成不必要的编译时间增加def buildDateTime = new Date().format(‘yyMMddHHmm’).toInteger()android { defaultConfig { versionCode buildDateTime }}
正确的做法是:
def buildDateTime = project.hasProperty(‘devBuild’) ? 100 : new Date().format(‘yyMMddHHmm’).toInteger()android { defaultConfig { versionCode buildDateTime }}
7. 避免使用动态版本依赖
一般使用固定版本依赖即可。
8. 注意内存使用
要注意分配给Gradle的内存使用:
目前配置
org.gradle.jvmargs=-Xmx1536m
即可,不必再配置:
dexOptions { javaMaxHeapSize = ‘4g’}
9. 使用Gradle caching
在Gradle 3.5中,使用cache可以缓存并重复利用之前builds的生成的文件。
# Set this in gradle.propertiesorg.gradle.caching=true
10. 尽量减少apk的垃圾文件和垃圾方法png 使用 tinypng 优化11. 如果条件可以,请使用插件化 或者使用多application进行分拆12. 导入外部项目尽量导入aar包
阅读全文
0 0
- android Studio 加快编译速度(2017-06-21版)
- android studio加快编译速度
- Android Studio 加快编译速度
- 加快android studio 编译速度
- 加快Android Studio 编译速度
- 加快android studio 编译速度
- Android studio加快编译速度
- 如何加快Android Studio的编译速度
- 加快Android Studio的编译速度
- 加快Android Studio的编译速度
- Android Studio配置,加快编译速度
- Android Studio开启"DexInProcess"加快编译速度
- Android Studio配置,加快编译速度
- 加快Android Studio的编译速度
- 加快Android编译速度
- android加快编译速度
- 加快Android编译速度
- 加快Android编译速度
- Python:MECARD字符串转json
- 微信分享
- 百度地图的集成过程
- iOS
- 统计胜负
- android Studio 加快编译速度(2017-06-21版)
- 传统的操作数据库的主要步骤
- kali2.0 metasploit安装xssf模块
- SFML 与 VS2015 的安装配置
- DBN
- Android Studio JNI 初体验
- was访问ip 直接跳转至应用地址
- 深度学习caffe的代码怎么读?
- 2017-06-20 Gbase8t Create Table