transformDexArchiveWithExternalLibsDexMergerForDebug

Error:Execution failed for task ':app2:transformDexArchiveWithExternalLibsDexMergerForDebug'.

com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

在使用外部依赖库时出现这个问题
我自己封装了一个Retrofit+rxjava的library当依赖这个库时报出这个错误

封装的httplibrary的build.gradle

apply plugin: 'com.android.library'

android {

compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
}

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

}

dependencies {

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:26.1.0'
compile "io.reactivex.rxjava2:rxjava:2.1.0"
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.5.0'

}

依赖的build.gradle

apply plugin: 'com.android.library'

android {

compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"

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

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

}

dependencies {

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

// compile 'com.android.support:appcompat-v7:26.1.0'

testCompile 'junit:junit:4.12'
androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

compile project(':naslib')
//视频播放器
compile project(':videoplayer')
//自定义toast
compile project(':toasty')
//自定义dialog
compile project(':FlycoDialog_Lib')

//封装网络协议
compile project(path: ':HttpLibrary')
//权限管理
compile 'com.yanzhenjie:permission:1.1.2'

compile project(':imageloadlibrary')

//EventBus:是一款针对Android优化的发布/订阅事件总线。
// 主要功能是替代Intent,Handler,BroadCast在Fragment,Activity,Service,
// 线程之间传递消息.优点是开销小,代码更优雅。以及将发送者和接收者解耦。
compile 'org.greenrobot:eventbus:3.0.0'

}

慕容708150
浏览 1237回答 1
1回答

蛊毒传说

1.这个问题的出现是因为依赖了两个相同的但版本不同的库所导致的冲突。2.可以通过查看依赖库中的相同依赖文件版本是否相同3.我的解决是因为封装http库中使用的时 compile 'com.squareup.retrofit2:converter-gson:2.3.0' 在这个依赖中有依赖的gson是2.7的 而我在另一个库中是 compile files('src/main/libs/gson-2.8.0.jar') 导致出现这个问题 可以通过将下方的依赖改成上方的依赖就可以解决这个问题
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java