启用了multidex的DexIndexOverflowException

时间:2017-12-22 11:15:27

标签: android multidex android-multidex

我搜索了很多关于这个主题的内容,但只找到了一些旧的答案,告诉我们启用multidex,这与这种情况无关。

我在Android Gradle构建期间遇到此异常(任务 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

我启用了multidex:

defaultConfig { 
    multiDexEnabled true
}

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

这似乎与multidex在main dex文件中放入许多类的事实有关。但我找不到一个可靠的解决方案来解决这个问题。 Proguard在这里也不是一个好选择,因为它在调试版本中发生并且启用了Proguard它需要太长时间。

发生在:

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

更新 - 按要求添加了build.gradle文件:

主:

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

应用程式:

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'

0 个答案:

没有答案