Android在首次启动时需要花费更多时间启动应用程序 [英] Android takes more time on application start up during first time launch

查看:105
本文介绍了Android在首次启动时需要花费更多时间启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我使用了需要multidex支持的库.根据我所做的研究,我知道它会导致应用启动过程中的延迟.

In my project, I have used libraries which require multidex support. Based on the research I did, I came to know that it causes delay during app start up.

我已在gradle中启用了multidex功能. defaultConfig {multiDexEnabled true}

I have enabled multidex feature in gradle. defaultConfig { multiDexEnabled true }

我曾经为kitkat设备获取NoClassDefFound异常,所以我添加了以下内容:

I used to get NoClassDefFound Exception for kitkat devices so I added the following:

我已在清单中添加应用程序名称为 android:name ="android.support.multidex.MultiDexApplication"

I have added application name in manifest as android:name="android.support.multidex.MultiDexApplication"

并使用MultiDexApplication扩展了我的应用程序类.

and extended my application class with MultiDexApplication.

我知道以上任何一项都足够,但是我都写了.

I know any one of the above is sufficient but I have just written both.

我尝试了不同的方法来优化启动时间,如下所示:

I tried different ways to optimize the duration of start up like the following :

1.add productFlavors { 开发{ minSdkVersion 21 } 产品{ minSdkVersion 14 } }

1.added productFlavors { dev { minSdkVersion 21 } prod { minSdkVersion 14 } }

  1. dexOptions { preDexLibraries错误 javaMaxHeapSize"4g" }

  1. dexOptions { preDexLibraries false javaMaxHeapSize "4g" }

我仅导入了所需的Google Play服务的库,而不导入了完整的库.

I imported only required google play service's libraries instead of importing full library.

您能建议我一种缩短持续时间的方法吗,因为它实际上花费的时间超过10秒钟,甚至比某些设备所花费的时间还要长?

Can you please suggest me an approach to improvise the duration because its actually taking more than 10 seconds and some times even more than that in some of the devices?

或者除了multidex之外,还有其他原因可能会导致延迟吗?

Or Is there any other reason that might be causing the delay apart from multidex?

谢谢.

我已经添加了build.gradle文件内容:

I have added my build.gradle file contents :

 apply plugin: 'com.android.application'
 apply plugin: 'com.google.gms.google-services'

 android {
  compileSdkVersion 23
  buildToolsVersion "23.0.3"
  useLibrary 'org.apache.http.legacy'

 defaultConfig {
    applicationId "com.example.app"
    minSdkVersion 17
    targetSdkVersion 23
    versionCode 3
    versionName "1.2"
    multiDexEnabled true
}

dexOptions {
    incremental true
    javaMaxHeapSize "10g"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}

  dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/ormlite-android-4.28.jar')
    compile files('libs/ormlite-core-4.28.jar')
    compile project(':volley')
    compile 'com.android.support:cardview-v7:23.2.1'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.github.siyamed:android-shape-imageview:0.9.+@aar'
    compile 'com.viewpagerindicator:library:2.4.1@aar'
    compile 'com.android.support:design:23.2.1'
    compile 'com.facebook.android:facebook-android-sdk:4.1.2'
    compile 'org.jsoup:jsoup:1.8.2'
    compile 'org.twitter4j:twitter4j:4.0.3'
    compile 'com.github.castorflex.smoothprogressbar:library-circular:1.1.0'
    compile 'com.orhanobut:dialogplus:1.11@aar'
    compile 'com.google.android.gms:play-services-maps:8.3.0'
    compile 'co m.google.android.gms:play-services-gcm:8.3.0'
    compile 'com.google.android.gms:play-services-location:8.3.0'
    compile 'org.java-websocket:Java-WebSocket:1.3.0'
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
 }

推荐答案

新发布的Android Studio 2.0或2.1存在一个奇怪的问题.第一次启动应用程序需要比平时更长的时间.仅在调试模式下会发生此问题,而对您发布的APK无效.我也在遭受这个问题并找到了解决方案.

There is a strange issue with newly released Android Studio 2.0 or 2.1. First time of launching application take longer than usual. This issue happens only in debug mode and not effect to your released APK. Also I was suffering this issue and found this solution.

Settings/Preferences(Mac) → Build, Execution, Deployment → Instant Run and uncheck Instant Run

这将解决您的问题,如果是,请标记为可接受的答案.

This will solve your problem and if it is please mark as accepted answer.

这篇关于Android在首次启动时需要花费更多时间启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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