3

I searched a lot about this topic, but only found some old answers which tell to enable multidex, which is not relevant for this case.

I have this exception during Android Gradle build (task transformDexArchiveWithDexMergerForAppDebug)

What went wrong: Execution failed for task 
':app:transformDexArchiveWithDexMergerForAppDebug'. > 
  com.android.build.api.transform.TransformException: 
  com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

I have multidex enabled:

defaultConfig { 
    multiDexEnabled true
}

dependencies{
    compile 'com.android.support:multidex:1.0.2'
}

This seems to be related to fact that multidex puts to many classes in main dex file. But I can't find a reliable solution to fix that. Proguard is also not a good option here as it happens on debug build and with Proguard enabled it takes too long.

Happens on:

'com.android.tools.build:gradle:3.0.1'
'com.android.tools.build:gradle:2.3.0'

UPDATE - added build.gradle files as requested:

main:

buildscript {
  ext.kotlin_version = '1.1.60'
  ext.anko_version = '0.10.1'
  ext.play_services_version = '11.6.0'

  repositories {
    mavenCentral()
    jcenter()
    maven { url "https://jitpack.io" }
    maven { url 'https://maven.fabric.io/public' }
  }

  dependencies {
    classpath 'com.android.tools.build:gradle:2.3.0'
    classpath 'me.tatarka:gradle-retrolambda:3.6.1'
    classpath 'io.fabric.tools:gradle:1.22.1'
    classpath 'com.google.gms:google-services:3.1.1'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  }
}

allprojects {
  repositories {
    mavenCentral()
    jcenter()
    maven { url "https://jitpack.io" }
    maven { url 'https://maven.fabric.io/public' }
  }
}

app:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'
apply plugin: 'me.tatarka.retrolambda'

def getVersionCode = { ->
  version
}

def getVersionName = { ->
  ext.versionMajor + "." + ext.versionMinor + "." + ext.versionPatch
}

ext {
  versionMajor = 2
  versionMinor = 5
  versionPatch = 0
  ext.iconVersion = false
}

android {
  compileSdkVersion 25
  buildToolsVersion "25.0.2"

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

  sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
  }

  defaultConfig {
    minSdkVersion 16
    targetSdkVersion 25

    versionCode getVersionCode()
    versionName getVersionName()

    vectorDrawables.useSupportLibrary(true)
    multiDexEnabled true

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  }

  signingConfigs {
    //removed ...
  }

  buildTypes {
    debug {
      debuggable true
      versionNameSuffix '.develop'
      signingConfig signingConfigs.debug
    }

    release {
      minifyEnabled true
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      debuggable false
      signingConfig signingConfigs.release
      zipAlignEnabled true
    }
  }

  productFlavors {
    //removed
  }

  dexOptions {
    javaMaxHeapSize "4g"
    jumboMode true
  }

  testOptions {
    unitTests.returnDefaultValues = true
  }

  packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/ASL2.0'
  }
}

hockeyapp {
  //removed
}

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])

  // android support libs and views
  compile 'com.android.support:appcompat-v7:25.3.1'
  compile 'com.android.support:recyclerview-v7:25.3.1'
  compile 'com.android.support:design:25.3.1'
  compile 'com.android.support:cardview-v7:25.3.1'
  compile 'com.android.support:palette-v7:25.3.1'
  compile 'com.android.support:percent:25.3.1'

  compile 'com.github.lsjwzh.RecyclerViewPager:lib:v1.1.0'
  compile 'com.bignerdranch.android:expandablerecyclerview:2.0.0'
  compile 'org.apmem.tools:layouts:1.10@aar'
  compile 'com.github.frankiesardo:linearlistview:1.0.1@aar'
  compile 'com.github.aakira:expandable-layout:1.5.1@aar'
  compile 'org.bluecabin.textoo:textoo:1.0.1'
  compile 'com.lapism:searchview:4.0'
  compile 'com.google.android:flexbox:0.2.6'
  compile 'com.github.castorflex.smoothprogressbar:library-circular:1.2.0'

  // view injection
  compile 'com.jakewharton:butterknife:8.4.0'
  annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'

  // EDP
  compile 'org.greenrobot:eventbus:3.0.0'

  // image loader
  compile 'com.squareup.picasso:picasso:2.5.2'
  compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
  compile 'jp.wasabeef:picasso-transformations:2.1.2'
  compile 'com.github.chrisbanes:PhotoView:2.1.3'

  // calendar component
  compile 'com.squareup:android-times-square:1.6.4@aar'

  // time library
  compile 'net.danlew:android.joda:2.9.0'

  // play & firebase services
  compile "com.google.android.gms:play-services-analytics:$play_services_version"
  compile "com.google.android.gms:play-services-maps:$play_services_version"
  compile "com.google.android.gms:play-services-gcm:$play_services_version"
  compile "com.google.android.gms:play-services-location:$play_services_version"
  compile "com.google.firebase:firebase-messaging:$play_services_version"
  compile "com.google.firebase:firebase-core:$play_services_version"
  compile "com.google.firebase:firebase-appindexing:$play_services_version"

  // push
  compile 'com.onesignal:OneSignal:3.4.3@aar'

  // analytics & crash reports
  compile 'com.facebook.android:facebook-android-sdk:4.23.0'
  compile('com.crashlytics.sdk.android:crashlytics:2.5.7@aar') {
    transitive = true;
  }

  // logging
  compile 'com.jakewharton.timber:timber:4.5.0'

  // networking
  compile 'com.squareup.retrofit2:retrofit:2.2.0'
  compile 'com.squareup.retrofit2:converter-gson:2.2.0'
  compile 'com.squareup.okhttp3:okhttp:3.6.0'
  compile 'com.squareup.okhttp3:okhttp-urlconnection:3.6.0'
  compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'

  // coding tools
  compile 'me.tatarka:gradle-retrolambda:3.6.1'
  compile 'io.reactivex:rxandroid:1.2.1'
  compile 'io.reactivex:rxjava:1.2.9'
  compile 'com.android.support:multidex:1.0.1'
  compile 'com.facebook.stetho:stetho:1.3.1'
  compile 'com.github.markomilos:paginate:0.5.1'

  // data persistence
  compile 'com.j256.ormlite:ormlite-core:4.47'
  compile 'com.j256.ormlite:ormlite-android:4.47'
  compile 'com.github.orhanobut:hawk:1.23'

  // custom fonts
  compile 'uk.co.chrisjenx:calligraphy:2.2.0'

  // swagger model
  compile "io.swagger:swagger-annotations:1.5.0"

  // keyboard visibility listener
  compile 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:1.0.1'

  //views
  compile 'com.joooonho:selectableroundedimageview:1.0.1'
  compile 'me.grantland:autofittextview:0.2.1'

  //memory leaks analyzer
  debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
  releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
  testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'

  testCompile 'junit:junit:4.12'
  compile project(path: ':carousel')
  androidTestCompile 'junit:junit:4.12'
  androidTestCompile 'com.android.support:support-annotations:25.3.1'
  androidTestCompile 'com.android.support.test:runner:0.5'
  androidTestCompile 'org.mockito:mockito-android:2.7.14'

  compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
  compile "org.jetbrains.anko:anko-commons:$anko_version"
  compile "org.jetbrains.anko:anko-sdk25:$anko_version"
  compile "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
  compile "org.jetbrains.anko:anko-appcompat-v7-commons:$anko_version"
}

apply plugin: 'com.google.gms.google-services'
marcinm
  • 281
  • 1
  • 2
  • 11
  • 4
    Create `Application` class. Read https://stackoverflow.com/a/33430306/3395198 – IntelliJ Amiya Dec 22 '17 at 11:16
  • ^ That post is about using multidex, which as I wrote is not valid for this case - I have it enabled. – marcinm Dec 22 '17 at 11:19
  • read from `If your Application class is extending some other class and you don’t want to or can’t change it, override attachBaseContext() as shown below:` – IntelliJ Amiya Dec 22 '17 at 11:20
  • 1
    As I said - I have multidex enabled. And the part you told me to read tells how to enable multidex without extneding from MultidexApp class... – marcinm Dec 22 '17 at 11:22
  • Add your both build.gradle – Abubakker Moallim Dec 22 '17 at 11:33
  • Updated post with contents of both build.gradle files – marcinm Dec 22 '17 at 11:53
  • @marcinm As you mentioned that you think that it is somehow related to the fact of too many classes in main dex file - check out my answer here: https://stackoverflow.com/a/32780470/1233652 which relates to the similar issue. – Alex Lipov Dec 24 '17 at 07:47
  • Thanks Alex - I've seen that answer :) I'm thinking about upgrading minSdk to 21 for development builds to go around this (I use proguard for production, so it should be fine). I also tried your workaround, but in the latest gradle plugin (3.0.1) API seems to be changed and I couldn't get it to work. – marcinm Dec 27 '17 at 07:50
  • @marcinm did you solve this issue eventually? – ibit Oct 09 '18 at 09:57

0 Answers0