Android gradle用exclude排除引用包中的dependency引用

2019/11/14 11:48
阅读数 153

项目突然编译不通过,报如下错误

    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: D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\104.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\115.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\93.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\39.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\12.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\21.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\47.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\4.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\5.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\22.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\14.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\30.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\31.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\13.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\48.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\10.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\19.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\49.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\6.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\23.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\11.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\41.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\24.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\7.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\34.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\17.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\26.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\42.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\51.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\25.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\43.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\8.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\52.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\27.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\0.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\44.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\18.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\35.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\9.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\45.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\28.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\15.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\1.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\2.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\32.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\46.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\16.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\29.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\3.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\50.jar, D:\ws\AutosizingTest\app\build\intermediates\transforms\dexBuilder\debug\20.jar
      Program type already present: android.support.v4.widget.SlidingPaneLayout$AccessibilityDelegate
      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
     
    BUILD FAILED in 19s

经排查发现原来是项目中引用的第三方包'liji.library.dev:citypickerview:4.1.1'中引用的v7包和项目引用的v7包冲突导致的。

可以直接删除项目的v7包引用,直接用第三包里面的v7包就可以了。

但是如果第三方包引用的包太老旧,你执意要用最新的,那该怎么办呢?你可以用exclude把第三方包里的指定dependency排除掉,然后再重新编译就可以成功了。

    dependencies {
        implementation 'com.android.support:appcompat-v7:28.0.0'
        implementation ('liji.library.dev:citypickerview:4.1.1') {
            exclude group: 'com.android.support'
        }
    }

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部