aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.4k stars 2.11k forks source link

React-Native Android build fails #1308

Closed erez-guesty closed 5 years ago

erez-guesty commented 5 years ago

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"
          }
      }
}
aris-b commented 5 years ago

I had a similar issue, this happened to me because of firebase library version conflict. I solved it by excluding it from the implementation in app/build.gradle like this

compile (project(":pushnotification")){
        exclude group: "com.google.firebase"
    }

Also changed the alias of the library in ./settings.gradle to this

include ':pushnotification'
project(':pushnotification').projectDir = new File(rootProject.projectDir, '../node_modules/@aws-amplify/pushnotification/android')
erez-guesty commented 5 years ago

@aris-b tried it, still the same error. how does your full android/app/build.gradle and android/build.gradle looks like?

erez-guesty commented 5 years ago

@elorzafe hi, any new updates?

NikitaKis commented 5 years ago

I have the same problem: Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.

com.android.build.api.transform.TransformException: Error while generating the main dex list.

Please help!

Jobel91 commented 5 years ago

Same issue for me. After tried to add the Push Notifications ...

I tried to resolve this by adding "multiDexEnabled = true" because of previous error which looks like : "Program type already present: com.google.android.gms.common.api.zzf", but it wasn't the correct way.

By following this : https://stackoverflow.com/a/49915433/6103744; I edited

googlePlayServicesVersion = "11.8.0"

to match with the firebase version used

googlePlayServicesVersion = "12.0.1"

and build works now.

I hope this will help someone !

benjaminkoetting commented 5 years ago

I have the same error, my versions I use:

buildToolsVersion = "27.0.3" minSdkVersion = 19 compileSdkVersion = 27 targetSdkVersion = 26 supportLibVersion = "27.1.1" googlePlayServicesVersion = "12.0.1"

tried to exclude firebase package like @aris-b did it, but without success

bernhardt1 commented 5 years ago

@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?

bernhardt1 commented 5 years ago

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.

jordanranz commented 5 years ago

@bernhardt1,

Could you post the build error from your latest post above?

vitalii commented 5 years ago

have the same issue. I'm using pure react-native setup, not expo

React Native Environment Info:
    System:
      OS: macOS 10.14.2
      CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
      Memory: 1020.80 MB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.15.1 - ~/.nvm/versions/node/v10.15.1/bin/node
      npm: 6.7.0 - ~/.nvm/versions/node/v10.15.1/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        API Levels: 26, 27, 28
        Build Tools: 27.0.3, 28.0.3
        System Images: android-25 | Google APIs ARM 64 v8a, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5199772
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.6.3 => 16.6.3
      react-native: ^0.58.6 => 0.58.6
    npmGlobalPackages:
      react-native-cli: 2.0.1

had to update in app/build.gradle to 16/17 versions

    compile 'com.google.firebase:firebase-core:16.0.1'
    compile 'com.google.firebase:firebase-messaging:17.4.0'

applied all the solutions from above. no luck

> 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:

is there even working examples for android?

bernhardt1 commented 5 years ago

hi @vitalii

Unfortunately I don't have access to the failing build anymore. This helped me get by some of the build errors: https://github.com/aws-amplify/amplify-js/issues/1415#issuecomment-445624517

I was not able to receive push notifications on android even once I got the build working. I've backlogged notifications for now in my project.

I believe it was a com.google.firebase:firebase and gms:play-services-gcm versioning issue. I had to use 12.0.1 versions across the board to get the build to run. @jordanranz Can amplify push notifications work with the Google services at version 12.0.1?

Here is some of my build.gradle file if you want to reference:

 // Our dependencies
  implementation "com.google.android.gms:play-services-base:12.0.1"
  implementation ('com.google.firebase:firebase-core:12.0.1')
  implementation ('com.google.firebase:firebase-messaging:12.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:12.0.1'
  implementation 'com.google.android.gms:play-services-analytics:12.0.1'
  implementation 'com.google.android.gms:play-services-maps:12.0.1'
  implementation 'com.google.android.gms:play-services-auth:12.0.1'
  implementation 'com.google.android.gms:play-services-location:12.0.1'
  implementation 'com.google.android.gms:play-services-ads:12.0.1'
saadq commented 5 years ago

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.

viniciusfont commented 5 years ago

@saadq You summed it up very well. I'm having exactly the same problem.

viniciusfont commented 5 years ago

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'
}
saadq commented 5 years ago

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

Luckygirlllll commented 5 years ago

Hello all! Is there any updates? Did anyone found working solution so far? I did expo eject, added aws push notification and getting an error now:'Program type already present: com.google.android.gms.gcm.PendingCallback'

Luckygirlllll commented 5 years ago

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

jordanranz commented 5 years ago

Seems like a solution has been posted above.

Anyone still experiencing a related problem for the issue posted?

Luckygirlllll commented 5 years ago

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.

jordanranz commented 5 years ago

3060

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 5 years ago

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

mgonzalezs commented 4 years ago

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: #1858 (comment)

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

Worked!

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.