ore*_*ion 11 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)
Run Code Online (Sandbox Code Playgroud)
这真的很奇怪,因为我已经在我的项目中启用了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'
}
Run Code Online (Sandbox Code Playgroud)
我的应用类
public class RiderApplication extends MultiDexApplication implements Application.ActivityLifecycleCallbacks,
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
....
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest
<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">
Run Code Online (Sandbox Code Playgroud)
删除库可以解决问题
有什么建议?
编辑 我尝试用几种方法解决它,我发现只有当我将库包含在内时才会发生这种情况
androidTestImplementation
Run Code Online (Sandbox Code Playgroud)
但是当作为常规使用时
implementation
Run Code Online (Sandbox Code Playgroud)
dex错误消失了
真奇怪
编辑
它只发生在gradle 3.0.1上,如果我回到gradle 2.3.3,问题就不复存在了
嗯,这很奇怪,但以前也发生过。
我偶然发现了这个线程,并建议添加以下内容:
dexOptions {
jumboMode = true
// Avoid the OutOfMemoryError: GC overhead limit exceeded:
incremental true
javaMaxHeapSize "4g"
}
Run Code Online (Sandbox Code Playgroud)
这应该解决字符串数量太大的问题,而不是方法数量太大的问题。
有关 Jumbo 模式与 Multidex 的更多信息,请参阅此处:Android:Jumbo 模式与 Multidex
快乐的测试。
| 归档时间: |
|
| 查看次数: |
889 次 |
| 最近记录: |