我面对编译错误" com.android.dex.DexIndexOverflowException:方法ID不在[0,0xffff]:65536",我在google搜索问题是我的项目达到了方法的限制。我遵循MultIDex指令。我添加了build.gradle,以下是build.gradle的文件上下文
apply plugin: 'com.android.application'
android {
compileSdkVersion 15
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 15 //lower than 14 doesn't support multidex
targetSdkVersion 21
// Enabling multidex support.
multiDexEnabled = true
}
dexOptions {
preDexLibraries = false
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
当我再次构建它时,错误仍然存在,我该怎么办?
答案 0 :(得分:0)
您还需要创建自定义应用程序并覆盖attachBaseContext方法,如下所示:
public class MyApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
然后将其添加到您的清单上,如下所示:
<application
android:name=".MyApplication"
.....
</application>
瞧!
答案 1 :(得分:0)
我有其他响应者的建议,但IntelliJ仍然无法识别MultiDex包,即使手动将库添加到项目(multidex-1.0.1.aar
文件,由Gradle拉入)。真正的问题是IntelliJ似乎还没有识别aar
文件中的符号。但是,应用程序仍然通过IntelliJ中的Gradle任务构建。