Reputation: 2159
I encountered a problem with the Firebase integration. First of all, I have added rules to the root-level build.gradle
file:
buildscript {
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And the module Gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24"
defaultConfig {
applicationId "com.example.app"
minSdkVersion 14
targetSdkVersion 24
versionCode 2
versionName "0.9"
}
buildTypes {
///
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.firebase:firebase-core:9.0.2'
compile 'com.google.firebase:firebase-crash:9.0.2'
}
apply plugin: 'com.google.gms.google-services'
During the build of the project, I get the error:
Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/firebase/FirebaseException;
Error reason is clear, but I didn't compile any library twice. Should I exclude FirebaseException
class from the build process manually? If so, how? Perhaps this is a bug within the Firebase dependencies?
Thanks.
Upvotes: 24
Views: 20757
Reputation: 1
This is because some of your libraries use different versions of other library.
Check out your last added library and exclude. For my project that was 'react-native-firestack'.
compile(project(':react-native-firestack')){
exclude group: "com.google.android.gms" // very important
}
Upvotes: 0
Reputation: 2607
I am using react-native-maps and react-native-google-signin.
And, I got Multiple dex files define Lcom/google/firebase/FirebaseException
Bellow my solution.
Open build.gradle (react-native-maps)
dependencies {
provided "com.facebook.react:react-native:+"
compile "com.google.android.gms:play-services-base:10.2.4"
compile "com.google.android.gms:play-services-maps:10.2.4"
}
The version is 10.2.4
Continue open build.gradle (react-native-google-signin)
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "com.android.support:appcompat-v7:23.0.1"
compile 'com.google.android.gms:play-services-auth:9.2.1' <- change here
compile "com.facebook.react:react-native:+"
}
It uses version 9.2.1, and this is reason.
Change it to version 10.2.4 will be
compile 'com.google.android.gms:play-services-auth:10.2.4'
Next, open build.gradle (app) and add a new one
compile 'com.google.android.gms:play-services-auth:10.2.4'
Now you have.
compile 'com.google.android.gms:play-services-auth:10.2.4'
compile(project(":react-native-google-signin")){
exclude group: "com.google.android.gms"
}
Run command cd android & gradlew clean & cd ..
util no error then run react-native run-android
.
Hope can help.
Upvotes: 2
Reputation: 22394
Thanks to this post, just check and upgrade your google dependencies versions to the last release.
I could fix my problem. The problem was that BaseGameUtils was still using/referencing an older version of play-services. Added the correct version, and it works now. Guess I will omit BaseGameUtils for my next project.
Upvotes: 0
Reputation: 1203
In case it helps anyone, I was hitting a similar problem, it was caused by the Gradle plugin for Google services bringing in a dependency which conflicted with Firebase.
In my top level build.gradle I had, in buildscript:
classpath 'com.google.gms:google-services:3.0.0'
Which was bringing in (automatically) dependencies which were conflicting with, in my app's build.gradle:
compile 'com.firebaseui:firebase-ui-auth:2.2.0'
Little bit confusing as I only had one compile dependency and was scratching my head what could be conflicing.
I removed the google-services gradle plugin and it solved the issue. I suppose I could also just find the right version :)
Upvotes: 1
Reputation: 544
FireBase is a huge library, so you need to enable multidex support in your application.
dependencies {
compile ('com.google.firebase:firebase-core:9.0.2') {
exclude module: 'play-services-base'
exclude module: 'support-v4'
exclude module: 'support-annotations'
}
compile 'com.android.support:multidex:1.0.1'
}
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}
Upvotes: 5
Reputation: 12021
I encountered this error when I was using firebase-ui:2.0.0. I managed to solve it by downgrading to 'com.firebaseui:firebase-ui:1.2.0'
and added the following line in Project level build.gradle:
allprojects {
repositories {
jcenter()
// Add the following
maven {
url 'https://maven.fabric.io/public'
}
}
}
Upvotes: 0
Reputation: 1539
Please add this code inside android in build.gradle
dexOptions {
preDexLibraries = false
}
Upvotes: -2
Reputation: 6689
I had this problem with react-native-google-signin
module. As the instructions how to modify build.gradle
are often not up to date, incomplete or just defined in multiple unrelated projects the project compiled only after copying the settings from the react-native-google-signin
example project. It turns out the order of statements is important as well as exclude group
command. The final result looked like this (in app/build.gradle
):
dependencies {
...
compile 'com.google.android.gms:play-services-auth:9.2.1'
compile(project(":react-native-google-signin")) {
exclude group: "com.google.android.gms"
}
}
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
The top build.gradle
included an additional gms
classpath as usual:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.google.gms:google-services:3.0.0'
}
}
After these changes build finished without any Multiple dex
errors.
Upvotes: 14
Reputation: 9102
Looks like you have reached methods count limit. Try to remove firebase
dependencies and check methods count for your app (for example, with this gradle plugin (if you don't remove these dependencies you won't be able to build your project at all, thus, to use the methods count plugin).
Firebase is a HUGE library - 17k+ methods. It depends on tons of stuff. One thing you can do is to check dependencies list by clicking this button on "methodscount.com":
If you already have some of these in your project you can try to exclude them:
compile ('com.google.firebase:firebase-core:9.0.2') {
exclude module: 'play-services-base'
exclude module: 'support-v4'
exclude module: 'support-annotations'
}
If this doesn't help then you might want to configure multidex for you project.
Upvotes: 3