Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

com.android.dex.DexIndexOverflowException on Android Studio 3.0

I have a library I use for Espresso tests that when I added to my project I'm not able to compile my tests.

Gradle outputs this error

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)

Which is really weird because I already have multiDex enabled in my project

My Project 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'
}

My Application Class

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

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

Removing the library solves the problem

Any suggestions?

EDIT I tried to fix it in several ways, and I discovered that this only happends when I include the library as

androidTestImplementation

But when used as a regular

implementation

The dex error disappears

Really strange

EDIT

It only happens with gradle 3.0.1, if I go back to gradle 2.3.3 the problem is no more

like image 463
orelzion Avatar asked Nov 22 '17 10:11

orelzion


1 Answers

Solved by updating gradle build tools from version 3.0.1 to 3.1.0-rc02. So please try:

classpath 'com.android.tools.build:gradle:3.1.0-rc02'
like image 95
Flavio Avatar answered Oct 24 '22 02:10

Flavio