我有一个用于 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/