【发布时间】:2016-05-18 10:12:53
【问题描述】:
在我的项目中,我使用了需要 multidex 支持的库。根据我所做的研究,我了解到它会导致应用启动延迟。
我在 gradle 中启用了 multidex 功能。 defaultConfig { multiDexEnabled true }
我曾经为 kitkat 设备获得 NoClassDefFound Exception,所以我添加了以下内容:
我在清单中添加了应用程序名称 android:name="android.support.multidex.MultiDexApplication"
并使用 MultiDexApplication 扩展了我的应用程序类。
我知道上面的任何一个都足够了,但我只是写了两个。
我尝试了不同的方法来优化启动持续时间,如下所示:
1.添加产品风味{ 开发{ minSdkVersion 21 } 产品{ minSdkVersion 14 } }
dexOptions { preDexLibraries 错误 javaMaxHeapSize "4g" }
我只导入了所需的 google play 服务的库,而不是导入完整的库。
您能否建议我一种即兴创作持续时间的方法,因为它实际上需要超过 10 秒,有时甚至超过某些设备的时间?
或者除了multidex之外还有其他原因可能导致延迟吗?
提前致谢。
我已经添加了我的 build.gradle 文件内容:
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'
}
【问题讨论】:
-
发布您的
build.gradle -
我能知道被否决的原因吗?这样我就不会再犯错误了。谢谢。
-
@IntelliJAmiya 当我尝试设置 buildToolsVersion 23.2.1 时,它说它无法下载。
-
Android Studio 使用 Gradle(一种高级构建工具包)来自动化和管理构建过程,同时允许您定义灵活的自定义构建配置。在这里你有很多
dependencies这就是为什么慢。没有别的 -
@IntelliJ Amiya - 我将 buildToolsVersion 更改为 23.0.3。仍然需要相同的时间。是的,我明白这一点。但是有没有其他可行的方法来优化它,因为它需要这么多时间才能开始而且用户可能觉得它对用户不友好,这真的很奇怪。
标签: android android-studio android-5.0-lollipop android-multidex