Multiple dex files define Lcom/google/firebase/FirebaseException - android

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.

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.

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
}

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.

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.

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

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

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.

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
}

Please add this code inside android in build.gradle
dexOptions {
preDexLibraries = false
}

Related

Program type already present: android.support.v4.app.BackStackRecord$Op

I got this error every time I try to run my android game:
Program type already present: android.support.v4.app.BackStackRecord$Op
Message{kind=ERROR, text=Program type already present: android.support.v4.app.BackStackRecord$Op, sources=[Unknown source file], tool name=Optional.of(D8)}
this is my build.gradle (app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.play.flyaway"
minSdkVersion 21
targetSdkVersion 27
ndk {
moduleName "player_shared"
}
}
sourceSets {
main {
jni.srcDirs = []
}
}
buildTypes{}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
implementation 'com.google.android.gms:play-services:12.0.1'
implementation files('libs/dagger-1.2.2.jar')
implementation files('libs/javax.inject-1.jar')
implementation files('libs/nineoldandroids-2.4.0.jar')
implementation files('libs/support-v4-19.0.1.jar')
}
build.gradle (Project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
}
}
allprojects {
repositories {
jcenter()
google()
}
}
Any solution to this problem? I already try everything I know of course, but I'm new on this, I really don't know what cause the error apart from what the console says
You need to remove the following dependency:
implementation files('libs/support-v4-19.0.1.jar')
and also remove the jar from libs directory. Then use the matching support library of your compileSdkVersion. So, change the above dependency with:
implementation 'com.android.support:support-v4:27.1.1'
This is related with Google play service dependency:
SDK Version Support in 11.2
When you upgrade your app’s Play services dependencies to 11.2.0 or
later, your app’s build.gradle must also be updated to specify a
compileSdkVersion of at least 26 (Android O). This does not change the
way your app runs. You will not be required to update
targetSdkVersion.
It's about duplicated support library used :
This dependency:
implementation files('libs/nineoldandroids-2.4.0.jar')
is using old version of support library. Try excluding the support library with:
implementation files('libs/nineoldandroids-2.4.0.jar'){
exclude group: 'com.android.support'
exclude module: 'appcompat-v7'
exclude module: 'support-v4'
}
This Problem is caused due to the versions of the support file and plays service. Update the play service dependencies as per the recommendations(Latest) and sync the project.
compile 'com.google.android.gms:play-services:12.0.1'
I have used only support:AppCompat, so having this problem
Solved this using implementation 'com.android.support:design:____'
implementation 'com.android.support:support-v4:____' along with AppCompat
In my case the problem was I already had the jar present in lib/ folder. Deleting it resolved the problem.
So check if you have jar present in any folder:
find . -name *.jar
If present in lib folder try deleting it

Error [DuplicatePlatformClasses] class conflict when building release on Room persistence

I have used this guide to build persistence with Room in my Android App:
https://developer.android.com/training/data-storage/room/index.html
and added dependances like shown here:
https://developer.android.com/topic/libraries/architecture/adding-components.html
when i build the debug version and deply to phone, everithing works fine.
When i build the release signed APK i got this error message:
Error:Error: json defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
my app.gradle:
apply plugin: 'com.android.application'
android {
signingConfigs {
/* TODO(developer): Configure to sign app with a release key for testing.
release {
storeFile file('path/to/release/signing/key')
keyAlias 'release_key_alias'
keyPassword "${password}"
storePassword "${password}"
}*/
}
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "myappid"
minSdkVersion 14
targetSdkVersion 23
versionCode 10
versionName "1.8"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// TODO(developer): uncomment below once config above is complete and uncommented.
//signingConfig signingConfigs.release
}
}
}
configurations {
all {
exclude module: 'httpclient'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:26.1.0'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.volley:volley:1.0.0'
compile 'com.github.nkzawa:socket.io-client:0.3.0'
compile 'io.socket:socket.io-client:0.8.3'
compile 'com.android.support:design:26.1.0'
compile 'android.arch.persistence.room:runtime:1.0.0'
implementation "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
}
my project.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
//classpath 'io.socket:socket.io-client:0.8.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
ext{
roomVersion = '1.0.0'
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
}
}
Somebody can help or give me clues?
I finally found the problem was a JSON sub-module:
compile 'com.github.nkzawa:socket.io-client:0.3.0'
this library has a submodule:
org.json:json
that is now conflicting with android native module, because in my other dependancies i can't find this one. It was working fine 10 days ago.
I also had to kill this:
compile 'io.socket:socket.io-client:0.8.3'
the final solution was to add an exclude for the module and change the line like this:
implementation ('com.github.nkzawa:socket.io-client:0.3.0',{
exclude group:'org.json', module:'json'
})
I also have noticed AFTER i solved the problem that in the error log it was suggesting me the module that was in conflict but even if i read it a hundred times i didn't noticed before:
so maybe google or Intellij could improve the writing of this errors...
To spot this class duplicate conflict error module i found the best way to proceed is to create a new project and paste in the dependancies in app build.gradle, and check them one by one or with "dividi et impera", maybe this is an obvious suggestion for someone but i would have like to have it sooner.
I had the same problem and I searched for the conflict via the gradle dependency tree:
gradlew app:dependencies
Then I excluded the the json module for the conflicting library:
implementation ('<conflicting-library>',{
exclude group:'org.json', module:'json'
})
How to find the duplicate library.
open gradle run window and run such command:
gradle module-name:dependencies
the "module-name" should be your app module's name, for me, it's "osmunda-demo".
then use Ctrl+F to search "commons-logging", you'll find it.
#Romeo has suggested a really great point. Was unable to debug the code for hours. The problem lies within the dependencies that are imported in build.gradle. It may be your own custom sdk/artifact. I had issues with my own library which uses jjwt. I added the exclusion in my sdk but you will have to add it again whenever using the sdk. Make sure to add exclude group: 'org.json', module: 'json' in your artifact implementation.

Manually download dependency file that times out for gradle project in Android Studio

I am trying to add Robobinding with AspectJ using gradle to a new project in Android Studio. When I click "Sync Project with Gradle Files", the process has remained at "Gradle: Download https://jcenter.bintray.com/org/aspectj/aspectjtools/1.8.2/aspectjtools-1.8.2.jar" for the last 8 hours overnight. It did not timeout or throw some error.
I tried to manually download aspectjtools-1.8.2.jar and place in C:\Users\Knobloch.gradle\caches\modules-2\files-2.1\org.aspectj\aspectjtools\1.8.2 but discovered from the nearby folders that they have some sort of GUID subfolder that I would need.
I have tried adding the jar manually in the libs folder and used:
compile files('libs/aspectjtools-1.8.2.jar')
which did not work. (And now I've noticed the gradle compile tree function in my module config would be redundant).
Here is relevant section of my Project build.gradle:
buildscript {
repositories {
jcenter()
maven() {
name 'RoboBinding AspectJPlugin Maven Repository'
url "https://github.com/RoboBinding/RoboBinding-aspectj-plugin/raw/master/mavenRepo"
}
}
dependencies {
classpath 'org.robobinding:aspectj-plugin:0.8.4'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
apply plugin: 'org.robobinding.android-aspectj'
apply plugin: 'com.neenbedankt.android-apt'
And relevant section in my Module:app build.gradle:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:support-v4:22.2.0'
compile "org.robobinding:robobinding:$robobindingVersion"
aspectPath "org.robobinding:robobinding:$robobindingVersion"
//alternatively we can use with-aop-and-dependencies jar(RoboBinding provides a minimal Proguarded with-aop-and-dependencies jar.).
compile("org.robobinding:robobinding:$robobindingVersion:with-aop-and-dependencies") {
exclude group: 'com.google.guava', module: 'guava'
}
aspectPath("org.robobinding:robobinding:$robobindingVersion:with-aop-and-dependencies") {
exclude group: 'com.google.guava', module: 'guava'
}
compile files('libs/aspectjtools-1.8.2.jar')
}
Refer to answer given by #user "Andromeda" here.
If you are using Android Studio 0.8 or above, a more detailed answer is here by #user "SamRad".

Android Studio (IntelliJ) and gradle, how do I add different versions of a dependency?

I need json-lib in my project.
I've added json-lib to my gradle dependencies, and this in turn has dependencies on various commons libraries.
This is the relevant section of my app/build.gradle (updated as per suggestion below from Médéric)
dependencies {
compile 'commons-collections:commons-collections:3.2.1'
compile 'net.sf.json-lib:json-lib:2.4:jdk15'
compile 'commons-beanutils:commons-beanutils:1.8.0'
compile 'commons-lang:commons-lang:2.6'
compile 'commons-logging:commons-logging:1.1.1'
compile 'net.sf.ezmorph:ezmorph:1.0.6'
However when I try to run my app I get the following:
java.lang.IllegalArgumentException: already added:org/apache/commons/collections/ArrayStack;
So the dependency is clashing with the libraries provided with Android Studio I presume.
I've tried to exclude the offending file like this:
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/services/org.apache.commons.collections.ArrayStack'
But that doesn't work.
If I don't include the dependencies above, at runtime I get the following error:
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/commons/collections/map/ListOrderedMap;`
I'm running Android Studio 1.2.1.1 with Gradle version 2.2.1 and Android Plugin version 1.2.3
Added the repositories section of my build.gradle:
allprojects {
repositories {
maven {
url 'http://download.crashlytics.com/maven'
artifactUrls 'http://mvnrepository.com'
}
jcenter()
mavenCentral()
}
}
apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
android {
compileSdkVersion 'Google Inc.:Google APIs:10'
buildToolsVersion "22.0.1"
repositories {
maven {
url 'http://download.crashlytics.com/maven'
artifactUrls 'http://mvnrepository.com'
}
}
This is the code that causes the runtime error:
public static String toString(Object o) {
try {
// the call to JSONObject.fromObject() below causes the runtime error. It is used to detect circular references
JSONObject.fromObject(o);
return objectGraphAsString(o, new StringBuffer()).toString();
} catch (JSONException e) {
...
}
return "";
}
And this is the stacktrace:
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/commons/collections/map/ListOrderedMap;
at net.sf.json.JSONObject.<init>(JSONObject.java:1450)
at net.sf.json.util.CycleDetectionStrategy.<clinit>(CycleDetectionStrategy.java:37)
at net.sf.json.JsonConfig.<clinit>(JsonConfig.java:65)
at net.sf.json.JSONObject.fromObject(JSONObject.java:134)
UPDATED:
I'm now trying to use a different 3rd party library, in this case XStream, and I'm getting similar errors in a clashing dependency.
I can't be the first person who has needed to add a dependency like this. Is the Android build process really this broken?
Have you try to use real dependency instead of a jar file ?
replace
compile files('libs/json-lib-2.4-jdk15.jar')
by
compile 'net.sf.json-lib:json-lib:2.4:jdk15'
and do the same for other libs : gradle will manage to resolve recursive dependencies.
Edit
You need to exclude commons-collections which is common to multiple libraries. Try this
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile('net.sf.json-lib:json-lib:2.4:jdk15') {
exclude group: 'commons-collections', module: 'commons-collections'
}
compile 'commons-beanutils:commons-beanutils:1.8.0'
compile 'commons-lang:commons-lang:2.6'
compile 'commons-logging:commons-logging:1.1.1'
compile 'net.sf.ezmorph:ezmorph:1.0.6'
}

configuration issue. "Configuration with name 'default' not found"

I am relatively new to Android development and VERY new to Android Studio (much more experienced with Eclipse + android plugin). I am trying to edit a github project, but I can't seem to get it to even compile! I have been reading up, and my error seems to have to do with the build.gradle/locations of libraries themselves.
My error is:
Error:Configuration with name 'default' not found.
It also says "Gradle project sync failed, but I think its related to the above error…whatever that means.
My outer build.gradle is:
// 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:0.12.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
And my inner build.gradle file is:
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
defaultConfig {
applicationId "com.wisely.loyalty"
minSdkVersion 14
targetSdkVersion 18
versionCode 17
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':facebook')
compile project(':cwac')
// You must install or update the Support Repository through the SDK manager to use this dependency.
// You must install or update the Support Repository through the SDK manager to use this dependency.
// You must install or update the Support Repository through the SDK manager to use this dependency.
// You must install or update the Support Repository through the SDK manager to use this dependency.
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5'
compile('org.apache.httpcomponents:httpmime:4.3.5') {
exclude module: "httpclient"
}
compile 'com.android.support:support-v13:20.0.0'
compile 'com.google.android.gms:play-services:5.0.+'
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.android.support:support-v4:20.0.0'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.2'
compile 'com.makeramen:roundedimageview:1.3.0'
compile 'com.crashlytics.android:crashlytics:1.+'
}
EDIT:
General file hierarchy
root
.idea
app
libs
cwac
fb
utils
src
… all source files
gradle
build.gradle
settings.gradle
External Libraries
Android API 20 Platform
JDK
EDIT: Settings.gradle:
include ':app', ':facebook', ':cwac', ':utils'
project(':facebook').projectDir = new File('app/libs/facebook')
project(':cwac').projectDir = new File('app/libs/cwac')
project(':utils').projectDir = new File('app/libs/utils')
Progress Update:
I've tried moving the library files around in the directory to no avail. I also tried using my eclipse environment which just seemed to have even more issues. I really need to get this project configured properly!
UPDATE #2:
I have a strong feeling that this has to do with the gradle version since the file configuration seems fine, and its likely my computer that is lacking something. I am new to using gradle. Is there a way to update it? Or is it simply updated through the support libraries in the sdk manager?
Add your library folder in your root location of your project and copy all the library files there. For ex YourProject/library then sync it

Categories

Resources