gradle - Android Studio构建太慢的multidex应用程序 [英] gradle - Android Studio build too slow multidex application

查看:434
本文介绍了gradle - Android Studio构建太慢的multidex应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将multidex:true添加到我的项目中,并创建一个从MultiDexApplication扩展的Application类时,我的项目构建时间从20秒过渡到90秒左右。如何更快地完成一些操作?

解决方案

如果您和我一样已经尝试过Vic Vu的解决方案,但仍无法避免启用multiDex,那么您可以尝试此操作(只要您正在使用Android 5.0及以上版本的设备)。



注意这只会加速开发版本的建立。基本上你需要为 dev 引入两种产品风格,一种用于



添加 multiDexEnabled true

  android {
productFlavors {
//定义单独的dev和prod产品风格。
dev {
// dev使用minSDKVersion = 21允许Android gradle插件
//预先分配每个模块并生成一个可以在
//上测试的APK Android Lollipop没有耗时的dex合并过程。
minSdkVersion 21
}
prod {
//应用程序的实际minSdkVersion。
minSdkVersion 14
}
}
...
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard -android.txt'),
'proguard-rules.pro'
}
defaultConfig {
applicationIdcom.something.something
targetSdkVersion 23
versionCode 1
versionName1.0.0

multiDexEnabled true
}
}
依赖项{
compile'c​​om.android.support :multidex:1.0.1'
}

我有一个扩展 Application 因此我必须重载 attachBaseContext()

  @Override 
protected void attachBaseContext(Context base){
super.attachBaseContext(base);
MultiDex.install(this);

$ / code>

如果您没有扩展 Application 在您的 AndroidManifest.xml 应用程序 MultiDexApplication >标记。



确保在Android Studio Build Variants 中指向 devDebug



阅读此处的完整说明 https://developer.android.com/studio/build/multidex.html#dev-build


When I add to my project the multidex:true, and make an Application class that extends from the MultiDexApplication, my project build time passed from 20 sec to around 90 sec.How to do some faster?

解决方案

If you are like me who already tried Vic Vu's solution but still can't avoid enabling multiDex then you can try this (as long as your are using a device that has Android 5.0 and above).

Note This will only speed up your development build. Your production build will still be slow.

Basically you need to introduce 2 product flavors one for dev and one for prod.

Add multiDexEnabled true

android {
    productFlavors {
        // Define separate dev and prod product flavors.
        dev {
            // dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
            // to pre-dex each module and produce an APK that can be tested on
            // Android Lollipop without time consuming dex merging processes.
            minSdkVersion 21
        }
        prod {
            // The actual minSdkVersion for the application.
            minSdkVersion 14
        }
    }
          ...
    buildTypes {
        release {
            runProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                                                 'proguard-rules.pro'
        }
        defaultConfig {
            applicationId "com.something.something"
            targetSdkVersion 23
            versionCode 1
            versionName "1.0.0"

            multiDexEnabled true
        }
    }
dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

And I have a class which extends Application so I had to override attachBaseContext()

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

If you are not extending Application simply use MultiDexApplication in your AndroidManifest.xml application tag.

Ensure that in your Android Studio Build Variants you are pointing to devDebug.

Read the complete instructions here https://developer.android.com/studio/build/multidex.html#dev-build

这篇关于gradle - Android Studio构建太慢的multidex应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆