-2

My app is crashing due to multidex. Below is the crash log information :

12-23 16:43:12.437 6823-6823/com.rogers.tsc I/MultiDex: VM with version 2.1.0 has multidex support 12-23 16:43:12.438 6823-6823/com.rogers.tsc I/MultiDex: install 12-23 16:43:12.438 6823-6823/com.rogers.tsc I/MultiDex: VM has multidex support, MultiDex support library is disabled. 12-23 16:43:12.462 6823-6823/com.rogers.tsc D/AndroidRuntime: Shutting down VM 12-23 16:43:12.463 6823-6823/com.rogers.tsc E/AndroidRuntime: FATAL EXCEPTION: main Process: com.rogers.tsc, PID: 6823 java.lang.RuntimeException: Unable to get provider com.google.android.gms.measurement.AppMeasurementContentProvider: java.lang.NullPointerException: null reference at android.app.ActivityThread.installProvider(ActivityThread.java:5156) at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688) at android.app.ActivityThread.-wrap1(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.NullPointerException: null reference at com.google.android.gms.common.internal.zzx.zzz(Unknown Source) at com.google.android.gms.measurement.internal.zzw.zzaT(Unknown Source) at com.google.android.gms.measurement.AppMeasurementContentProvider.onCreate(Unknown Source) at android.content.ContentProvider.attachInfo(ContentProvider.java:1748) at android.content.ContentProvider.attachInfo(ContentProvider.java:1723) at android.app.ActivityThread.installProvider(ActivityThread.java:5153) at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748)  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688)  at android.app.ActivityThread.-wrap1(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5417)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

It seems there is some problem with the multidex which is causing the issue. I have already added the multidex support to my application. I also have added compile 'com.android.support:multidex:1.0.0' to my app gradle.

Here is my application class

 public class MyApplication extends Application {

private static TscApplication mApplication;
public static TscApplication getApplication()
{
    return mApplication;
}

public Context getApplicationContext(){

    return mApplication;
}
@Override
public void onCreate() {
    super.onCreate();
    mApplication = this;

}
@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

}

Whenever I add application class reference in AndroidManifest then only crash is occurring otherwise not if I remove it.

Below is my app.graddle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.app.ysc"
        minSdkVersion 15
        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'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.google.android.gms:play-services-gcm:8.4.0'
    compile 'com.android.support:multidex:1.0.0'
}
apply plugin: 'com.google.gms.google-services'
2
  • Just do public class MyApplication extends MultiDexApplication {
    – M D
    Dec 23, 2015 at 12:41
  • You don't need to extends any class with Application class. Just Enable multidex in app gradle. multiDexEnabled = true
    – asad.qazi
    Dec 23, 2015 at 13:51

1 Answer 1

2

basically this is caused because you exceed the limits of method.you have two options for solve this error .

1)Decrease the no of methods in your project .Basically the library you added in your projects methods also count in your project methods. so don't use whole package of that library use the module that you uses in your project:For example Google play services you added whole package add the module you want to use like map etc..

2)Second one Enable the multidex for enable multidex : Now, all you need to do is override this in your Application class

public class YouApplication extends MultiDexApplication {

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}

}

Add multidex support library in your gradal

  android {
  compileSdkVersion 22
  buildToolsVersion "23.0.0"

 defaultConfig {
     minSdkVersion 14 //lower than 14 doesn't support multidex
     targetSdkVersion 22

     // Enabling multidex support.
     multiDexEnabled true
    }
    }

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 like this

<?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="YouApplication">
...
</application>

I hope this will Help you....

1
  • you either use multidex install in on attachBaseContext method or extend MultidexApplication using both are pointless as both do the same
    – ceph3us
    Jan 17, 2017 at 1:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.