Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does use of multiDexEnabled (true) allow the app to build but constantly crash?

An app I am working on (base code not written by me, containing a number of large libs which can't be removed). On a recent run it started responding with the message:

This only occurs when the app tries to build when using the run arrow, it successfully builds when calling "rebuild" or "clean".

A solution included on line is to use the multiDexEnabled true (multiDex documentation here.)

Using this I was able to get the building with both "run" arrow and "rebuild". However the app built and run on phone crashes withthe following error message:

12-11 16:17:16.963 28868-28868/? D/dalvikvm: Late-enabling CheckJNI
12-11 16:17:17.023 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 10471 (common_google_play_services_updating_text) in Lcom/google/android/gms/R$string;
12-11 16:17:17.023 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0021
12-11 16:17:17.023 28868-28868/com.myname.myappcoop I/dalvikvm: DexOpt: unable to optimize static field ref 0x28e8 at 0x2e in Lcom/google/android/gms/common/GoogleApiAvailability;.zza
12-11 16:17:17.033 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 10465 (common_google_play_services_unknown_issue) in Lcom/google/android/gms/R$string;
12-11 16:17:17.033 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0012
12-11 16:17:17.033 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 10462 (common_google_play_services_notification_ticker) in Lcom/google/android/gms/R$string;
12-11 16:17:17.033 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0013
12-11 16:17:17.033 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 10437 (common_ic_googleplayservices) in Lcom/google/android/gms/R$drawable;
12-11 16:17:17.033 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0039
12-11 16:17:17.033 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 10462 (common_google_play_services_notification_ticker) in Lcom/google/android/gms/R$string;
12-11 16:17:17.033 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0099
12-11 16:17:17.043 28868-28868/com.myname.myappcoop I/dalvikvm: Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzj
12-11 16:17:17.043 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve virtual method 616: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
12-11 16:17:17.043 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x6e at 0x000b
12-11 16:17:17.043 28868-28868/com.myname.myappcoop I/dalvikvm: DexOpt: unable to optimize static field ref 0x28c4 at 0x6c in Lcom/google/android/gms/common/GooglePlayServicesUtil;.zza
12-11 16:17:17.043 28868-28868/com.myname.myappcoop I/dalvikvm: DexOpt: unable to optimize static field ref 0x28e9 at 0x6e in Lcom/google/android/gms/common/GooglePlayServicesUtil;.zza
12-11 16:17:17.083 28868-28907/com.myname.myappcoop I/GMPM: App measurement is starting up
12-11 16:17:17.083 28868-28907/com.myname.myappcoop E/GMPM: getGoogleAppId failed with status: 10
12-11 16:17:17.083 28868-28907/com.myname.myappcoop E/GMPM: Uploading is not possible. App measurement disabled
12-11 16:17:17.113 28868-28868/com.myname.myappcoop D/dalvikvm: GC_FOR_ALLOC freed 358K, 3% free 16887K/17276K, paused 11ms, total 12ms
12-11 16:17:17.133 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 8714 (static_string) in Lcom/myname/display/R$string;
12-11 16:17:17.133 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x000b
12-11 16:17:17.133 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 8710 (static_string2) in Lcom/myname/display/R$string;
12-11 16:17:17.133 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x000e
12-11 16:17:17.133 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 8711 (static_string3) in Lcom/myname/display/R$string;
12-11 16:17:17.133 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0011
12-11 16:17:17.133 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 8716 (static_string4) in Lcom/myname/display/R$string;
12-11 16:17:17.133 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0014
12-11 16:17:17.133 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 8717 (static_string5) in Lcom/myname/display/R$string;
12-11 16:17:17.133 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0017
12-11 16:17:17.133 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 8721 (static_string6) in Lcom/myname/display/R$string;
12-11 16:17:17.133 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x001a
12-11 16:17:17.133 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 8720 (static_string7) in Lcom/myname/display/R$string;
12-11 16:17:17.133 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x001d
12-11 16:17:17.133 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 8719 (static_string8) in Lcom/myname/display/R$string;
12-11 16:17:17.133 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x60 at 0x0020
12-11 16:17:17.143 28868-28868/com.myname.myappcoop D/MAIN: Context 1 : com.myname.myapp.Application@4268dfe8
12-11 16:17:17.163 28868-28868/com.myname.myappcoop E/dalvikvm: Could not find class 'com.myname.myapp.view.FalseActionBar$1', referenced from method com.myname.myapp.view.FalseActionBar.initializeView
12-11 16:17:17.163 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve new-instance 3015 (Lcom/myname/myapp/view/FalseActionBar$1;) in Lcom/myname/myapp/view/FalseActionBar;
12-11 16:17:17.163 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x22 at 0x002a
12-11 16:17:17.163 28868-28868/com.myname.myappcoop W/dalvikvm: VFY: unable to resolve static field 10366 ($SwitchMap$com$myname$myapp$view$FalseActionBar$TitleMode) in Lcom/myname/myapp/view/FalseActionBar$3;
12-11 16:17:17.163 28868-28868/com.myname.myappcoop D/dalvikvm: VFY: replacing opcode 0x62 at 0x0005
12-11 16:17:17.163 28868-28868/com.myname.myappcoop D/dalvikvm: DexOpt: unable to opt direct call 0x5db9 at 0x2c in Lcom/myname/myapp/view/FalseActionBar;.initializeView
12-11 16:17:17.163 28868-28868/com.myname.myappcoop D/dalvikvm: DexOpt: unable to opt direct call 0x5dba at 0x46 in Lcom/myname/myapp/view/FalseActionBar;.initializeView
12-11 16:17:17.163 28868-28868/com.myname.myappcoop D/AndroidRuntime: Shutting down VM
12-11 16:17:17.163 28868-28868/com.myname.myappcoop W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x4162fba8)
12-11 16:17:17.163 28868-28868/com.myname.myappcoop E/AndroidRuntime: FATAL EXCEPTION: main
                           Process: com.myname.myappcoop, PID: 28868
                           java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myname.myappcoop/com.myname.myapp.MainActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class com.myname.myapp.view.FalseActionBar
                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
                               at android.app.ActivityThread.access$800(ActivityThread.java:135)
                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
                               at android.os.Handler.dispatchMessage(Handler.java:102)
                               at android.os.Looper.loop(Looper.java:136)
                               at android.app.ActivityThread.main(ActivityThread.java:5001)
                               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: android.view.InflateException: Binary XML file line #24: Error inflating class com.myname.myapp.view.FalseActionBar
                               at android.view.LayoutInflater.createView(LayoutInflater.java:620)
                               at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
                               at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                               at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                               at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                               at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                               at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
                               at android.app.Activity.setContentView(Activity.java:1929)
                               at com.myname.myapp.MainActivity.onCreate(MainActivity.java:96)
                               at android.app.Activity.performCreate(Activity.java:5231)
                               at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
                               at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                               at android.os.Handler.dispatchMessage(Handler.java:102) 
                               at android.os.Looper.loop(Looper.java:136) 
                               at android.app.ActivityThread.main(ActivityThread.java:5001) 
                               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.reflect.InvocationTargetException
                               at java.lang.reflect.Constructor.constructNative(Native Method)
                               at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
                               at android.view.LayoutInflater.createView(LayoutInflater.java:594)
                               at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
                               at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                               at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                               at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                               at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                               at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290) 
                               at android.app.Activity.setContentView(Activity.java:1929) 
                               at com.myname.myapp.MainActivity.onCreate(MainActivity.java:96) 
                               at android.app.Activity.performCreate(Activity.java:5231) 
                               at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
                               at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                               at android.os.Handler.dispatchMessage(Handler.java:102) 
                               at android.os.Looper.loop(Looper.java:136) 
                               at android.app.ActivityThread.main(ActivityThread.java:5001) 
                               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.NoClassDefFoundError: com.myname.myapp.view.FalseActionBar$1
                               at com.myname.myapp.view.FalseActionBar.initializeView(FalseActionBar.java:61)
                               at com.myname.myapp.view.FalseActionBar.<init>(FalseActionBar.java:46)
                               at java.lang.reflect.Constructor.constructNative(Native Method) 
                               at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
                               at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
                               at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
                               at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                               at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                               at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                               at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                               at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290) 
                               at android.app.Activity.setContentView(Activity.java:1929) 
                               at com.myname.myapp.MainActivity.onCreate(MainActivity.java:96) 
                               at android.app.Activity.performCreate(Activity.java:5231) 
                               at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
                               at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                               at android.os.Handler.dispatchMessage(Handler.java:102) 
                               at android.os.Looper.loop(Looper.java:136) 
                               at android.app.ActivityThread.main(ActivityThread.java:5001) 
                               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) 
12-11 16:17:46.173 28868-28868/? I/Process: Sending signal. PID: 28868 SIG: 9

The where the code is crashing (Caused by: java.lang.NoClassDefFoundError: com.myname.myapp.view.FalseActionBar$1) is when a listener is being declared. It was originally in another class extending on click listener so I brought it into the code, but that did not help.

    title.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v) {
            switch (mode) {
                case NONE:
                    //Nothing!
                    break;

                case BACK:
                    if(delegate != null){
                        delegate.goBack(backLocation);
                    }
                    break;

                case HOME:
                    if(delegate != null){
                        delegate.goHome();
                    }
                    break;
            }
        }

I originally thought the issue was with the inflater though now I am fairly sure it must be with the use of multiDex.

What is multiDex doing that is causing the crash on inflation?

like image 623
Luke Avatar asked Dec 11 '15 03:12

Luke


People also ask

What is multiDexEnabled true in Android?

Android applications by default have SingleDex support which limits your application to have only 65536 methods(references). So multidexEnabled = true simply means that now you can write more than 65536 methods(references) in your application.

What is the use of multidex in Android?

Multidex support for Android 5.dex files and compiles them into a single . oat file for execution by the Android device. Therefore, if your minSdkVersion is 21 or higher multidex is enabled by default, and you do not need the multidex library. For more information on the Android 5.0 runtime, read ART and Dalvik.

How do I disable multidex?

Show activity on this post. You can disable multidex only if your project doesn't exceed either 65k methods limitation or 65k fields limitation. People seems to be unaware about the 65k fields limitation. You can hit the fields limitation if you're using huge total of resources like drawable, string id, etc.


2 Answers

you need to do following things

  1. in build.gradle add

    dexOptions {
        javaMaxHeapSize "4g"
    }
    
  2. enable multidex

    defaultConfig {
        multiDexEnabled true
    }
    
  3. Create a file extends with MultiDexApplication as following

    public class App extends MultiDexApplication {
    
        @Override
        protected void attachBaseContext(Context base) {
            super.attachBaseContext(base);
            MultiDex.install(this);
        } 
    }
    

    and make this 'App' class as application class in manifest as below -

    <application
        android:name=".activity.App"
    
like image 122
Deepak Avatar answered Oct 20 '22 01:10

Deepak


Just add

android:name="android.support.multidex.MultiDexApplication"

in AndroidManifest.xml in the application XM tag as property.

This will solve all your problems.

like image 36
Shailesh Narayan Avatar answered Oct 20 '22 01:10

Shailesh Narayan