重复条目:com / google / android / gms / internal / zzahl.class

时间:2016-11-01 17:39:32

标签: android android-gradle google-play-services

这是我在构建项目时遇到的错误:

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

我似乎无法弄清楚导致错误的原因,我怀疑这是我在我的gradle或Java Activity中搞砸了的东西。这是代码:

摇篮:

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")]
        }
    }
}

活动:

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;
    }
}

我尝试过做一个干净的构建。我找不到重复的库。我看不到游戏服务和firebase在版本号中排队的位置。我只是看不出这个错误是怎么回事。任何指导都将不胜感激。

2 个答案:

答案 0 :(得分:6)

有同样的问题,我发现我的一个依赖是使用不同版本的PlayServices而不是firebase依赖行中给出的版本。

已经

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

已更改为

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

另外,如前所述,你应该放置     build.gradle文件底部的apply plugin: 'com.google.gms.google-services'

答案 1 :(得分:3)

documentation for Firebase UI表示版本0.6.2应与Firebase / Google Play服务库版本9.8.0一起使用。

变化:

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

为:

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

此外,apply plugin: 'com.google.gms.google-services'应为build.gradle文件的placed at the bottom

您有multiDexEnabled true但未在依赖项中包含compile 'com.android.support:multidex:1.0.1'。目前尚不清楚您是否需要Multidex,但没有库和configuration in your manifest,它将无法启用。