Search code examples
androidfirebasefirebase-notifications

App cannot be installed in device after integrating firebase notification


I have added these line to integrate firebase notification to my app

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
  }

If I try to run app after adding those dependencies then it shows the following error:

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


Solution

  • A dependency report shows that audience-network-sdk has a transitive dependency on com.google.android.gms:play-services-ads:8.4.0. This is the source of the conflict.

    I don't use the Facebook libs and am not sure of the best solution. These two options will both allow you to build. I don't know if each will support your code. You'll have to experiment:

    Option 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'
    

    Option 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'