2017-09-09 37 views
1

构建我们的应用程序代码时出现构建错误DexIndexOverflowException。关于构建错误:DexIndexOverflowException

似乎我们的应用程序或应用程序中包含的库中的一些代码正在调用Google Play服务中的功能,最高呼叫次数为65536次。

要进一步追踪,您可以告诉我们一种深入了解可能对上述错误负责的依赖关系的方法。

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 

    //compile files('libs/commons-collections-3.2.1.jar') 
    compile(name: 'HERE-sdk', ext: 'aar') 
    compile('com.crashlytics.sdk.android:crashlytics:[email protected]') { 
     transitive = true; 
    } 
    compile 'com.android.support:appcompat-v7:25.3.1' 
    compile 'com.android.support:design:25.3.1' 
    compile 'com.android.support:support-v4:25.3.1' 
    compile 'com.android.support:recyclerview-v7:25.3.1' 
    compile 'com.google.android.gms:play-services-location:11.0.4' 
    compile 'com.bugfender.sdk:android:0.8.4' 
    compile 'com.google.code.gson:gson:2.2.4' 
    compile 'com.squareup.okhttp3:logging-interceptor:3.8.0' 
    compile 'com.squareup.retrofit2:retrofit:2.0.2' 
    compile 'com.squareup.retrofit2:converter-gson:2.0.2' 
    compile 'com.github.lzyzsd:circleprogress:1.2.1' 
    compile 'com.google.firebase:firebase-core:11.0.4' 
    compile 'com.google.firebase:firebase-auth:11.0.4' 

} 
apply plugin: 'com.google.gms.google-services' 

回答

1

它不是一个单一的依赖性的问题,这个问题是因为所有的依赖性的方法计数加你的应用程序代码的方法数加起来超过65536

正如android docs

提到

这两个错误条件都显示一个常见数字:65,536。这个数字非常重要,它代表了单个Dalvik Executable(DEX)字节码文件中代码可以调用的引用的总数。本页面解释了如何通过启用称为multidex的应用程序配置来移除此限制,该配置允许您的应用程序构建和读取多个DEX文件。

对于文档,如果不从构建文件中删除所有不必要的依赖关系,请确保使用您在gradle.build文件中提到的所有依赖关系,如果不尝试构建项目。

如果你仍然有问题,那么你需要在代码

使multidex如果你的minSdkVersion小于21,那么你需要将其添加到构建gradle这个

android { 
defaultConfig { 
    ... 
    minSdkVersion 21 
    targetSdkVersion 26 
    multiDexEnabled true 
} 
...} 



dependencies { 
    compile 'com.android.support:multidex:1.0.1' 
} 

,并改变base应用程序扩展MultiDexApplication如果您正在使用单独的应用程序类(您可能因为您正在使用crasylitics)。如果不添加以下内容到您的清单文件中

  android:name="android.support.multidex.MultiDexApplication" > 

然后尝试重新编译它。

荣誉

+1

谢谢您的回答..是的,我们在应用启用multidex,也是我们正在调试代码也看看我们是否可以删除一些库.. – Relsell