Troubleshoot an Android single Dex file with no more than 65,535 method issues

Source: Internet
Author: User

First, looking for the pit: Google stipulates that the method in a single Dex file cannot exceed the 65536 limit

There are too many third-party plug-in jar packages referenced in the project's Lib folder when we write the project, or if the project is too large, it is possible for the compile run to report the Com.android.dex.DexIndexOverflowException:method ID not in [0, 0XFFFF]: 65536 error. See this error stating that your method adds up to more than 65536 of this number. But google specifies that the method in a single Dex file cannot exceed the 65536 limit.

As shown, the message in Android Studio shows the error

Here is the specific error code:

 for ' : App:transformclasseswithdexfordebug ' .   inch [00xffff65536  

Encountered this pit when looking for a half-day jar package Repetition, is also a moment of confusion, lessons learned

OK, the mistake has found us to solve the problem, the pit is always to fill.

Second, pits

A netizen said in the module's Build.gradle file to add the basis of the words to solve:

  defaultconfig {         "com.xxx.xxx        "           1"1.0        "                  true     }

multidexenabled true

After running the compilation you may not find the problem, but in some cases the app jumps directly, the pit is still much better

I jumped in here, unexpectedly reported a bunch of mistakes, the following is the error message errors

Java.lang.RuntimeException:Unable to instantiate activity Componentinfo{com.xxx.xxx/com.xxx.xxx.ui.actmain.mainact }: Java.lang.ClassNotFoundException:Didn'T find class "COM.XXX.XXX.UI.ACTMAIN.MAINACT" on Path:dexpathlist[[zip file "/data/app/ com.xiaodongwa.vronline-2.apk "],nativelibrarydirectories=[/data/app-lib/com.xxx.xxx-2,/vendor/lib,/system/lib] ]At Android.app.ActivityThread.performLaunchActivity (Activitythread.java:2190) at Android.app.ActivityThread.handleLaunchActivity (Activitythread.java:2313) at android.app.activitythread.access$1100(Activitythread.java:141) at Android.app.activitythread$h.handlemessage (Activitythread.java:1238) at Android.os.Handler.dispatchMessage (Handler.java:102) at Android.os.Looper.loop (Looper.java:136) at Android.app.ActivityThread.main (Activitythread.java:5336At 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:871) at com.android.Internal. os. Zygoteinit.main (Zygoteinit.java:687) at Dalvik.system.NativeStart.main (Native Method) caused by:java.lang.ClassNotFoundException:Didn'T find class "COM.XXX.XXX.UI.ACTMAIN.MAINACT" on Path:dexpathlist[[zip file "/data/app/com.xxx.xxx-2.apk"], Nativelibrarydirectories=[/data/app-lib/com.xxx.xxx-2,/vendor/lib,/system/lib]]At Dalvik.system.BaseDexClassLoader.findClass (Basedexclassloader.java: About) at Java.lang.ClassLoader.loadClass (Classloader.java:497) at Java.lang.ClassLoader.loadClass (Classloader.java:457) at Android.app.Instrumentation.newActivity (Instrumentation.java:1064) at Android.app.ActivityThread.performLaunchActivity (Activitythread.java:2181) at Android.app.ActivityThread.handleLaunchActivity (Activitythread.java:2313) at android.app.activitythread.access$1100(Activitythread.java:141) at Android.app.activitythread$h.handlemessage (Activitythread.java:1238) at Android.os.Handler.dispatchMessage (Handler.java:102) at Android.os.Looper.loop (Looper.java:136) at Android.app.ActivityThread.main (Activitythread.java:5336) 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:871) at com.android.Internal. os. Zygoteinit.main (Zygoteinit.java:687) at Dalvik.system.NativeStart.main (Native Method)

See this piece of red instant collapsed, thought on the code is enough to add, it seems not, a piece of sea found a key part

Classnotfoundexception:didn't find class "COM.XXX.XXX.UI.ACTMAIN.MAINACT" on Path:dexpathlist[[zip file "/data/app/com.xxx.xxx-2.apk"],nativelibrarydirectories=[/data/app-lib/com.xxx.xxx-2,/vendor/lib,/system/lib]   in caused by: partial discovery: Didn ' T find class "COM.XIAODONGWA.VRONLINE.UI.ACTMAIN.MAINACT" on Path:dexpathlist[[zip file "/data/app/ com.xiaodongwa.vronline-2.apk "]

The key mistake is to not find the Mainact class in Dexpathlist, Dex reads it well, it's not the suffix of the. dex file after we pack it, which involves Android multi-packet technology Multidex

OK,继续填坑

Third, detailed multi-sub-package technology

To implement multi-packet technology, we first need to use the Android SDK build Tools 21.1 and later versions, after completion also need to add multidex dependencies in dependencies, remember to add the above mentioned sentence

1, multidexenabled True

2. Add dependencies

Dependencies {      'com.android.support:multidex:1.0.1'  }  

Scenario one, let the application's own definition of application inherit multidexapplication

 Public class MyApplication extends multidexapplication{...  }  

Remember not to forget to modify the application you defined in the Manifest.xml file for your application, or the program will crash

Plan two, rewrite the Attachbasecontext method of application, this method is executed before OnCreate

 Public class MyApplication extends application{    @Override      protectedvoidbase) {          Super.attachbasecontext (base);          Multidex.install (this);      }  }   

This will solve the problem by compiling and running the program.

If you have any errors or questions, please advise

Troubleshoot an Android single Dex file with no more than 65,535 method issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.