Building and running app via Gradle and Android Studio is slower than via Eclipse

前端 未结 28 1912
太阳男子
太阳男子 2020-11-22 08:21

I have a multi-project (~10 modules) of which building takes about 20-30 seconds each time. When I press Run in Android Studio, I have to wait every time to rebuild the app,

28条回答
  •  粉色の甜心
    2020-11-22 08:43

    If using google play services, depending on just the libraries you need instead of the whole blob can make things faster.

    If your only need is maps, use:

    compile 'com.google.android.gms:play-services-maps:6.5.+'
    

    instead of:

    compile 'com.google.android.gms:play-services:6.5.+'
    

    The latter brings 20k methods (see blog) into the classpath, which might tip the total method count over 64k.

    That would force the use of proguard or multidex even for debug builds. For one of my projects i had the following build times

    • multidex build (with supportlibrary) ~40sec
    • proguard build ~20sec
    • build when method limit < 64k ~5sec

    If developing on sdk 21+, it would possible to optimize multidex builds as stated in the android documentation

    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
            }
        }
        ...
    }
    

提交回复
热议问题