【问题标题】:App cannot be installed in device after integrating firebase notification集成firebase通知后无法在设备中安装应用程序
【发布时间】:2017-04-18 13:42:51
【问题描述】:

我已添加这些行以将 Firebase 通知集成到我的应用中

build.gradle(module:app)

apply plugin: 'com.android.appname'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
    applicationId "com.example.app"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
    "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true

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

dependencies {
compile fileTree(dir: 'libs')
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.facebook.android:audience-network-sdk:4.21.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
}
apply plugin: 'com.google.gms.google-services'

build.gradle(project:appName)

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

 allprojects {
    repositories {
       jcenter()
     }
  }

  task clean(type: Delete) {
       delete rootProject.buildDir
  }

如果我在添加这些依赖项后尝试运行应用程序,则会显示以下错误:

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

【问题讨论】:

  • 请从您的build.gradle 文件中发布整个依赖项集,而不仅仅是compile 'com.google.firebase:firebase-messaging:10.2.1' 行。
  • @CommonsWare 更新问题
  • libs/ 有什么东西吗?此外,您可能需要运行 Gradle 依赖关系报告,以查看 Facebook 是否正在提取任何 com.google 工件,这些工件可能与您现在从 Firebase 获得的工件重复。
  • @CommonsWare 我没有任何“库/”
  • 那么我最好的猜测是 Firebase 和 Facebook 代码之间的冲突。由于我没有使用这些,我没有具体的建议。

标签: android firebase firebase-notifications


【解决方案1】:

依赖关系报告显示audience-network-sdkcom.google.android.gms:play-services-ads:8.4.0 具有传递依赖关系。这就是冲突的根源。

我不使用 Facebook 库,也不确定最佳解决方案。这两个选项都允许您构建。我不知道每个人是否都会支持您的代码。您必须进行实验:

选项 1:

compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile ('com.facebook.android:audience-network-sdk:4.21.1', {
    exclude group: 'com.google.android.gms', module: 'play-services-ads'
})
compile 'com.google.firebase:firebase-messaging:10.0.1'

选项 2:

compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.facebook.android:audience-network-sdk:4.21.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
compile 'com.google.android.gms:play-services-ads:10.0.1'

【讨论】:

  • 这两个选项都运行良好。非常感谢,你拯救了我的一天:)
【解决方案2】:

尝试在 build.gradle 的 buildTypes 之后添加 PackagingOptions

包装选项代码

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

    }

编辑代码

apply plugin: 'com.android.appname'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
    applicationId "com.example.app"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
   "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true

}
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(dir: 'libs')
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.facebook.android:audience-network-sdk:4.21.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
}
apply plugin: 'com.google.gms.google-services'

【讨论】:

    猜你喜欢
    • 2020-06-30
    • 1970-01-01
    • 2020-01-19
    • 2014-01-17
    • 1970-01-01
    • 2016-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多