我正在一个公司项目中,需要集成 Dynamsoft Android SDK 以用于文档扫描。问题是,当将sdk依赖项添加到当前项目时,它在构建控制台上出现此错误时与 okhttp3 冲突:
**任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败。
com.android.builder.dexing.DexArchiveMergerException:合并dex归档文件时出错: 程序类型已经存在:okhttp3.Address 在https://developer.android.com/studio/build/dependencies#duplicate_classes中了解如何解决该问题。**
正如在开发人员控制台中建议的那样,okhttp3已从Dynamsoft依赖项中排除(实际上以多种方式尝试过),但问题仍然存在。
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
buildToolsVersion "28.0.2"
compileSdkVersion 28
defaultConfig {
applicationId "no.aspit.capture"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
dev {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
}
}
lintOptions {
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'okhttp3/internal/publicsuffix/publicsuffixes.gz'
}
}
kotlin {
experimental {
coroutines 'enable'
}
}
androidExtensions {
experimental = true
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-rc02'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0-rc02'
implementation 'androidx.core:core-ktx:1.0.0-rc02'
implementation "android.arch.work:work-runtime-ktx:1.0.0-alpha08"
implementation 'androidx.preference:preference:1.0.0-rc02'
implementation 'androidx.fragment:fragment-ktx:1.0.0-rc02'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-rc02'
implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.squareup.moshi:moshi-kotlin:1.6.0'
implementation 'com.squareup.retrofit2:converter-moshi:2.4.0'
kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.6.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.github.ittianyu:BottomNavigationViewEx:1.2.4'
//noinspection GradleCompatible
implementation "com.android.support:design:26.1.0"
implementation 'com.squareup.picasso:picasso:2.71828'
//Joda time
implementation 'net.danlew:android.joda:2.9.9.4'
// Image Compression
implementation 'id.zelory:compressor:2.1.0'
//Stetho
implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.facebook.stetho:stetho-okhttp3:1.5.0'
//Dynumsoft
implementation ('com.dynamsoft:dynamsoftcamerasdk:2.0@aar'){
exclude group: 'com.squareup.okhttp3'
}
}
repositories {
maven {
url "http://download.dynamsoft.com/maven/dcs"
}
答案 0 :(得分:0)
您可以尝试解决冲突,如下所示:
configurations.all {
all*.exclude group: 'com.squareup.okhttp3', module: 'okhttp'
all*.exclude group: 'com.squareup.okio', module: 'okio'
resolutionStrategy.force 'com.squareup.okhttp3:okhttp:3.10.0'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-rc02'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0-rc02'
implementation 'androidx.core:core-ktx:1.0.0-rc02'
implementation "android.arch.work:work-runtime-ktx:1.0.0-alpha08"
implementation 'androidx.preference:preference:1.0.0-rc02'
implementation 'androidx.fragment:fragment-ktx:1.0.0-rc02'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-rc02'
implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.squareup.moshi:moshi-kotlin:1.6.0'
implementation 'com.squareup.retrofit2:converter-moshi:2.4.0'
kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.6.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.github.ittianyu:BottomNavigationViewEx:1.2.4'
//noinspection GradleCompatible
implementation "com.android.support:design:26.1.0"
implementation 'com.squareup.picasso:picasso:2.71828'
//Joda time
implementation 'net.danlew:android.joda:2.9.9.4'
// Image Compression
implementation 'id.zelory:compressor:2.1.0'
//Stetho
implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.facebook.stetho:stetho-okhttp3:1.5.0'
//Dynumsoft
implementation ('com.dynamsoft:dynamsoftcamerasdk:2.0@aar')
}