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

2024-03-30

我有一个用于 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 {
  ....
}

Android清单

<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">

删除库可以解决问题

有什么建议么?

EDIT我尝试以多种方式修复它,我发现只有当我将库包含为

androidTestImplementation

但当作为常规使用时

implementation

dex错误消失

真奇怪

EDIT

它只发生在 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'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android Studio 3.0 上的 com.android.dex.DexIndexOverflowException 的相关文章

随机推荐