amplify-js: React-Native Android build fails

Do you want to request a feature or report a bug? Bug report

What is the current behavior? I followed the Push-Notifications instructions, and Android build fails with the following error:

command:

$ react-native run-android

result:

Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
D8: Program type already present: com.google.android.gms.gcm.PendingCallback
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives

I want to assimilate push-notifications in my app.

What is the expected behavior? Build succeed.

Which versions of Amplify, and which browser / OS are affected by this issue? Did this work in previous versions?

OS: macOS Sierra 10.12.6
NodeJS: 8.11.1
npm: 6.2.0
Yarn: 1.3.2
Watchman: 4.9.0
Android Studio: 3.1.3 AI-173.4819257

Packages:

"react": "^16.4.0",
"react-native": "^0.55.0",
"@aws-amplify/pushnotification": "^1.0.2",
"aws-amplify": "^1.0.2",
"aws-amplify-react-native": "^1.0.2",

android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        maven {
                    url 'https://maven.google.com/'
                    name 'Google'
                }
        jcenter()
    }
    dependencies {
      classpath 'com.android.tools.build:gradle:3.1.2'
      classpath 'com.google.gms:google-services:3.2.0'

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

allprojects {
     repositories {
          mavenLocal()
          jcenter()
          maven {
              // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
              url "$rootDir/../node_modules/react-native/android"
          }
          maven {
              url "https://maven.google.com"
          }
      }
}

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 24 (3 by maintainers)

Most upvoted comments

I’m another person coming from an ejected react native app from Expo. I had the errors mentioned by @bernhardt1

All firebase libraries must be either above or below 14.0.0

and

Program type already present: com.google.android.gms.gcm.PendingCallback

Switching all the Google stuff from version 15.0.1 to 12.0.1 did indeed get rid of the first error although I can’t seem to figure out how to resolve that second one, and I’ve tried most of the solutions provided above.

@saadq Check out this awnser: https://github.com/aws-amplify/amplify-js/issues/1858#issuecomment-475604529

Applying this exclude setup did the trick for me:

implementation (project(':@aws-amplify_pushnotification')){
   exclude group: 'com.firebase'
   exclude group: 'com.google.android.gms', module: 'play-services-gcm'
}

Anyone who use Firebase with newer version will face this problem, Firebase version should be updated in Aws-amplify/push_notification to 16 version, no one would use 12 version in the new project.

I’m another person coming from an ejected react native app from Expo. I had the errors mentioned by @bernhardt1

All firebase libraries must be either above or below 14.0.0

and

Program type already present: com.google.android.gms.gcm.PendingCallback

Switching all the Google stuff from version 15.0.1 to 12.0.1 did indeed get rid of the first error although I can’t seem to figure out how to resolve that second one, and I’ve tried most of the solutions provided above.

@erez-guesty did you find a solution for this? None of the above has helped for me.

I’ve been trying to debug this for half the day, bouncing around between errors.

I ejected an expo project to expokit which added a ton of dependencies into the app/build.gradle:

dependencies {
  compile (project(':amazon-cognito-identity-js')) {
    exclude group: "com.google.firebase"
  }
  compile (project(':@aws-amplify_pushnotification')) {
    exclude group: "com.google.firebase"
  }
  implementation fileTree(dir: 'libs', include: ['*.jar'])

  implementation 'com.android.support:multidex:1.0.1'

  // Our dependencies
  implementation 'com.android.support:appcompat-v7:27.1.1'
  implementation ('com.google.firebase:firebase-core:15.0.1')
  implementation ('com.google.firebase:firebase-messaging:15.0.1')

  // Our dependencies from ExpoView
  // DON'T ADD ANYTHING HERE THAT ISN'T IN EXPOVIEW. ONLY COPY THINGS FROM EXPOVIEW TO HERE.
  implementation 'com.android.support:appcompat-v7:27.1.1'
  implementation 'com.facebook.android:facebook-android-sdk:4.37.0'
  implementation('com.facebook.android:audience-network-sdk:4.99.0') {
    exclude module: 'play-services-ads'
  }
  compileOnly 'org.glassfish:javax.annotation:3.1.1'
  implementation 'com.jakewharton:butterknife:8.4.0'
  implementation 'de.greenrobot:eventbus:2.4.0'
  implementation 'com.amplitude:android-sdk:2.9.2' // Be careful when upgrading! Upgrading might break experience scoping. Check with Jesse. See Analytics.resetAmplitudeDatabaseHelper
  implementation 'com.squareup.picasso:picasso:2.5.2'
  implementation 'com.google.android.gms:play-services-gcm:15.0.1'
  implementation 'com.google.android.gms:play-services-analytics:15.0.1'
  implementation 'com.google.android.gms:play-services-maps:15.0.1'
  implementation 'com.google.android.gms:play-services-auth:15.0.1'
  implementation 'com.google.android.gms:play-services-location:15.0.1'
  implementation 'com.google.android.gms:play-services-ads:15.0.1'
  annotationProcessor 'com.raizlabs.android:DBFlow-Compiler:2.2.1'
  implementation "com.raizlabs.android:DBFlow-Core:2.2.1"
  implementation "com.raizlabs.android:DBFlow:2.2.1"
  implementation "com.madgag.spongycastle:core:1.53.0.0"
  implementation "com.madgag.spongycastle:prov:1.53.0.0"

I’ve been bouncing around between build errors like : All firebase libraries must be either above or below 14.0.0

I updated the firebase-core/firebase-messaging:12.0.1 -> 15.0.1 to get around that one. Not sure how to debug this one though:

Program type already present: com.google.android.gms.gcm.PendingCallback
Message{kind=ERROR, text=Program type already present: com.google.android.gms.gcm.PendingCallback, sources=[Unknown source file], tool name=Optional.of(D8)}

Anyone figure this out?

@viniciusfont your solution helped me, however, I switched from 12 version to 16 version in the project, excluding firebase did the trick!

Thanks @viniciusfont! Going to try it out soon.


Edit: Your solution worked! Build issues were fixed once I added use that snippet, but I had to use :@aws-amplify/pushnotification' instead of :@aws-amplify_pushnotification'.

I started a fresh project today to figure out when the build errors start occurring. Here’s the setup.

start with this tutorial https://blog.expo.io/how-to-build-cloud-powered-mobile-apps-with-expo-aws-amplify-2fddc898f9a2

It seems to be the push notificaiton library causing problems.