欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

jar包引用时,小哥哥犯的错

程序员文章站 2022-02-12 21:22:55
...

我刚开始引用jar包的时候,用的是本地引用,

 修改宿主apk的build.gradle的dependencies:
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name:'cnadsdk', ext:'jar')
}

然后我一build demo 看到报一大堆类似先面的错误我慌了


AGPBI: {"kind":"error","text":"Program type already present: com.cc.c.e.Base64","sources":[{}],"tool":"D8"}
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED

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:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\0.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\1.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\2.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\3.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\4.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\5.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\6.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\7.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\8.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\9.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\10.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\11.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\12.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\13.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\14.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\15.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\16.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\17.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\18.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\19.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\20.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\21.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\22.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\23.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\24.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\25.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\26.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\27.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\28.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\29.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\30.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\31.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\32.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\33.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\34.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\35.jar, D:\work\leshice\app\build\intermediates\transforms\dexBuilder\debug\36.jar
  Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
  Program type already present: com.cc.c.e.Base64

* 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 6s


后来我翻了各种资料也没找出,主要是问题都不沾边
其实也是因为操作看不懂等等 ;
但是我翻了十篇博客后才意识到了一点,可能是我的一些依赖重复 ,
或者两个相同类进行重复引用,当然这个是我看博文神么额,
一般都是这种类似说法、。
后来,我徐哥发现
我们多引用了个
// implementation fileTree(include: [’*.jar’], dir: ‘libs’)
然后build 了一下项目,不报红了,心里也是。。。。了;‘

后来徐哥还说

// 可以一条依赖引入libs下所有的jar
implementation fileTree(dir: 'libs', include: ['*.jar'])

// 也可以指定依赖某一个或几个jar
implementation files('libs/dict-v120.jar', 'libs/download-v151.jar')’
相关标签: jar