我不知道如何解决 Android 中的 Multidex 问题。我的应用程序集成了很多 SDK,因此应用程序超过了 65k 方法限制。我浏览了很多教程和博客。我得到了很多解决方案。其中之一在下面提到,作为我的 gradle 的一部分。请有人提供一个良好且有效的解决方案。
android {
minSdkVersion 16
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "your.package.name"
.......... }
buildTypes {
release {
.............................
}
}
// Inside android part of build.gradle
dexOptions {
preDexLibraries = false
}
}
.............
............
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
..................
// Inside dependencies part of build.gradle
compile 'com.android.support:multidex:1.0.1'
..............
}
// Outside android part of build.gradle
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = []
}
dx.additionalParameters += '--multi-dex'
}
........
.......
}
最佳答案
这是我们在项目中一直使用的。看起来效果很好。如果您的计算机内存较低,您应该喜欢 2g 参数,因为它意味着 multidex 最多可以使用 2GB 内存。这对我们来说不是问题。
defaultConfig{
// All other stuff you have, just add this line
multiDexEnabled true
}
dexOptions {
incremental true
javaMaxHeapSize "2g"
}
dependencies {
'com.android.support:multidex:1.0.1'
}
在您的项目中,您应该创建一个 Application 类,并且它应该扩展 MultiDexApplication
import android.support.multidex.MultiDexApplication;
public class YourApllication extends MultiDexApplication {
@Override
public void onCreate() {
super.onCreate();
}
}
关于java - Android 中的 Multidex 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29833391/