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?
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.