Didn't find class "com.google.firebase.provider.FirebaseInitProvider"? - android

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'

Related

Didn't find class "com.google.firebase.provider.FirebaseInitProvider [duplicate]

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'

MultiDexApplication not found at app launch [duplicate]

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"

Getting Exception java.lang.NoClassDefFoundError: com.google.firebase.FirebaseOptions after updating to the new firebase

I have updated my application to the new firebase using the this and now when i compile my project i get the following exception.
Here is my logcat:
11:57:54.533 27844-27844/com.example.dayshift_2.traveyy E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dayshift_2.traveyy, PID: 27844
java.lang.NoClassDefFoundError: com.google.firebase.FirebaseOptions
at com.google.firebase.FirebaseApp.zzbu(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1591)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1562)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:4871)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4466)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4406)
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:5102)
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)
My Build.gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.dayshift_2.traveyy"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.facebook.android:facebook-android-sdk:4.+'
compile 'com.google.android.gms:play-services:9.0.0'
compile 'com.google.firebase:firebase-database:9.0.0'
compile 'com.google.firebase:firebase-auth:9.0.0'
compile 'com.android.support:support-v13:23.3.0'
compile 'com.roughike:bottom-bar:1.2.1'
}
apply plugin: 'com.google.gms.google-services'
Not sure where i am getting this exception from. any help will be highly appreciated.
Thank you
This worked for me:
If you haven't already, update your 'Google Play Services' to Revision 30 from Android SDK Manager > Extras.
And then add the line compile 'com.android.support:multidex:1.0.1' to your dependancies (or simply remove multiDexEnabled true if not required)
Add this attribute to the application tag in manifest: android:name="android.support.multidex.MultiDexApplication"
If you already have a custom application class defined in Android Manifest, extend it from MultiDexApplication instead of Application
Hope it helped!
Using latest Google Play services but was not working. For me this procedure is working:
Updated my Application class:
public class App extends Application {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Updated build.gradle file:
defaultConfig {
...
multiDexEnabled true
}
Included dependencies:
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
It is so simple to fix guys.If you are using player-services and firebase both in your project make sure that you don't import all the available services in the google.Just import the APIs what you actually need.
For example:
compile 'com.google.firebase:firebase-messaging:9.2.0'
compile 'com.google.android.gms:play-services:9.2.0'
Doing this way it can give you noclassdeffounderror .To fix this
remove play-services and sync your project. If you have dependency like using ads or maps in your app then define the specific API. like:
compile 'com.google.android.gms:play-services-maps:9.2.0'
Note: Maximum don't try to use multiDexEnabled true. This should be your last step to fix something.
Hope this is helpful.
I downgraded my google play-service dependency from
compile 'com.google.android.gms:play-services:9.2.0'
to
compile 'com.google.android.gms:play-services:8.4.0'
which solved this issue for me.
Please refer to the following Stack Overflow link for further description.
Please Note: On upgrading to the latest google play-service compile 'com.google.android.gms:play-services:9.4.0' it solved this issue as well.
Or you could selectively import certain services that you require, instead of importing all google play services.
Step1: Fix multidex
Application class:
public class StudyNApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
MultiDex.install(this);
}
}
Grade file
defaultConfig {
...
multiDexEnabled true
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Step2: Fix java.lang.NoClassDefFoundError: com.google.firebase.FirebaseOptions
Remove
compile 'com.google.android.gms:play-services:9.4.0'
Add two lib:
compile 'com.google.android.gms:play-services-maps:9.4.0'
compile 'com.google.android.gms:play-services-location:9.4.0'
It worked fine.
Don't forget it.
android:name="android.support.multidex.MultiDexApplication"
I solved by adding this and lowering the play-service dependancy to 8.4.0
compile 'com.google.android.gms:play-services:8.4.0'
#Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(newBase);
MultiDex.install(this);
}
and add the following to the manifest
android:name="android.support.multidex.MultiDexApplication"
I was facing the same error when I incremented the targetSDKVersion from 22 to 23 I spent minimum a whole day to resolve the issue. Now finally i find the result that use different play service api in your build.gradle file
Source:
https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project
I added only relevant Api's and my app is working fine.
Configure your app for multidex to resolve this issue.
For minSdkVersion 21 or above set multiDexEnabled to true in your module-level build.gradle file, as shown below:
android {
defaultConfig {
//...
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
}
//...
}
For minSdkVersion API 20 or lower
Modify the module-level build.gradle and add the multidex library as a dependency, as shown below:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
//...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
If you do not override the Application class, edit your manifest file to set android:name in the application 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>
2.1.1. If you do override the Application class Extend MultiDexApplication
public class MyApplication extends MultiDexApplication { //... }
2.1.2. 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);
}
}
for more mdex-gradle
Hope this will be help others who are facing same issue.
I think I've found a solution for this issue at this answer, please give it a look and thank #Gabriele Mariotti, he wrote:
In your top-level build.gradle you have to add:
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.0.0'
}
}
Then in your module build.gradle:
apply plugin: 'com.android.application'
android {
// ...
}
dependencies {
// ...
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(**R.string.default_web_client_id**))
.requestEmail()
.build();
In my same case i changed requestIdToken and it worked.
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'.
try to solve...
in Gradle file
multiDexEnabled true
compile 'com.android.support:multidex:1.0.1'
Manifest file
application tag add this line
android:name="android.support.multidex.MultiDexApplication"
Before doing all those hectic solutions, try to Clean Project or Rebuild Project from Android Studio.
java.lang. NoClassDefFoundError
Exceptions is thrown when you change any Class name in your project but it couldn't get the changes you made in Runtime.
Downgrade your dependency in build.gradle file:
from:
compile 'com.google.android.gms:play-services:9.4.0'
to:
compile 'com.google.android.gms:play-services:7.3.0'
This worked in my case, hope same for you.

NoClassDefFoundError with Android Studio on Android 4

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

DexIndexOverflowException issue after updating to latest appcompat and support library

I'm using the below settings through gradle:
compileSdkVersion 21
ANDROID_BUILD_MIN_SDK_VERSION=14
ANDROID_BUILD_TARGET_SDK_VERSION=21
ANDROID_BUILD_TOOLS_VERSION=21.0.2
ANDROID_BUILD_SDK_VERSION=21
I also have the following settings in my gradle file:
compile 'com.android.support:support-annotations:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:support-v4:21.0.0'
I always get the error UNEXPECTED TOP LEVEL EXCEPTION.
But when I make the 21.0.0 to 20.0.0 it works fine...but i'm not able to access any of the Android API 21 options. Is there something i'm doing wrong here? How do I get it to compile without this exception? I do not have the support jars anywhere else outside of other grade projects (facebook etc.).
Here is the full stack trace:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:283)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
at com.android.dx.command.dexer.Main.run(Main.java:245)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
This message sounds like your project is too large.
You have too many methods. There can only be 65536 methods for dex.
Since the gradle plugin 0.14.0 and the Build Tools 21.1.0 you can use the multidex support.
Just add these lines in the build.gradle:
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
Also 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>
If you are using a own Application class, change the parent class from Application to MultiDexApplication.
1) add dependency to application build.gradle file
compile 'com.android.support:multidex:1.0.2'
2) 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);
}
}
3) Add multidex support to defaultConfig at build.gradle
defaultConfig {
...
minSdkVersion 16
targetSdkVersion 26
...
// Enabling multidex support.
multiDexEnabled true
}
...
Before messing around with MultiDex
It either solution is too big (use MultiDex) or you compile and include in your project some not needed stuff. I got this issue on my tiny project. Here is what I did to fix it:
I removed this from build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
And I manually removed my build folder from application root. Problem fixed.
Follow this guide to workaround 65K limit.
I solved this issue in gradle by setting multiDexEnabled true and extending my application with class MyApp extends MultiDexApplication
I simply commented out the compile filetree(include: ['*.jar'], dir: 'libs')
in the build.gradle file (as suggested above) and rebuilt the project. Compiled without any errors. I did not need to move any folders.
First make sure that minification is enabled in app/build.cradle:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug {
signingConfig signingConfigs.config
}
}
If this does not solve the issue, enable multidex build for your app.
I faced this issue when i had compiled the entire package of Google Play Services APIs into my app. I solved the issue by using selective API.
For example, to include only the Google Fit and Android Wear APIs, replace the following line in your build.gradle file:
compile 'com.google.android.gms:play-services:11.0.2'
with these lines:
compile 'com.google.android.gms:play-services-fitness:11.0.2'
compile 'com.google.android.gms:play-services-wearable:11.0.2'
Issue is explained in following link.

Categories

Resources