手头开发的APP集成了Facebook Ad jar 包AudienceNetwork.jar,打算更新到其最新版本4.14.1。
删除本地lib库里的老的AudienceNetwork.jar,在app的build.gradle的dependencies里添加
compile (‘com.facebook.android:audience-network-sdk:4.14.1‘)
编译报错如下信息:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ‘:transformClassesWithJarMergingForDebug‘.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzaa.class
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
从duplicate entry看是有重复的类被打包导致Excepion,查阅Gradle文档,可以排除重复文件打包,接下来的问题是排查下是哪个文件有问题,从上述信息看,应该是从com.google.android.gms下的某个类,考虑到之前使用facebook jar单独打包并没有发生此问题,那么就应该是编译依赖的4.14.1导致的。
到依赖仓库jcenter的老家Jfrog bintray逛逛,搜索facebook,找到audience-network-sdk:4.14.1的对应文件,有2个分别是aar和pom后缀的文件,我们只看配置文件就好,如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.facebook.android</groupId>
<artifactId>audience-network-sdk</artifactId>
<version>4.14.1</version>
<packaging>aar</packaging>
<name>Audience-Network-SDK</name>
<description>Facebook Audience Network SDK for Android</description>
<url>https://developers.facebook.com/products/app-monetization/audience-network/</url>
<licenses>
<license>
<name>Facebook Platform License</name>
<url>https://github.com/facebook/facebook-android-sdk/blob/master/LICENSE.txt</url>
<distribution>repo</distribution>
</license>
<license>
<name>Apache License Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>facebook</id>
<name>Facebook</name>
</developer>
</developers>
<scm>
<url>https://developers.facebook.com/docs/android/downloads</url>
</scm>
<dependencies>
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>play-services-ads</artifactId>
<version>8.4.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.android.support</groupId>
<artifactId>appcompat-v7</artifactId>
<version>23.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.android.support</groupId>
<artifactId>recyclerview-v7</artifactId>
<version>23.1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
显然,报错就是在打包play-services-ads时产生的,因为需要集成Firebase,在build.gradle中添加了
apply plugin: ‘com.google.gms.google-services‘
导致把google服务的全家桶都加了进来,自然也会有广告服务,冲突由此产生。
找到原因就很好解决了,在编译时把重复的去除就可以了。
原build.gradle里依赖部分:
dependencies { compile fileTree(: , : []) compile compile compile compile compile } apply :
更新后:
dependencies { compile fileTree(: , : []) compile compile compile compile compile () { exclude : exclude : exclude : } } apply :
再次编译,成功!