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)
@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:
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
and
Switching all the Google stuff from version
15.0.1to12.0.1did 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:
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:
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.