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

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

问题描述

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

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 Exception 所以我添加了以下内容:

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.添加了productFlavors {开发{minSdk 版本 21}产品{minSdk 版本 14}}

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

  1. dexOptions {preDexLibraries falsejavaMaxHeapSize "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天全站免登陆