1

I have an Android App that uses lot of JAR's and have hit the limit of 65K methods. To resolve the issue, I used Android Maven Plugin 4.0.0-rc.1 that supports multi-dex option. I was able to generate the APK file which multiple dex files; classes.dex and classes2.dex.

However, when I install and run this App on the tablet, I get the following exception.

com.mmh.application.MiApplication: java.lang.UnsupportedOperationException: Class loader not supported
09-24 20:29:52.672: E/AndroidRuntime(3810):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4733)
09-24 20:29:52.672: E/AndroidRuntime(3810):     at android.app.ActivityThread.access$1600(ActivityThread.java:175)
09-24 20:29:52.672: E/AndroidRuntime(3810):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368)
09-24 20:29:52.672: E/AndroidRuntime(3810):     at android.os.Handler.dispatchMessage(Handler.java:102)
09-24 20:29:52.672: E/AndroidRuntime(3810):     at android.os.Looper.loop(Looper.java:146)
09-24 20:29:52.672: E/AndroidRuntime(3810):     at android.app.ActivityThread.main(ActivityThread.java:5602)
09-24 20:29:52.672: E/AndroidRuntime(3810):     at java.lang.reflect.Method.invokeNative(Native Method)
09-24 20:29:52.672: E/AndroidRuntime(3810):     at java.lang.reflect.Method.invoke(Method.java:515)
09-24 20:29:52.672: E/AndroidRuntime(3810):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
09-24 20:29:52.672: E/AndroidRuntime(3810):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
09-24 20:29:52.672: E/AndroidRuntime(3810):     at dalvik.system.NativeStart.main(Native Method)
09-24 20:29:52.672: E/AndroidRuntime(3810): Caused by: java.lang.UnsupportedOperationException: Class loader not supported
09-24 20:29:52.672: E/AndroidRuntime(3810):     at com.mmh.application.Dexter.loadAllDexes(Dexter.java:69)
09-24 20:29:52.672: E/AndroidRuntime(3810):     at com.mmh.application.MiApplication.onCreate(MiApplication.java:292)
09-24 20:29:52.672: E/AndroidRuntime(3810):     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
09-24 20:29:52.672: E/AndroidRuntime(3810):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4730)
09-24 20:29:52.672: E/AndroidRuntime(3810):     ... 10 more

I am using the same Dexter class that is given in the PR https://github.com/jayway/maven-android-plugin/pull/425.

Snippet of MiApplication is given below -

public class MiApplication extends Application {
    public void onCreate() {
        Dexter.loadAllDexes(this);
        super.onCreate();
}

I printed the classloader it was using for loading Dexter class and it appears it's using PathClassLoader.

09-24 20:29:52.672: I/c*.m*.a*.Dexter(3810): Dexter Classloader dalvik.system.PathClassLoader: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.miairline-3.apk"],nativeLibraryDirectories=[/data/app-lib/com.miairline-3, /vendor/lib, /system/lib]]]

Dexter class throws 'Unsupported classloader' exception if it's loaded from any other than DexClassLoader.

How do I ensure that Dexter class is loaded from DexClassLoader? and how do I resolve this 'unsupported classloader' issue?

mmh
  • 63
  • 2
  • 8

2 Answers2

0

Which Android version is on this tablet? It would be strange if this is ICS because I've tested it on ICS and it works. I also wrote code which works on Gingerbread and as far as I know PathClassLoader and DexClassLoader have same source code on GB and Honeycomb. Changes were made in ICS and Dexter is for ICS. Dexter needs BaseDexClassLoader which is base class for PathClassLoader and DexClassLoader on ICS. In pre ICS these classes inherit directly from ClassLoader.

Check this project: https://github.com/casidiablo/multidex/ it looks better than code which I wrote, I don't know if this works without modification witch secondary dexes created by AMP but should help you.

LukaszS
  • 586
  • 1
  • 4
  • 6
  • The tablet is Samsung Galaxy Tab4 and has Jelly Bean (4.4.2). I tried changing Dexter code to use PathClassLoader, but then it throws exception that "pathList field not found". If you see, Dexter checks whether the classloader is an instance of DexClassLoader and not BaseDexClassLoader so I am not sure how it works for PathClassLoader. – mmh Sep 27 '14 at 05:25
  • If you don't mind, could you please share the relevant part of the code and your maindexList file. – mmh Sep 27 '14 at 05:28
0

I found an answer to this problem. It was my mistake.

Instead of

localClassLoader instanceof BaseDexClassLoader

I had used

localClassLoader instanceof DexClassLoader

When I changed all references from DexClassLoader to BaseDexClassLoader, the issue went away and I was able to create and load multiple dex files in my App.

mmh
  • 63
  • 2
  • 8