android - Android Studio 3.0 上的 com.android.dex.DexIndexOverflowException

标签 android android-multidex

我有一个用于 Espresso 测试的库,当我将它添加到我的项目时,我无法编译我的测试。

Gradle 输出这个错误

Caused by: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
    at com.android.dx.merge.DexMerger$8.updateIndex(DexMerger.java:565)
    at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:276)
    at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:574)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:166)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)

这真的很奇怪,因为我已经在我的项目中启用了 multiDex

我的项目build.gradle

defaultConfig {
            minSdkVersion 16
            targetSdkVersion 21
            versionName versionNameFromGitTagVia()
            versionCode versionCodeFromJenkins()
            multiDexEnabled true

            testInstrumentationRunner "app.test.general.InstrumentationRunner" ...
}
dependencies {
    ...
    androidTestImplementation project(':test-utils')
    ...
    implementation 'com.android.support:multidex:1.0.2'
}

我的应用类

public class RiderApplication extends MultiDexApplication implements Application.ActivityLifecycleCallbacks,
        GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
  ....
}

安卓 list

<application
    android:name=".RiderApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:theme="@style/MyAppTheme"
    tools:replace="android:theme,android:icon">

删除库解决问题

有什么建议吗?

编辑 我尝试通过多种方式修复它,但我发现只有当我将库包含为

时才会发生这种情况
androidTestImplementation

但作为常规使用时

implementation

dex错误消失

真的很奇怪

编辑

它只发生在 gradle 3.0.1 上,如果我回到 gradle 2.3.3 问题就没有了

最佳答案

通过将 gradle 构建工具从版本 3.0.1 更新到 3.1.0-rc02 解决。 所以请尝试:

classpath 'com.android.tools.build:gradle:3.1.0-rc02'

关于android - Android Studio 3.0 上的 com.android.dex.DexIndexOverflowException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47432055/

相关文章:

Android studio 报错Okhttp3 点击按钮后无法上传音频文件

android - 裁剪ImageViews的Canvas方法

android - 特定的 applicationIdSuffix 阻止应用程序启动

android - java.lang.NoClassDefFoundError : com. 谷歌.android.gms.common.internal.zzd

android - 版本为 1.6.0 的 VM 不支持 multidex : Unable to find application Mono. Android.Platform.ApiLevel_23 或 Xamarin.Android.Platform

Android 多个 dex 文件定义 Lcom/google/android/gms/common/api/zza

android - 在 Android Studio 中使用 MultiDex 功能时,有没有办法限制主 dex 文件中的方法数量

android - 如何将 edittext 值存储在字符串数组中?

安卓市场过滤问题

java - SQLite连接池