WideFide WideFide - 3 months ago 154x
Android Question

Generate Signed APK Error: Error converting bytecode to dex and 1 more

When I Clean/Rebuild my project or even run app, It doesn't return any errors. But when I generate signed APK, It returns two errors.

Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzox;

And this one

Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzd.class

Below is the code from

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "22.0.1"

defaultConfig {
applicationId "com.wildlife.dbd"
minSdkVersion 16
targetSdkVersion 24
versionCode 10
versionName "2.2.2"
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

apply plugin: 'com.google.gms.google-services'

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:design:24.0.0'

// FB Ads
compile 'com.facebook.android:audience-network-sdk:4.10.0'

// Analytics
compile 'com.google.android.gms:play-services-analytics:9.0.0'


Facebook audience network will pull in play-services as well, so you'll have to exclude it:

I don't remember exactly what Facebook's dependencies are, so your 'analytics' line might not be complete enough for the audience network to run properly. You might want to add the entire play services like so: compile 'com.google.android.gms:play-services:9.2.1', and remove analytics.

Or if you can see exactly which dependencies Facebook requires, you can grab the correct ones here.

compile ('com.facebook.android:audience-network-sdk:4.10.0') {
    exclude group: 'com.google.android.gms'