I'm trying the new MultiDex Support on my app and so far I've managed to compile my app correctly, but when running it, I get the following exception:
java.lang.RuntimeException: Unable to instantiate application android.support.multidex.MultiDexApplication: java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/me.myapp.main-2.apk"],nativeLibraryDirectories=[/data/app-lib/me..main-2, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:507)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4382)
at android.app.ActivityThread.access$1500(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/me.myapp.main-2.apk"],nativeLibraryDirectories=[/data/app-lib/me.myapp.main-2, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:998)
at android.app.LoadedApk.makeApplication(LoadedApk.java:502)
This is my gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 21
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:support-v13:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.0'
}
And my AndroidManifest.xml:
<application
android:name="android.support.multidex.MultiDexApplication">
I don't understand what the problem is. I think I'm doing everything according to the documentation. Is there something else i am missing? I made sure I had the latest support library and repo installed from the SDK manager.
The solution didn't help me because I was using jetpack version ie androidx. libraries.
Followed official doc.
And
I had to change name to androidx....Multidex.
<application
android:name="androidx.multidex.MultiDexApplication" >
...
</application>
Hope It helps other people looking for adding multidex with jetpack.
In my case its solved by changes below code in Manifest from
android:name="android.support.multidex.MultiDexApplication"
to
android:name="androidx.multidex.MultiDexApplication"
My configuration:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.+' // 0.14.1, 2014-11-6
}
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
android {
compileSdkVersion = 21
buildToolsVersion = "21.1.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
multiDexEnabled true
}
}
Unfortunately, I have the same problem. But I found a strange situation:
build/intermediates/dex/debug:
-rw-rw-r-- 1 andrew andrew 2221176 Nov 6 20:18 classes2.dex
-rw-rw-r-- 1 andrew andrew 8357596 Nov 6 20:18 classes.dex
unzip apk, build/outputs/apk:
-rw-rw-r-- 1 andrew andrew 8357596 Nov 6 20:18 classes2.dex
-rw-rw-r-- 1 andrew andrew 2221176 Nov 6 20:18 classes.dex
In apk, the main classes of classes.dex should be bigger than classes2.dex, but its not. I do also dex2jar & unzip jar to check classes, the application class is not there in classes.dex, its in classes2.dex contrarily.
However, I should have fixed it. Here is my patched android gradle plugin you can try:
buildscript {
repositories {
mavenCentral()
maven { url 'https://github.com/yongjhih/android-gradle-plugin.m2/raw/master/' }
}
dependencies {
classpath 'com.infstory.tools.build:gradle:0.14.+'
}
}
The patch is in: https://github.com/yongjhih/android-gradle-plugin/commit/9c2212e3b1b4c6e1f7b47f2086aba1903a6258bf
or
https://android-review.googlesource.com/#/c/113331/
issue: https://code.google.com/p/android/issues/detail?id=78761
The official patch is https://android-review.googlesource.com/#/c/113201/ that already been merged, I think it might be fixed in next version.
Already been fixed 0.14.2 (2014/11/10). (from http://tools.android.com/tech-docs/new-build-system)
Release notes:
0.14.2 (2014/11/10)
Fix potential multi-dex issue where the dex files could be renamed during packaging, leading to the wrong main dex file being used.
Fix versionNameSuffix support
Fix BuildType.initWith to copy shrinkResources flag
setup default proguard rule file if none are provided (SDK/tools/proguard/proguard-android.txt)
BuildType.pseudoLocalesEnabled flag to include fake locales in apk.
Setting up your app project to use a multidex configuration requires that you make the following modifications to your app project, depending on the minimum Android version your app supports.
If your minSdkVersion is set to 21 or higher, all you need to do is set multiDexEnabled to true in your module-level build.gradle file, as shown here:
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
}
...
}
However, if your minSdkVersion is set to 20 or lower, then you must use the multidex support library as follows:
Modify the module-level build.gradle file to enable multidex and add the multidex library as a dependency, as shown here:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
Depending on whether you override the Application class, perform one of the following:
If you do not override the Application class, edit your manifest file to set android:name in the tag as follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows:
public class MyApplication extends MultiDexApplication { ... }
Or if you do override the Application class but it's not possible to change the base class, then you can instead override the attachBaseContext() method and call MultiDex.install(this) to enable multidex:
public class MyApplication extends SomeOtherApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
I recently had this issue. Despite no change to my configuration this error started occurring. I tried all of the suggested solutions including deleting the virtual device and creating a fresh one.
However, I did notice that if I built an APK and dragged it into the emulator to install, it worked fine.
In the end cleaning the project and re-running and then it worked.
For me, the answer was to switch to the androidx versions
android:name="androidx.multidex.MultiDexApplication"
implementation "androidx.multidex:multidex:2.0.1"
I was using the latest Android Studio and following the official document to add support to multidex https://developer.android.com/studio/build/multidex.html . But I still got the same exception. I spent a lot of time solving it. At last, I found the cause was I enabled "Java Exception Breakpoints - Any exception", and "Exception Breakpoints - When any is thrown". After I disabled them, the app ran without problems.
Just follow the official document about multidex https://developer.android.com/studio/build/multidex.html . It works.
Delete ./gradle .idea and build directory
Clean project
Uninstall app if already install on device and again install
In my case I just changed the build.gradle and I leaved the AndroidManifest like that:
android:name=".MainApplication"
I am using React Native.
i jaust changed
in manifest application
android:name="android.support.multidex.MultiDexApplication"
to
android:name="androidx.multidex.MultiDexApplication"
and it's working fine
This worked for me.
File -> Sync Project with Grandle Files
Very strange, I got same error message, but after I fixed some gradle lines it worked. Maybe it helps somebody:
Project build.gradle:
from:
..
dependencies {
// Android Gradle Plugin
classpath 'com.android.tools.build:gradle:3.2.1'
// Analytics
**classpath 'com.google.gms:google-services:3.0.0'**
}
..
to:
..
dependencies {
// Android Gradle Plugin
classpath 'com.android.tools.build:gradle:3.2.1'
// Analytics
**classpath 'com.google.gms:google-services:3.2.1'**
}
..
In the module build.gradle:
from:
..
dependencies {
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:support-compat:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
**implementation 'com.google.android.gms:play-services-analytics:12.0.1'**
}
..
to:
..
dependencies {
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:support-compat:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
**implementation 'com.google.android.gms:play-services-analytics:16.0.5'**
}
..
There was no other changes in my code, but the fixed version worked on 4.x emulators too. Only the ** marked lines are changed.
The Problem is in Gradle File Please Increase the Version That's it
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
}
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.1"
defaultConfig {
applicationId "com.nandeproduction.dailycost"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}}
[Solution] Use this special code
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
Go to manifest -> inside application tag -> directly put your class name with dot or check the package of that file and add that manually.
android:name=".AppController"
Related
I am getting the below exception on app launch.
java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.vfirst.ifbagro-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.vfirst.ifbagro-1, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:4993)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4596)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4536)
at android.app.ActivityThread.access$1300(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5214)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.vfirst.ifbagro-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.vfirst.ifbagro-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.ActivityThread.installProvider(ActivityThread.java:4978)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4596)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4536)
at android.app.ActivityThread.access$1300(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5214)
at java.lang.reflect.Method.invokeNative(Native Method)
Here is the the app level build.gradle
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.vfirst.ifbagro"
minSdkVersion 17
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile 'com.google.android.gms:play-services-location:9.4.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.firebase:firebase-messaging:9.4.0'
compile 'com.google.android.gms:play-services:9.4.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
This is my application level build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.google.gms:google-services:3.0.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
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 {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
How to solve the issue?
I had the same error and I solved it with MultiDex, like described on this link :
https://developer.android.com/studio/build/multidex.html
Sometimes it is not enough just to enable MultiDex.
If any class that's required during startup is not provided in the primary DEX file, then your app crashes with the error java.lang.NoClassDefFoundError.
https://developer.android.com/studio/build/multidex#keep
FirebaseInitProvider is required during startup.
So you must manually specify FirebaseInitProvider as required in the primary DEX file.
build.gradle file
android {
buildTypes {
release {
multiDexKeepFile file('multidex-config.txt')
...
}
}
}
multidex-config.txt (in the same directory as the build.gradle file)
com/google/firebase/provider/FirebaseInitProvider.class
I too faced the same issue and finally solved it by disabling Instant Run in an android studio.
Settings → Build, Execution, Deployment → Instant Run and uncheck Enable Instant Run
Update:
There is no Instant Run option available in latest Android Studio 3.5+. It should be applicable only for older versions.
In the build.gradle(Module:app) file, insert the code below into defaultConfig :
defaultConfig {
applicationId "com.***.****"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
}
and insert into to dependencies :
implementation 'com.android.support:multidex:2.0.1'
Then add code to manifest :
<application
android:name="android.support.multidex.MultiDexApplication"
I had the same problem in my (YouTube player project)... and the following solved the problem for me:
Add this code into your build.gradle (module: app) inside defaultConfing:
defaultConfig {
....
....
multiDexEnabled = true
}
Add this code into your build.gradle (module: app) inside dependencies:
dependencies {
compile 'com.android.support:multidex:1.0.1'
.....
.....
}
Open AndroidManifest.xml and within application:
<application
android:name="android.support.multidex.MultiDexApplication"
.....
.....
</application>
or if you have your App class, extend it from MultiDexApplication like:
public class MyApp extends MultiDexApplication {
.....
And finally, I think you should have Android Support Repository downloaded, in the Extras in SDK Manager.
Just override the following method in your application class.
public class YourApplication extends Application {
#Override
protected void attachBaseContext(Context context) {
super.attachBaseContext(context);
MultiDex.install(this);
}
#Override
public void onCreate() {
super.onCreate();
Realm.init(this); //initialize other plugins
}
}
When your app and the libraries it references exceed 65,536 methods, you encounter a build error that indicates your app has reached the
limit of the Android build architecture
To avoid this limitation you have to configure your app for multidex
If your minSdkVersion is set to 21 or higher, all you need to do is
set multiDexEnabled to true in your module-level build.gradle file, as
shown here:
android {
defaultConfig {
...
minSdkVersion 21
multiDexEnabled true
}
...
}
Else, if your minSdkVersion is set to 20 or lower, then you must
use the multidex support library as follows:
1.Modify the module-level build.gradle file to enable multidex and add the multidex library as a dependency, as shown here:
android {
defaultConfig {
...
minSdkVersion 15
multiDexEnabled true
}
...
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
2.Depending on whether you override the Application class, perform one of the following:
If you do not override the Application class, edit your manifest file to set android:name in the tag as follows:
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
Else If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows:
public class MyApplication extends MultiDexApplication { ... }
Else you do override the Application class but it's not possible to change the base class, then you can instead override the
attachBaseContext() method and call MultiDex.install(this) to enable
multidex:
public class MyApplication extends SomeOtherApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Enabling multidex is not a good solution because multidexhave another usage in android see this answer what is multidex
The solution is disabling instant run as #Shylendra Madda said
Settings → Build, Execution, Deployment → Instant Run and uncheck Enable Instant Run
I think the reason of this problem is when instant run is enabled, Android Studio don't put libraries such as firebase into generated apk to decreasing project build time because firebase library and other libraries such as maps and others is exist in play services and play services is installed on android device so if instant run enabled don't need to put them in generated apk to make build time faster.
So when you extract apk and install it on another device you will see this exception
I have also face the same issue after trying all solution I found the below solution.
If you have applied proguard rules then add below line in ProGuard Rules
-keep class com.google.firebase.provider.FirebaseInitProvider
and its solve my problem.
1: Go to the gradle enable multiDexEnabled and add the multidex library in the dependencies.
android {
...
defaultConfig {
multiDexEnabled true
...
}
}
dependencies {
// add dependency
implementation 'com.android.support:multidex:1.0.1'
}
2: Go to the Manifest file and write android:name=".MyApplication" (Class name(MyApplication) is optional you can write whatever you want ).
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
.
.
.
.
.
</application>
3: As you wrote android:name=".MyApplication" Inside Application at Manifest file. it will give you an error because you didn't create MyApplication class. Create MyApplication Class extend it by "application" class or Simply click on.MyApplication, a small red balloon appear on the left side of a syntax click on it, you will see (create MyApplication class) in the menu, click on it and Include below Method Inside that class.
public class MyApplication extends Application {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
If you want to get more information then Click on this Link:[https://developer.android.com/studio/build/multidex.html]
Hopefully, It works for you.
First add the following into build.gradle(Module:app)---->
defaultConfig{
..
multiDexEnabled true
..
}
Then in same file add the following
dependencies{
...
compile 'com.android.support:multidex:1.0.1'
...
}
Then in AndroidManifest.xml write the following
<application
android:name="android.support.multidex.MultiDexApplication"
.....
.....
</application>
That's it. It will definitely work
If you are using MultiDex in your App Gradle then change extends application to extends MultiDexApplication in your application class. It will defiantly work
I had the same issue and solved just add a piece of code, If you are getting this issue means you had already completed all the steps that need to use Firebase. You just need to create a class that extends the Application (public class Application_CrashReport extends Application ) and add this class in mainifest file and In that class just override the below method
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
}
and add MultiDex.install(this); in that method means
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
Note :- Don't forget to follow above steps
This is a bit late for those coming in, but check your proguard rules! I wasted a lot of time on this. Your proguard rules could be changing the names to important firebase files. This really only proves a problem in production and instant run :)
proguard-rules.pro
-keep class com.google.firebase.** { *; }
-keep class com.firebase.** { *; }
-keep class org.apache.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }
-dontwarn org.apache.**
-dontwarn org.w3c.dom.**
As mentioned previously, this is a problem with multidex: you should add implementation to your build.gradle and MainApplication.java. But what you add really depends on whether you support AndroidX or not. Here is what you need to solve this problem:
If you support AndroidX
Put these lines of code into your build.gradle (android/app/build.gradle):
defaultConfig {
applicationId "com.your.application"
versionCode 1
versionName "1.0"
...
multiDexEnabled true // <-- THIS LINE
}
...
...
dependencies {
...
implementation "androidx.multidex:multidex:2.0.1" // <-- THIS LINE
...
}
Put these lines into your MainApplication.java (android/app/src/main/java/.../MainApplication.java):
package com.your.package;
import androidx.multidex.MultiDexApplication; // <-- THIS LINE
...
...
public class MainApplication extends MultiDexApplication { ... } // <-- THIS LINE
If you don't support AndroidX
Put these lines of code into your build.gradle (android/app/build.gradle):
defaultConfig {
applicationId "com.your.application"
versionCode 1
versionName "1.0"
...
multiDexEnabled true // <-- THIS LINE
}
...
...
dependencies {
...
implementation "com.android.support:multidex:1.0.3" // <-- THIS LINE
...
}
Put these lines into your MainApplication.java (android/app/src/main/java/.../MainApplication.java):
package com.your.package;
import android.support.multidex.MultiDex;; // <-- THIS LINE
...
...
public class MainApplication extends MultiDexApplication { ... } // <-- THIS LINE
This is due to MultiDex.
Steps to solve:
In gradle->dependencies->(compile'com.android.support:multidex:1.0.1')
Add this in dependencies
In your project application class extends MultiDexApplication like this (public class MyApplication extends MultiDexApplication)
Run and check
You should extend your Application class with MultiDexApplication instead of Application.
This issue occurred when I switched to Android Studio 3.4 with Android Gradle plugin 3.4.0. which works with the R8 compiler.
The Android Gradle plugin includes additional predefined ProGuard rules files, but it is recommended that you use proguard-android-optimize.txt. More info here.
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile(
'proguard-android-optimize.txt'),
// List additional ProGuard rules for the given build type here. By default,
// Android Studio creates and includes an empty rules file for you (located
// at the root directory of each module).
'proguard-rules.pro'
}
}
I was facing the same problem and i solved this issue by changing the fireabseStorage version the same as the Firebase database version
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:17.0.0'
to
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
If you have > 20 minsdkversion, you need to use the latest Firebase Auth version i.e.
implementation 'com.google.firebase:firebase-auth:18.1.0'
and no need to setup multi-dex if you don't actually need it.
I encountered this issue when I've used 16.0.5 from the Firebase helper but was able to fix it when I've updated to 18.1.0.
If you're using Xamarin.Forms you might want to check out Didn't find class "com.google.firebase.provider.FirebaseInitProvider"? as this captures the issue with the dex error with google firebase on startup (unresolved at this time).
I've reverted to using no shrinking in the short-term and plan to use ProGuard until R8 is more stable.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// add the above code in your app level gradle file just after
defaultConfig{
}
add in project root path google-services.json
dependencies {
compile 'com.android.support:support-v4:25.0.1'
**compile 'com.google.firebase:firebase-ads:9.0.2'**
compile files('libs/StartAppInApp-3.5.0.jar')
compile 'com.android.support:multidex:1.0.1'
}
apply plugin: 'com.google.gms.google-services'
android studio was getting build error while build execution with following:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex"
My app:build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.pdroid.foodieschoice"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
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.firebaseui:firebase-ui-auth:2.3.0'
testCompile 'junit:junit:4.12'
}
configurations.all {
resolutionStrategy {
force 'com.android.support:appcompat-v7:26.0.1'
force 'com.android.support:support-compat:26.0.1'
force 'com.android.support:support-core-ui:26.0.1'
force 'com.android.support:support-annotations:26.0.1'
force 'com.android.support:recyclerview-v7:26.0.1'
}
}
apply plugin: 'com.google.gms.google-services'
any solutions
Edit: i have done with sample through firebase github site and solved
For Cordova based project, run cordova clean android before build again, as #mkimmet suggested.
This error happens when you add an external library which may not be compatible with your compileSdkVersion .
Be careful when you are adding an external library.
I spent 2 days on this problem and finally it got solved following these steps.
Make sure all your support libraries are same as compileSdkVersion of your build.gradle(Module:app) in my case it is 26.
In your defaultConfig category type multiDexEnabled true. This is the important part.
Go to File | Settings | Build, Execution, Deployment | Instant Run and try to Enable/Disable Instant Run to hot swap... and click okay
Sync Your project.
Lastly, Go to Build | click on Rebuild Project.
Note: Rebuild Project first cleans and then builds the project.
Try to add this in gradle
android {
defaultConfig {
multiDexEnabled true
}
}
Resolution:
Refer to this link: As there are various options to shut the warning off depending on the minSdkVersion, it is set below 20:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
... }
dependencies { compile 'com.android.support:multidex:1.0.3' }
If you have a minSdkVersion greater than 20 in your build.gradle set use the following to shut down the warning:
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
}
... }
Update dependencies as follows:
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
Again the only difference is the keywords in dependencies:
minSdkVersion below 20: use compile
minSdkVersion above 20: use implementation
I hope this was helpful, please upvote if it solved your issue, Thank you for your time.
Also for more info, on why this occurs, please read the first paragraph in the link, it will explain thoroughly why? and what does this warning mean.
Simply try doing a "Build -> Clean Project". That solved the problem for me.
For me, adding
multiDexEnabled true
and
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
into the app level Build.gradle file solved the issue
Go to your module level build.gradle file and add the following lines to the code
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
}
...
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
That solved the problem easily. Check this documentation
Use multiDexEnabled true as below.
{
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
and
implementation 'com.android.support:multidex:1.0.3'
this Solution worked for me.
I tried many solutions as mentioned above including the multiDexEnabled true but none of that worked for me.
Here is the solution which worked for me - copy this code in app\build.gradle file
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support' && requested.name != 'multidex') {
details.useVersion "${rootProject.ext.supportLibVersion}"
}
}
}
Make sure to run gradlew clean before running the code
Same thing happened to me, figured out that I was in the middle of updating to AS 3.0.1 and after I did the update, cleaned and rebuilt the app, everything was fixed.
For me what fixed this error was changing one line in my app's gradle dependencies.
from this:
compile('com.google.android.gms:play-services-gcm:+') {
force = true
}
To this:
compile('com.google.android.gms:play-services-gcm:11.8.0') {
force = true
}
Also be sure your app is subclassing MultiDexApplication
import android.support.multidex.MultiDexApplication
class App : MultiDexApplication()
or if not subclassing Application class, add to AndroidManifest.xml
<application
android:name="android.support.multidex.MultiDexApplication"
This is what works for me. clean prepare and run.
cordova clean android;
ionic cordova prepare andriod;
ionic cordova run andriod;
hope it helps.
I also got the similar error.
Problem :
Solution :
Main root cause for this issue ismultiDex is not enabled.
So in the Project/android/app/build.gradle, enable the multiDex
For further information refer the documentation: https://developer.android.com/studio/build/multidex#mdex-gradle
Are you in between SDK or platform updates?
If yes complete those completely and then try to continue.
I normally update the individual packages that need to be updated as to taking the entire update which could go up to 2.5 GB sometimes. Doing this complete update sometimes fails. I had a number of SDK updates once I upgraded to Android Studio 3.0 and was getting the above error since all packages had not been updated. Once I updated all packages the above error was gone.
In my case changing firebase library version from 2.6.0 to 2.4.2 fixed the issue
For me, the problem was the use of Java 1.8 in a module, but not in the app module. I added this to the app build gradle and worked:
android{
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Same problem. I have enabled multidex:
defaultConfig {
applicationId "xxx.xxx.xxxx"
minSdkVersion 24
targetSdkVersion 26
multiDexEnabled true
I have cleared cache, ran gradle clean, rebuild, make, tried to make sure no conflicts in imported libraries (Removed all transitive dependencies) and made all updates. Still:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Turns out the build did not like:
implementation 'org.slf4j:slf4j-android:1.7.21'
When the version of Android Studio is 3.0.1, Gradle Version is 4.1 and Android PluginVersion is 3.0.0, it will encounter this problem. Then I downgrade Gradle Version is 3.3, Android Android is zero, there is no such problem.
I had this when requested SDK version didn't match the dependencies. You can click the line highlighted and fix this clicking the red light bulb. No need to find the actual version, just let the IDE figure it out for you. And add google repo to maven config.
I was receiving the same error and in my case, the error was resolved when I fixed a build error which was associated with a different build variant than the one I was currently building.
I was building the build variant I was looking at just fine with no errors, but attempting to debug caused a app:transformDexArchiveWithExternalLibsDexMergerForDebug error. Once I switched to build the other build variant, I caught my error in the build process and fixed it. This seemed to resolve my app:transformDexArchiveWithExternalLibsDexMergerForDebug issue for all build variants.
Note that this error wasn't within the referenced external module but within a distinct source set of a build variant which referenced an external module. Hope that's helpful to someone who may be seeing the same case as me!
I Have Done and fixed this issue by just doing this jobs in my code
Open ->build.gradle
Change value
from
compile 'com.google.code.gson:gson:2.6.1'
to
compile 'com.google.code.gson:gson:2.8.2'
1)Please add multiDexEnabled true
2)if you get compilation error then check your app level build.gradle weather same dependencies are implemented with different versions.
3)Remove one if you find same dependencies.
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
hope it works fine :) Happy Coding
The easiest way to avoid suck kind of error is:
-Change library combilesdkversion as same as your app compilesdkversion
-Change library's supportLibrary version as same as your build.gradle(app)
I am getting the below exception on app launch.
java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.vfirst.ifbagro-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.vfirst.ifbagro-1, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:4993)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4596)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4536)
at android.app.ActivityThread.access$1300(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5214)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.vfirst.ifbagro-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.vfirst.ifbagro-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.ActivityThread.installProvider(ActivityThread.java:4978)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4596)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4536)
at android.app.ActivityThread.access$1300(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5214)
at java.lang.reflect.Method.invokeNative(Native Method)
Here is the the app level build.gradle
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.vfirst.ifbagro"
minSdkVersion 17
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile 'com.google.android.gms:play-services-location:9.4.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.firebase:firebase-messaging:9.4.0'
compile 'com.google.android.gms:play-services:9.4.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
This is my application level build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.google.gms:google-services:3.0.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
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 {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
How to solve the issue?
I had the same error and I solved it with MultiDex, like described on this link :
https://developer.android.com/studio/build/multidex.html
Sometimes it is not enough just to enable MultiDex.
If any class that's required during startup is not provided in the primary DEX file, then your app crashes with the error java.lang.NoClassDefFoundError.
https://developer.android.com/studio/build/multidex#keep
FirebaseInitProvider is required during startup.
So you must manually specify FirebaseInitProvider as required in the primary DEX file.
build.gradle file
android {
buildTypes {
release {
multiDexKeepFile file('multidex-config.txt')
...
}
}
}
multidex-config.txt (in the same directory as the build.gradle file)
com/google/firebase/provider/FirebaseInitProvider.class
I too faced the same issue and finally solved it by disabling Instant Run in an android studio.
Settings → Build, Execution, Deployment → Instant Run and uncheck Enable Instant Run
Update:
There is no Instant Run option available in latest Android Studio 3.5+. It should be applicable only for older versions.
In the build.gradle(Module:app) file, insert the code below into defaultConfig :
defaultConfig {
applicationId "com.***.****"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
}
and insert into to dependencies :
implementation 'com.android.support:multidex:2.0.1'
Then add code to manifest :
<application
android:name="android.support.multidex.MultiDexApplication"
I had the same problem in my (YouTube player project)... and the following solved the problem for me:
Add this code into your build.gradle (module: app) inside defaultConfing:
defaultConfig {
....
....
multiDexEnabled = true
}
Add this code into your build.gradle (module: app) inside dependencies:
dependencies {
compile 'com.android.support:multidex:1.0.1'
.....
.....
}
Open AndroidManifest.xml and within application:
<application
android:name="android.support.multidex.MultiDexApplication"
.....
.....
</application>
or if you have your App class, extend it from MultiDexApplication like:
public class MyApp extends MultiDexApplication {
.....
And finally, I think you should have Android Support Repository downloaded, in the Extras in SDK Manager.
Just override the following method in your application class.
public class YourApplication extends Application {
#Override
protected void attachBaseContext(Context context) {
super.attachBaseContext(context);
MultiDex.install(this);
}
#Override
public void onCreate() {
super.onCreate();
Realm.init(this); //initialize other plugins
}
}
When your app and the libraries it references exceed 65,536 methods, you encounter a build error that indicates your app has reached the
limit of the Android build architecture
To avoid this limitation you have to configure your app for multidex
If your minSdkVersion is set to 21 or higher, all you need to do is
set multiDexEnabled to true in your module-level build.gradle file, as
shown here:
android {
defaultConfig {
...
minSdkVersion 21
multiDexEnabled true
}
...
}
Else, if your minSdkVersion is set to 20 or lower, then you must
use the multidex support library as follows:
1.Modify the module-level build.gradle file to enable multidex and add the multidex library as a dependency, as shown here:
android {
defaultConfig {
...
minSdkVersion 15
multiDexEnabled true
}
...
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
2.Depending on whether you override the Application class, perform one of the following:
If you do not override the Application class, edit your manifest file to set android:name in the tag as follows:
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
Else If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows:
public class MyApplication extends MultiDexApplication { ... }
Else you do override the Application class but it's not possible to change the base class, then you can instead override the
attachBaseContext() method and call MultiDex.install(this) to enable
multidex:
public class MyApplication extends SomeOtherApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Enabling multidex is not a good solution because multidexhave another usage in android see this answer what is multidex
The solution is disabling instant run as #Shylendra Madda said
Settings → Build, Execution, Deployment → Instant Run and uncheck Enable Instant Run
I think the reason of this problem is when instant run is enabled, Android Studio don't put libraries such as firebase into generated apk to decreasing project build time because firebase library and other libraries such as maps and others is exist in play services and play services is installed on android device so if instant run enabled don't need to put them in generated apk to make build time faster.
So when you extract apk and install it on another device you will see this exception
I have also face the same issue after trying all solution I found the below solution.
If you have applied proguard rules then add below line in ProGuard Rules
-keep class com.google.firebase.provider.FirebaseInitProvider
and its solve my problem.
1: Go to the gradle enable multiDexEnabled and add the multidex library in the dependencies.
android {
...
defaultConfig {
multiDexEnabled true
...
}
}
dependencies {
// add dependency
implementation 'com.android.support:multidex:1.0.1'
}
2: Go to the Manifest file and write android:name=".MyApplication" (Class name(MyApplication) is optional you can write whatever you want ).
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
.
.
.
.
.
</application>
3: As you wrote android:name=".MyApplication" Inside Application at Manifest file. it will give you an error because you didn't create MyApplication class. Create MyApplication Class extend it by "application" class or Simply click on.MyApplication, a small red balloon appear on the left side of a syntax click on it, you will see (create MyApplication class) in the menu, click on it and Include below Method Inside that class.
public class MyApplication extends Application {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
If you want to get more information then Click on this Link:[https://developer.android.com/studio/build/multidex.html]
Hopefully, It works for you.
First add the following into build.gradle(Module:app)---->
defaultConfig{
..
multiDexEnabled true
..
}
Then in same file add the following
dependencies{
...
compile 'com.android.support:multidex:1.0.1'
...
}
Then in AndroidManifest.xml write the following
<application
android:name="android.support.multidex.MultiDexApplication"
.....
.....
</application>
That's it. It will definitely work
If you are using MultiDex in your App Gradle then change extends application to extends MultiDexApplication in your application class. It will defiantly work
I had the same issue and solved just add a piece of code, If you are getting this issue means you had already completed all the steps that need to use Firebase. You just need to create a class that extends the Application (public class Application_CrashReport extends Application ) and add this class in mainifest file and In that class just override the below method
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
}
and add MultiDex.install(this); in that method means
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
Note :- Don't forget to follow above steps
This is a bit late for those coming in, but check your proguard rules! I wasted a lot of time on this. Your proguard rules could be changing the names to important firebase files. This really only proves a problem in production and instant run :)
proguard-rules.pro
-keep class com.google.firebase.** { *; }
-keep class com.firebase.** { *; }
-keep class org.apache.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }
-dontwarn org.apache.**
-dontwarn org.w3c.dom.**
As mentioned previously, this is a problem with multidex: you should add implementation to your build.gradle and MainApplication.java. But what you add really depends on whether you support AndroidX or not. Here is what you need to solve this problem:
If you support AndroidX
Put these lines of code into your build.gradle (android/app/build.gradle):
defaultConfig {
applicationId "com.your.application"
versionCode 1
versionName "1.0"
...
multiDexEnabled true // <-- THIS LINE
}
...
...
dependencies {
...
implementation "androidx.multidex:multidex:2.0.1" // <-- THIS LINE
...
}
Put these lines into your MainApplication.java (android/app/src/main/java/.../MainApplication.java):
package com.your.package;
import androidx.multidex.MultiDexApplication; // <-- THIS LINE
...
...
public class MainApplication extends MultiDexApplication { ... } // <-- THIS LINE
If you don't support AndroidX
Put these lines of code into your build.gradle (android/app/build.gradle):
defaultConfig {
applicationId "com.your.application"
versionCode 1
versionName "1.0"
...
multiDexEnabled true // <-- THIS LINE
}
...
...
dependencies {
...
implementation "com.android.support:multidex:1.0.3" // <-- THIS LINE
...
}
Put these lines into your MainApplication.java (android/app/src/main/java/.../MainApplication.java):
package com.your.package;
import android.support.multidex.MultiDex;; // <-- THIS LINE
...
...
public class MainApplication extends MultiDexApplication { ... } // <-- THIS LINE
This is due to MultiDex.
Steps to solve:
In gradle->dependencies->(compile'com.android.support:multidex:1.0.1')
Add this in dependencies
In your project application class extends MultiDexApplication like this (public class MyApplication extends MultiDexApplication)
Run and check
You should extend your Application class with MultiDexApplication instead of Application.
This issue occurred when I switched to Android Studio 3.4 with Android Gradle plugin 3.4.0. which works with the R8 compiler.
The Android Gradle plugin includes additional predefined ProGuard rules files, but it is recommended that you use proguard-android-optimize.txt. More info here.
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile(
'proguard-android-optimize.txt'),
// List additional ProGuard rules for the given build type here. By default,
// Android Studio creates and includes an empty rules file for you (located
// at the root directory of each module).
'proguard-rules.pro'
}
}
I was facing the same problem and i solved this issue by changing the fireabseStorage version the same as the Firebase database version
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:17.0.0'
to
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
If you have > 20 minsdkversion, you need to use the latest Firebase Auth version i.e.
implementation 'com.google.firebase:firebase-auth:18.1.0'
and no need to setup multi-dex if you don't actually need it.
I encountered this issue when I've used 16.0.5 from the Firebase helper but was able to fix it when I've updated to 18.1.0.
If you're using Xamarin.Forms you might want to check out Didn't find class "com.google.firebase.provider.FirebaseInitProvider"? as this captures the issue with the dex error with google firebase on startup (unresolved at this time).
I've reverted to using no shrinking in the short-term and plan to use ProGuard until R8 is more stable.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// add the above code in your app level gradle file just after
defaultConfig{
}
add in project root path google-services.json
dependencies {
compile 'com.android.support:support-v4:25.0.1'
**compile 'com.google.firebase:firebase-ads:9.0.2'**
compile files('libs/StartAppInApp-3.5.0.jar')
compile 'com.android.support:multidex:1.0.1'
}
apply plugin: 'com.google.gms.google-services'
I have enable Multidex support in my project and it was working fine on Android 5.0 and above, But when I started testing my app with Android 4.3 and below it start giving me NoClassDefFoundError for TwitterConfig.
I can't disable my Multidex support. I am not getting why I am getting this issue. Tried to find out solution on net but didn't help.
Here is Exception which I am getting.
java.lang.NoClassDefFoundError: com.twitter.sdk.android.core.TwitterAuthConfig$1
at com.twitter.sdk.android.core.TwitterAuthConfig.<clinit>(TwitterAuthConfig.java:39)
at MyApplication.onCreate(MyApplication.java:46)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4702)
at android.app.ActivityThread.access$1400(ActivityThread.java:168)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1389)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)
Here is my app.gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
android {
packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "2g"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:design:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.1'
compile 'com.android.support:cardview-v7:22.2.1'
compile 'com.android.support:support-v4:22.2.1'
compile project(':MPChartLib')
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
compile('com.crashlytics.sdk.android:crashlytics:2.5.2#aar') {
transitive = true;
}
compile('com.twitter.sdk.android:twitter:1.8.0#aar') {
transitive = true;
}
}
Here is my Twitter Code in MyApplication class.
#Override
public void onCreate() {
super.onCreate();
//Configure twitter using Twitter key and Secret Key
TwitterAuthConfig authConfig =
new TwitterAuthConfig(TWITTER_KEY,
TWITTER_SECRET);
// add functionalities which we are using with Fabric
Fabric.with(this, new Crashlytics(), new Twitter(authConfig));
FacebookSdk.sdkInitialize(getApplicationContext());
// Initialize the SDK before executing any other operations,
// especially, if you're using Facebook UI elements.
}
Even i tried this solution too but didn't help.
Any hint or reference appreciated.
Multidex support for Android 5.0 and higher
Android 5.0 and higher uses a runtime called ART which natively
supports loading multiple dex files from application APK files. ART
performs pre-compilation at application install time which scans for
classes(..N).dex files and compiles them into a single .oat file for
execution by the Android device. For more information on the Android
5.0 runtime, see Introducing ART.
That means your app would working fine on API level 21 or above.
Multidex support prior to Android 5.0
Versions of the platform prior to Android 5.0 use the Dalvik runtime
for executing app code. By default, Dalvik limits apps to a single
classes.dex bytecode file per APK. In order to get around this
limitation, you can use the multidex support library, which becomes
part of the primary DEX file of your app and then manages access to
the additional DEX files and the code they contain.
So, Firstly making sure you have imported correct dependency, which It seems you did it.
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
In your manifest add the MultiDexApplication class from the multidex support library to the application element.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
Alternative to that, If your app extends the Application class, you can override the attachBaseContext() method and call MultiDex.install(this) to enable multidex.
public void onCreate(Bundle arguments) {
MultiDex.install(getTargetContext());
super.onCreate(arguments);
...
}
Finally, you will need to update your build.gradle file as below by adding multiDexEnabled true :
defaultConfig {
applicationId '{Project Name}'
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
I hope it will help you out.
I've solved the problem by setting fabric gradle plugin version manually to lower version '1.21.6'. Probably there was some issue with the latest one, which in my case was '1.23.0'. (Fabric plugin version history)
So I set
dependencies {
classpath 'io.fabric.tools:gradle:1.21.6'
}
instead of
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
I'm in the process of converting an existing app from Eclipse to Android Studio. However, when I run it on a device running 4.x (I've tested several versions on emulators), it immediately crashes with a NoClassDefFoundError.
I've tried commenting out references to the classes it can't find, but there's always another. As far as can tell, the offending class is always
Within my own code
An inner class (Update: With more investigation, this one isn't always true)
Everything works fine on a 5.0.1 emulator (I don't have a device to test on). My build.gradle file is fairly long, but looks like this:
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = "2.7.1"
android {
compileSdkVersion 19
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.myapp.android"
minSdkVersion 8
targetSdkVersion 19
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
*snip*
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
repositories {
maven {
url "https://repo.commonsware.com.s3.amazonaws.com"
}
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName 'com.pact.android'
}
}
dependencies {
*snip compile project(':...') declarations
apt "com.googlecode.androidannotations:androidannotations:$AAVersion"
compile "com.googlecode.androidannotations:androidannotations-api:$AAVersion"
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.google.android.gms:play-services:3.1.36'
*snip many more compile declarations*
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Some examples of classes that cause trouble:
An anonymous class that implements an interface inside the facebook library (as a library project)
Parcelable.CREATOR implementations in my models
An inner class that extends android.os.Library
An inner class in my own code
A class that implements an interface in a library from maven
What's going wrong, and how do I fix it?
I was incompletely implementing MultiDex support, so some of my classes weren't in the proper dex file. To fix it, you have to do more than just set multiDexEnabled = true in your defaultConfig block. You also have to:
Include compile 'com.android.support:multidex:1.0.1' in your dependencies
Have your Application class extend MultiDexApplication instead of just Application. Alternatively, you can call MultiDex.install() in attachBaseContext() of your application.
See https://developer.android.com/tools/building/multidex.html for more details.
1) Add multiDexEnabled = true in your default Config
2) Add compile com.android.support:multidex:1.0.0 in your dependencies
3) Application class extend MultiDexApplication instead of just Application
1) add multiDexEnabled = true in your defaultConfig in build.gradle.
2) You also have to Include compile 'com.android.support:multidex:1.0.1'
3) add the following to your "application" tag in your manifest:
android:name="android.support.multidex.MultiDexApplication"
its working with me , hope that help
I solved the problem by removing multiDexEnabled = true in my case.
I also issue get resolved after doing following steps
1) add multiDexEnabled = true in your defaultConfig in build.gradle.
2) You also have to Include compile com.android.support:multidex:1.0.1
3) add the following to your "application" tag in your manifest:
android:name="android.support.multidex.MultiDexApplication"
I got the same issue, tried all solutions suggested on StackOverflow but they did not work in my case.
After that I found out that one of libraries compiled by Java 8. So, I need to enable Java 8 in my project too.
android {
//...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
There are many reasons which leads to this error. Hope it helps.
In my case, it was Kotlin forEach was causing the exception.
More info here: java.lang.NoClassDefFoundError $$inlined$forEach$lambda$1 in Kotlin