Execution failed for task ':packageAllDebugCla

2019-04-28 23:17发布

I am try to use the new android multidex support for a project. I have some problem with this exception:

Error:Execution failed for task ':shineV3:packageAllDebugClassesForMultiDex'.

java.util.zip.ZipException: duplicate entry: com/google/android/gms/analytics/internal/Command$1.class

about the problem. I use 2 different jar package as dependency, and some class will be duplicated in classes.dex because both jars contains they. any idea? thanks in Advance

3条回答
时光不老,我们不散
2楼-- · 2019-04-28 23:51

If you are integrating Google Analytics V2 and Google play services in your app, then you need to do the following in your gradle file:

dependencies {
    compile 'com.google.android.gms:play-services:4.0.30'
    compile files('libs/libGoogleAnalyticsServices.jar')
}

It worked for me. Hope it will work for others too. :)

查看更多
何必那么认真
3楼-- · 2019-04-28 23:55

For those that are coming into this, I figured out why this was happening. For me it was that I was compiling the Google Analytics V2 jar as well as the full play services. Google allows you to break down what play services you really need for you app and compile those individual items. Check them out here. I excluded the Google Play Analytics which is on V4 right now and it worked

查看更多
再贱就再见
4楼-- · 2019-04-29 00:03

adding this to your grdale compile "com.google.android.gms:play-services:7.5.+" means adding all play services including analytics, maps, vcm .. etc. you can add

as guides mentions:

In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.

From version 6.5, you can instead selectively compile Google Play service APIs into your app. For example, to include only the Google Fit and Android Wear APIs, replace the following line in your build.gradle file:

compile 'com.google.android.gms:play-services:7.5.0' with these lines:

compile 'com.google.android.gms:play-services-fitness:7.5.0' compile 'com.google.android.gms:play-services-wearable:7.5.0'

https://developers.google.com/android/guides/setup

查看更多
登录 后发表回答