奇数DexArchiveMergerException

问题描述:

我以前遇到过这个问题,并且能够很容易地修复它。但是,这一次,我不明白是什么原因造成的。自从它工作以来,对build.gradle的唯一改动是implementation project(':sharedfiles')--一个用于穿戴/移动的共享通用模块。我没有添加这个,我将该模块添加为依赖项,并且该行被自动添加,所以我怀疑它是一个错误。我有multipleDexEnabled true,无法找到任何冲突的依赖关系。任何帮助将不胜感激,这是我第一次使用通用模块。这里是两个build.gradle文件。奇数DexArchiveMergerException

移动模块

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 26 
    defaultConfig { 
     applicationId "bhprograms.supremis" 
     minSdkVersion 23 
     targetSdkVersion 26 
     multiDexEnabled true 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    implementation fileTree(include: ['*.jar'], dir: 'libs') 
    implementation 'com.android.support:appcompat-v7:26.1.0' 
    implementation 'com.android.support.constraint:constraint-layout:1.0.2' 
    testImplementation 'junit:junit:4.12' 
    androidTestImplementation 'com.android.support.test:runner:1.0.1' 
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 
    wearApp project(':wear') 
    implementation 'com.google.android.gms:play-services-wearable:+' 
    implementation files('libs/gson.jar') 
    implementation project(':sharedfiles') 
} 

公用模块

apply plugin: 'com.android.library' 

android { 
    compileSdkVersion 26 



    defaultConfig { 
     minSdkVersion 23 
     targetSdkVersion 26 
     versionCode 1 
     multiDexEnabled true 
     minSdkVersion 23 
     targetSdkVersion 26 
     versionName "1.0" 

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

    } 

    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 

} 

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

    implementation 'com.android.support:appcompat-v7:26.1.0' 
    testImplementation 'junit:junit:4.12' 
    androidTestImplementation 'com.android.support.test:runner:1.0.1' 
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 
    implementation files('libs/gson.jar') 
} 

,当然,错误。

Error:Execution failed for task ':mobile:transformDexArchiveWithExternalLibsDexMergerForDebug'. 
> com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex 

通过在移动模块中删除implementation files('libs/gson.jar')来解决。不知道为什么这会修复它,可能是因为我没有在移动模块中使用这个jar。如果实验性功能无法正常工作,我将来可能需要它,但这是导致此问题的原因。