【问题标题】:duplicate entry error after adding google services添加谷歌服务后重复输入错误
【发布时间】:2016-05-25 02:48:49
【问题描述】:

我想将 firebase 添加到我的一个应用程序中。我根据firebase官方文件集成了firebase。但是当我尝试“运行”应用程序时。它给了我这个警告

错误:任务 ':app:transformClassesWithJarMergingForDebug' 执行失败。 com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com/google/android/gms/internal/zzc.class

我删除了所有 firebase 编码并将其从 gradle 文件中删除。但错误仍然存​​在,直到我删除此行

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

但不幸的是,我需要 google 服务才能使用 firebase。这是我的应用程序 gradle 文件

 apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.3'

    defaultConfig {
        applicationId ""
        minSdkVersion 19
        targetSdkVersion 22
        versionCode 15
        versionName "2.01"
        multiDexEnabled true
    }

    dexOptions {
        preDexLibraries = false
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/main.jar')
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:cardview-v7:23.0.+'
    compile 'com.android.support:recyclerview-v7:23.0.+'
    compile 'com.squareup.picasso:picasso:2.5.0'
    compile 'com.commit451:NativeStackBlur:1.0.1'
 compile 'com.google.firebase:firebase-analytics:9.0.0'
    compile 'com.github.bumptech.glide:glide:3.6.1'
    compile 'com.facebook.android:audience-network-sdk:4.11.0'
}
apply plugin: 'com.google.gms.google-services'

这是我的项目 gradle 文件

 buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

【问题讨论】:

  • 你能完整显示你的两个 build.gradle 文件吗?
  • 我用两个 build.gradle 文件更新了问题
  • 你有这个类在同一个罐子里吗?
  • 其实我发现了问题所在。问题出在 Facebook 受众网络

标签: android firebase google-play-services


【解决方案1】:

问题出在 Facebook Audience 网络上。一旦我排除了谷歌服务,它就可以正常工作。如果有同样问题的人像这样改变你的受众网络依赖

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

【讨论】:

【解决方案2】:

添加这些依赖项:

compile 'com.google.android.gms:play-services-location:11.0.4'
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.google.android.gms:play-services-gcm:11.0.4'
compile 'com.google.android.gms:play-services-places:11.0.4'

【讨论】:

    【解决方案3】:

    添加

    android{
    ....
        packagingOptions {
                exclude 'META-INF/LICENSE'
                exclude 'META-INF/LICENSE-FIREBASE.txt'
                exclude 'META-INF/NOTICE'
            }
    
    }
    

    到您应用的 gradle 文件。

    【讨论】:

    • 它没有解决问题。仍然得到同样的错误
    【解决方案4】:

    添加 Firebase 相关的依赖项

    和Firebase相关的依赖在同一个build.gradle文件的dependencies下。

    依赖{ compile 'com.google.firebase:firebase-core:9.2.0' // 必须包含此行才能与 Firebase 集成 compile 'com.google.firebase:firebase-messaging:9.2.0' // 必须包含此行才能使用 FCM }

    使用 com.google.android.gms:play-services 更新服务

    如果您将 Firebase 添加到使用 gms:play-services 的任何功能(例如 gps 位置)的现有项目中, 你也必须更新他们的版本。在编写本教程后,9.2.0 运行良好。如果您遇到编译问题,您需要检查找出正确的版本号。

    编译'com.google.android.gms:play-services-location:9.2.0'
    编译 'com.google.android.gms:play-services-places:9.2.0'

    来源: https://www.codementor.io/flame3/send-push-notifications-to-android-with-firebase-du10860kb

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多