我正在将mapbox-sdk的依赖项集成到我的gradle构建文件中,并遇到我的依赖项树中重复的错误。如何排除必要的依赖关系?
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.1.1'
implementation 'com.android.support:recyclerview-v7:28.1.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
// android exinterface
implementation 'com.android.support:exifinterface:28.0.0'
// mapbox sdk
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:6.7.0'
// navigation sdk will transitively bring maps-sdk
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.24.0-beta.1'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.google.android:support-v4:r7'
// multidex enabling
implementation 'com.android.support:multidex:1.0.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
我有多个androidx.fragment:fragment:1.0.0(*)条目,这似乎是问题所在。
+--- androidx.legacy:legacy-support-v4:1.0.0
| +--- androidx.core:core:1.0.0 (*)
| +--- androidx.media:media:1.0.0
| | +--- androidx.annotation:annotation:1.0.0
| | +--- androidx.core:core:1.0.0 (*)
| | \--- androidx.versionedparcelable:versionedparcelable:1.0.0 (*)
| +--- androidx.legacy:legacy-support-core-utils:1.0.0 (*)
| +--- androidx.legacy:legacy-support-core-ui:1.0.0 (*)
| \--- androidx.fragment:fragment:1.0.0 (*)
+--- com.mapbox.mapboxsdk:mapbox-android-sdk:6.7.0
| +--- com.mapbox.mapboxsdk:mapbox-android-telemetry:3.5.2
| | +--- com.mapbox.mapboxsdk:mapbox-android-core:0.2.1
| | | \--- androidx.appcompat:appcompat:1.0.0 (*)
| | +--- com.squareup.okhttp3:okhttp:3.10.0 -> 3.11.0
| | | \--- com.squareup.okio:okio:1.14.0
| | +--- com.google.code.gson:gson:2.8.2 -> 2.8.5
| | +--- androidx.appcompat:appcompat:1.0.0 (*)
| | \--- androidx.lifecycle:lifecycle-extensions:2.0.0
| | +--- androidx.lifecycle:lifecycle-runtime:2.0.0 (*)
| | +--- androidx.arch.core:core-common:2.0.0 (*)
| | +--- androidx.arch.core:core-runtime:2.0.0 (*)
| | +--- androidx.fragment:fragment:1.0.0 (*)
我得到的异常是DexArchiveMergerException,如下所示:
BUILD FAILED in 17s
19 actionable tasks: 7 executed, 12 up-to-date
./gradlew build
> Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
D8: Program type already present: androidx.fragment.app.Fragment$InstantiationException
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Program type already present: androidx.fragment.app.Fragment$InstantiationException
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.0-milestone-1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 8s
19 actionable tasks: 4 executed, 15 up-to-date
答案 0 :(得分:0)
在gradle.properties
中添加以下行
android.useAndroidX=true
android.enableJetifier=true
通常由于以下情况之一而发生此错误:
- 二进制依赖项包含一个库,您的应用程序还包含一个库 直接依赖。例如,您的应用声明了直接 对库A和库B的依赖,但是库A已经包括 库B的二进制文件。要解决此问题,请将库B删除为 直接依赖。
- 您的应用具有本地二进制依赖性和远程 对同一库的二进制依赖性。要解决此问题,请删除 二进制依赖项之一。
请参考此处:https://developer.android.com/studio/build/dependencies#duplicate_classes