Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

duplicate entry: com/google/android/gms/internal/zzahl.class

Here is the error I'm getting when I build my project:

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

I can't seem to figure out what is causing the error, I suspect it's something I messed up in my gradle or Java Activity. Here's the code:

Gradle:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        classpath 'com.github.ben-manes:gradle-versions-plugin:0.13.0' // version plugin support
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

plugins {
    id "org.sonarqube" version "2.1" // https://plugins.gradle.org/plugin/org.sonarqube
}

apply plugin: 'com.android.application'
apply plugin: 'com.github.ben-manes.versions' // ./gradlew dependencyUpdates -Drevision=release
apply plugin: 'sonar-runner'
apply plugin: 'android-apt'
apply plugin: 'com.google.gms.google-services'

repositories {
    jcenter()
}

def versionMajor = 1
def versionMinor = 0
def versionPatch = 0
def versionBuild = 0
def versionMajorMinorPatchBuild = "${versionMajor}.${versionMinor}.${versionPatch}.${versionBuild}"
def versionString = "${versionMajor}.${versionMinor}.${versionPatch}"
def versionStringFull = "${versionMajor}.${versionMinor}.${versionPatch}.${versionBuild}"

android {
    compileSdkVersion 25
    buildToolsVersion "24.0.3"

    dexOptions {
        javaMaxHeapSize "4g"
    }

    defaultConfig {
        applicationId "skipasses.android.abc.123.skipasses"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    // set dummy signing values if not defined in ~/.gradle/gradle.properties
    if (!project.hasProperty('SkiPassKeyStoreFile')) {
        println "Using dummy signing values"
        project.ext.setProperty('SkiPassKeyStoreFile', 'dummy.keystore')
        project.ext.setProperty('SkiPassKeyStorePassword', 'dummy!')
        project.ext.setProperty('SkiPassKeyAlias', 'dummy')
        project.ext.setProperty('SkiPassKeyPassword', 'dummy!')
    }

    // defined on the build server in the /usr/share/tomcat/.gradle/gradle.properties
    signingConfigs {
        release {
            storeFile file(SkiPassKeyStoreFile)
            storePassword SkiPassKeyStorePassword
            keyAlias SkiPassKeyAlias
            keyPassword SkiPassKeyPassword
        }
        lwa {
            storeFile file('keystore.jks')
            keyAlias 'androiddebugkey'
            keyPassword 'android'
            storePassword 'android'
        }
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }

    buildTypes {
        release {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField "String", "VERSION_NAME_FULL", "\"${versionString}\""
            signingConfig signingConfigs.release
        }
        debug {
            versionNameSuffix '-DEV'
            buildConfigField "String", "VERSION_NAME_FULL", "\"${versionStringFull}${versionNameSuffix}\""
        }
        beta {
            versionNameSuffix '-BETA'
            //noinspection GroovyAssignabilityCheck
            signingConfig android.signingConfigs.debug
            zipAlignEnabled true
            buildConfigField "String", "VERSION_NAME_FULL", "\"${versionStringFull}${versionNameSuffix}\""
        }
    }

    lintOptions {
        abortOnError false
    }
}

ext {
    // versions for libraries that multiple dependencies
    supportLibVersion = '25.0.0'
    dagger = '2.7'
    butterknife = '8.4.0'
    pocketknife = '3.2.1'
}

dependencies {
    // Support Libraries
    compile "com.android.support:appcompat-v7:${supportLibVersion}"
    compile "com.android.support:design:${supportLibVersion}"

    // Dependency Injection dependencies
    compile "com.google.dagger:dagger:${dagger}"
    apt "com.google.dagger:dagger-compiler:${dagger}"

    // View Binding
    compile "com.jakewharton:butterknife:${butterknife}"
    apt "com.jakewharton:butterknife-compiler:${butterknife}"

    compile "com.vikingsen:pocketknife-core:${pocketknife}"
    apt "com.vikingsen:pocketknife-compiler:${pocketknife}"

    // Unit Testing
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    // Firebase
    compile 'com.google.firebase:firebase-auth:9.8.0'
    compile 'com.firebaseui:firebase-ui-database:0.6.1'
    compile 'com.firebaseui:firebase-ui-auth:0.6.1'
    compile 'com.google.firebase:firebase-core:9.8.0'
    compile 'com.android.support:support-v4:25.0.0'
    compile 'com.android.support:recyclerview-v7:25.0.0'
    testCompile 'junit:junit:4.12'
    provided 'javax.annotation:jsr250-api:1.0'
}

sonarqube { //./gradlew sonarqube aDebug
    properties {
        if (!project.hasProperty("abc123SonarHostUrl")) {
            println '!!!! ABC123 Sonar properties must be set in your gradle.properties !!!!'
            return
        }

        // Project Information
        property "sonar.projectKey", "SkiPasses"
        property "sonar.projectName", "SkiPasses"
        property "sonar.projectVersion", versionMajorMinorPatchBuild

        // Sonar Information
        property "sonar.host.url", abcSonarHostUrl
        property "sonar.jdbc.url", abcSonarJdbcUrl
        property "sonar.jdbc.driverClassName", abcSonarJdbcDriver
        property "sonar.jdbc.username", abcSonarUsername
        property "sonar.jdbc.password", abcSonarPassword

        properties["sonar.sources"] = "src/main" //android.sourceSets.main.java.srcDirs
        properties["sonar.tests"] = android.sourceSets.androidTest.java.srcDirs

        if (file("build/intermediates/classes/debug").exists()) {
            properties["sonar.binaries"] = [file("build/intermediates/classes/debug")]
        }
        if (file("build/intermediates/classes/beta").exists()) {
            properties["sonar.binaries"] = [file("build/intermediates/classes/beta")]
        }
    }
}

And the Activity:

package abc123.android.abc.123.skipasses.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import com.google.firebase.auth.FirebaseAuth;

import abc123.android.abc.123.skipasses.R;

public class DashboardActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dashboard);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();
        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        //Todo: figure out why the BuildConfig is not being fetched
//        TextView textView = (TextView) findViewById(R.id.version_text);
//        textView.setText(getString(R.string.version_number, BuildConfig.VERSION_NAME));
    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        int id = item.getItemId();
        //TODO Create fragments for each menu item
        if (id == R.id.nav_my_reservations) {
        } else if (id == R.id.nav_make_reservation) {
        } else if (id == R.id.nav_settings) {
        } else if (id == R.id.nav_log_out) {
            FirebaseAuth.getInstance().signOut();
            Intent loginIntent = new Intent(DashboardActivity.this, LoginActivity.class);
            startActivity(loginIntent);
        }
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }
}

I've tried doing a clean build. I can't find duplicate libraries. I can't see where there are play-services and firebase not lining up in version numbers. I just don't see how this error is happening. Any guidance would be appreciated.

like image 992
Ken C Avatar asked Nov 01 '16 17:11

Ken C


2 Answers

Had the same issue and I figured out that one of my dependency was using a different version of the PlayServices than the one given in the firebase dependency line.

Had

compile 'com.google.android.gms:play-services-analytics:9.6.1'
compile 'com.google.firebase:firebase-messaging:9.8.0'

Changed to

compile 'com.google.android.gms:play-services-analytics:9.6.1'
compile 'com.google.firebase:firebase-messaging:9.6.1'

Also, as mentionned earlier, you should place apply plugin: 'com.google.gms.google-services' at the bottom of your build.gradle file.

like image 54
Loïc Avatar answered Nov 10 '22 01:11

Loïc


The documentation for Firebase UI indicates version 0.6.2 should be used with Firebase/Google Play Services libraries version 9.8.0.

Change:

compile 'com.firebaseui:firebase-ui-database:0.6.1'
compile 'com.firebaseui:firebase-ui-auth:0.6.1'

to:

compile 'com.firebaseui:firebase-ui-database:0.6.2'
compile 'com.firebaseui:firebase-ui-auth:0.6.2'

Also, apply plugin: 'com.google.gms.google-services' should be placed at the bottom of the build.gradle file.

You have multiDexEnabled true but do not include compile 'com.android.support:multidex:1.0.1' in your dependencies. It's not clear if you need Multidex, but without the library and configuration in your manifest, it will not be enabled.

like image 20
Bob Snyder Avatar answered Nov 10 '22 01:11

Bob Snyder