Mobile_xxx:transformClassesWithJarMergingForRelease‘

简介: Mobile_xxx:transformClassesWithJarMergingForRelease‘

1Error:Execution failed for task ':Mobile_XMXT:transformClassesWithJarMergingForRelease'.


> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/gson/DefaultDateTypeAdapter.class


我这个报这个错误的原因是因为jar包冲突,很明显,gom.goole.gson  duplicafe 意思就是有两个这个文件,重复了。


看到错误,我检查了一下项目,原来的项目中的GSON是直接将源码拷贝到了项目中,后来引入了一个第三方的视频监控sdk,我看了一下 这个sdk中也包含这个


image.png

image.png

一个在项目里面 一个在jar包里面,删除哪个都会引起相关联的错误。怎么办呢?


说明一下,Android Studio引用第三方库几种方式:


方式:1:它就会自动把这个包下载下来,并且引用它。节省git空间,而且修改版本也很方便。

compile 'com.android.support:support-v4:23.3.0'


方式2:引用libs下所有jar包


compile fileTree(dir: 'libs', include: ['*.jar'])


方式3:引用一个jar

compile files('libs/fastjson-1.1.53.android.jar')


方式4:引用一个aar文件,注意并不能像 方式2 那样自动引用全部的aar,而需要对每个aar分别进行引用。

compile(name: 'aar_file_name', ext: 'aar')


方式5:引用库类型的项目

compile project(':xxxsdk')


方式6:仅仅在编译时使用,但最终不会被编译到apk或aar里

provided files('libs/glide-3.7.0.jar')


所以后来我将项目中的gson源码删除掉,改为第一种引用三方库方式,这样做的目的就是可以在build.gradle控制引入三方库的编译及打包方式。


下面再说一下 android studio 引入三方库的几种依赖方式


1.Compile


compile是对所有的build type以及favlors都会参与编译并且打包到最终的apk文件中。


2.Provided

Provided是对所有的build type以及favlors只在编译时使用,类似eclipse中的external-libs,只参与编译,不打包到最终apk。


3.APK

只会打包到apk文件中,而不参与编译,所以不能再代码中直接调用jar中的类或方法,否则在编译时会报错


4.Test compile

Test compile 仅仅是针对单元测试代码的编译编译以及最终打包测试apk时有效,而对正常的debug或者release apk包不起作用。


5.Debug compile

Debug compile 仅仅针对debug模式的编译和最终的debug apk打包。


6.Release compile


Release compile 仅仅针对Release 模式的编译和最终的Release apk打包。


相关文章
|
Java API Android开发
MPaaS(Mobile PaaS)
阿里巴巴集团推出的移动应用开发平台,它提供了一系列的移动应用开发解决方案,包括移动应用开发、测试、部署和运营等。ResultPbPB 是 MPaaS 平台提供的一个数据传输协议,用于在移动应用程序和云端服务之间传输数据。
405 1
|
SQL Java 数据库连接
Could not find resource xxx/xxxx/xxx.xml报错解决
Could not find resource xxx/xxxx/xxx.xml报错解决
Could not find resource xxx/xxxx/xxx.xml报错解决
|
iOS开发
iOS No "iOS Distribution" signing certificate matching team ID "xxxxxx" with a private key was fo...
iOS No "iOS Distribution" signing certificate matching team ID "xxxxxx" with a private key was fo...
1081 0
|
iOS开发
iOS 发布:“xxx”has one iOS Distribution certificate but its private key is not installed.解决方法
iOS 发布:“xxx”has one iOS Distribution certificate but its private key is not installed.解决方法
109 0
Unity报错:Read only asset Packages/com.xxxxx.xxx.xxxx/Editor/VSCodeDiscovery.cs.IPGSD has no meta
Unity报错:Read only asset Packages/com.xxxxx.xxx.xxxx/Editor/VSCodeDiscovery.cs.IPGSD has no meta
Unity报错:Read only asset Packages/com.xxxxx.xxx.xxxx/Editor/VSCodeDiscovery.cs.IPGSD has no meta
|
IDE AliOS-Things 物联网
my.httpReqeust安卓出现Alipay-Mobile-Proxy-Server(502_BAD_GATEWAY)的解决方案
报错原因: 出现Alipay-Mobile-Proxy-Server(502_BAD_GATEWAY)是因为目前 Android设备有安全代理,不允许请求非公网地址,如局域网 解决方案: 请使用公网请求地址。
768 0
|
iOS开发
This iPhone xxx is running iOS xxx, which may not be supported by this version of Xcode.
有时候我们的iPhone紧跟apple的步伐升级最新的版本了,但是Xcode并没有及时更新到最新版本(Xcode是在很大,而且有时候是需要最新的beta版本的),这时候真机调试的时候就会出现下面这样的问题: 报错: Could not locate device support files.
1754 0