Android Studio 2.0 稳定,应用启动变慢

标签 android android-studio

我使用的是 Android studio 1.5,运行良好(不是那么快)。今天我将它更新到 2.0 稳定版,现在第一次启动需要 2-3 分钟。第一次启动后我检查应用程序信息屏幕,我看到第一个有 41MB(因设备而异)缓存开始。我不知道发生了什么事。这是我的 gradle 文件

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    packagingOptions {


        exclude 'META-INF/NOTICE'

        exclude 'META-INF/LICENSE'

        exclude 'META-INF/DEPENDENCIES'

        exclude 'META-INF/DEPENDENCIES.txt'

        exclude 'META-INF/LICENSE.txt'

        exclude 'META-INF/NOTICE.txt'
    }
    sourceSets {
        main.jniLibs.srcDirs = ['libs']
    }



    defaultConfig {
        applicationId "com.my.app"
        minSdkVersion 17
        targetSdkVersion 21
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false;
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

    }
    dexOptions {
        preDexLibraries = false
        javaMaxHeapSize "2g"
    }


}


dependencies {

    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile project(':volley')
    compile project(':android-country-picker-master')
    compile project(':viewPagerIndicator')


    compile ('com.android.support:design:23.1.1') {
        exclude module: 'support-v4'
    }
    compile ('com.google.code.gson:gson:2.5'){
        exclude module: 'support-v4'
    }
    compile ('com.squareup.picasso:picasso:2.5.0'){
        exclude module: 'support-v4'
    }
    compile ('pl.droidsonroids.gif:android-gif-drawable:1.1.10'){
        exclude module: 'support-v4'
    }
    compile ('javax.annotation:javax.annotation-api:1.2'){
        exclude module: 'support-v4'
    }
    compile ('com.google.android.gms:play-services:8.4.0') {
        exclude module: 'support-v4'
    }
    compile ('com.squareup.retrofit:retrofit:1.9.0'){
        exclude module: 'support-v4'
    }
    compile ('com.squareup.okhttp:okhttp:2.4.0'){
        exclude module: 'support-v4'
    }
    compile 'org.apache.httpcomponents:httpclient:4.5.1'
    compile 'org.apache.httpcomponents:httpmime:4.3.6'
    compile ('com.google.guava:guava:18.0') {
        exclude module: 'support-v4'
    }
    compile ('org.apache.commons:commons-lang3:3.4'){
        exclude module: 'support-v4'
    }

}

如有任何帮助,将不胜感激,谢谢

最佳答案

如此处所述:http://tools.android.com/tech-docs/instant-run

When using Instant Run with a project configured for Legacy Multidex—that is, when build.gradle is configured withmultiDexEnabled true and minSdkVersion 20 or lower—build performance may decrease when deploying a clean build to target devices running Android 5.0 (API level 21) or higher.

[..] To improve clean build performance during development, consider creating a product flavor withminSdkVersion 21.

尝试在你的 gradle 中实现它

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

}
dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

关于Android Studio 2.0 稳定,应用启动变慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36496217/

相关文章:

android - 如何通过 USB 将 SecuGen 指纹扫描仪集成到 Android 应用程序中

java - API 29 java android 中不推荐使用 getBitmap

android - 无法从主 Activity 中的 onActivityResult 方法启动新 Activity

java - Android 中使用自定义 View 的加载动画

android - 如何将 EditText 放置在 Android 屏幕上的特定像素中?

android - 来自 androidx.core :core:1. 0.0 和 com.android.support :support-compat:26. 1.0 的重复类

java - Android Studio-ClassCastException 错误?

java - ArrayAdapter要求资源ID为DialogFragment中的TextView

java - NDK 解析结果 : Project settings: Gradle model version=5. 1.1,NDK 版本未知

java - Android Studio 3.5.1 中出现什么类型的问题?