react-native-google-sign-in
react-native-google-sign-in copied to clipboard
Build Failed: com.android.dex.DexException
I followed exactly all setup instructions on a brand new macOS with brand new react-native 0.45.1
and checked that all files are as described in the README. But running react-native run-android
build fails with the following error:
Running dex in-process requires build tools 23.0.2.
For faster builds update this project to use the latest build tools.
Dex: Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/firebase/iid/zzb;
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/firebase/iid/zzb;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
:app:transformClassesWithDexForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Is there a way to fix this?
I get his also when just running the example app. A fix would be greatly appreciated.
I followed this and I was able to run the example! https://stackoverflow.com/questions/38191170/multiple-dex-files-define-lcom-google-firebase-firebaseexception
@grigored Hi, I can't fix it. Could you please provide your app/build.gradle file?
This is the relevant part of what I have in app/build.graddle
android {
compileSdkVersion 25
buildToolsVersion '26'
defaultConfig {
applicationId "com.appId"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
///more stuff
}
dependencies {
compile(project(":react-native-google-sign-in")) { // ADD this
exclude group: "com.google.android.gms"
}
compile "com.google.android.gms:play-services-auth:10.0.1"
compile project(':react-native-fbsdk')
compile(project(':react-native-maps')){
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
}
compile 'com.google.android.gms:play-services-base:10.0.1'
compile 'com.google.android.gms:play-services-maps:10.0.1'
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
}
apply plugin: "com.google.gms.google-services" // Add this after dependencies.
And this is my top build.graddle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.0.0' // Add this
// 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"
}
}
}
@grigored I'm still have the exception after run 'react-native run-android' :
Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/firebase/iid/zzb;
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/firebase/iid/zzb;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
It is my dependencies from app/build.gradle file:
dependencies {
compile(project(":react-native-google-sign-in")) {
exclude group: "com.google.android.gms"
}
compile project(':react-native-fbsdk')
compile project(':react-native-hockeyapp')
compile project(':react-native-sensors')
compile project(':react-native-ble-manager')
compile project(':react-native-localization')
compile project(':react-native-audio')
compile project(':react-native-beacons-manager')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.google.android.gms:play-services-auth:10.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile project(':react-native-device-info')
compile project(':react-native-google-analytics-bridge')
}
apply plugin: "com.google.gms.google-services"
And it is my android/build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'net.hockeyapp.android:HockeySDK:4.1.2'
classpath 'com.google.gms:google-services:3.0.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"
}
}
}
i'm no Android expert, so can't help you on this. But maybe you can try to start simple, run the example first, make sure that works, and then add the additional dependencies one by one and see which one causes the problem
Finally, I've fixed it using 11.0.2 version for play-services-auth:
compile(project(":react-native-google-sign-in")) {
exclude group: "com.google.android.gms"
}
compile "com.google.android.gms:play-services-auth:11.0.2"
@grigored @valerybodak @BerndWessels
Sorry for the delay, I am fully occupied at the moment so that I don't really have time to put on this project, but I did research a bit.
This issue really seems to depend on your own project's module dependencies whether you have other libraries that also uses com.google.android.gms
package group, which is very likely in most cases as it is very commonly used library.
It only becomes a problem if there are conflicts on the versions for the same library.
It happened to me too and I had to manually check project dpendencies and explicitly force versions on commonly used libraries.
I used the following commands to see my android module dependencies (run them on your app/android
folder):
./gradlew app:dependencyInsight --configuration compile
./gradlew -q app:dependencies
I currently don't have a better solution to this. To my knowledge there is no one for all solution to this issue as it will differ for each project settings. I wish Android package manager is smart enough to handle these conflicts automatically, but unfortunately it's not. You can search StackOverflow and there are tons of questions regarding the same issue.
If someone who's an Android expect has a better solution that is more automatic, then please share it with us!
core problem is when you run react-native link, its linking twice, so you should remove entry in settings.gradle and build.gradle and mainApplication.java(imports/ initializing) better way to fix it is avoiding linking google-signin package twice.
@valerybodak 's solution also worked for me. I'm not actually even using this library but reviewing the dependencies as @joonhocho suggested, then excluding them with exclude group: "com.google.android.gms"
got me past this issue.
I implemented @joonhocho 's solution and worked for me.
-
cd android/
-
./gradlew app:dependencyInsight --configuration compile
-
./gradlew -q app:dependencies > /some/path/file.txt
- Open the file with a text editor
- Looking for
com.google.android.gms
, view the version number used and put the same number in every place where appearcom.google.android.gms:service
onandroid/app/build.gradle
For example:compile "com.google.android.gms:play-services-auth:NUMBER OF VERSION"