Error:Execution failed for task ':app2:transformDexArchiveWithExternalLibsDexMergerForDebug'.
com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
在使用外部依賴庫時出現(xiàn)這個問題我自己封裝了一個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')
//封裝網(wǎng)絡(luò)協(xié)議
compile project(path: ':HttpLibrary')
//權(quán)限管理
compile 'com.yanzhenjie:permission:1.1.2'
compile project(':imageloadlibrary')
//EventBus:是一款針對Android優(yōu)化的發(fā)布/訂閱事件總線。
// 主要功能是替代Intent,Handler,BroadCast在Fragment,Activity,Service,
// 線程之間傳遞消息.優(yōu)點是開銷小,代碼更優(yōu)雅。以及將發(fā)送者和接收者解耦。
compile 'org.greenrobot:eventbus:3.0.0'
}
1 回答

蠱毒傳說
TA貢獻1895條經(jīng)驗 獲得超3個贊
1.這個問題的出現(xiàn)是因為依賴了兩個相同的但版本不同的庫所導致的沖突。
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')
導致出現(xiàn)這個問題
可以通過將下方的依賴改成上方的依賴就可以解決這個問題
添加回答
舉報
0/150
提交
取消