Unity Android with AppCompat Rejecting re-init on previously-failed class java.lang.Class

Hi I am building a Unity app which uses Android library as one of the plugin. This Android library uses AppCompat.

Reading from the Unity blog, I realized that Unity does not include the appcompat library during the building due to several reasons (mainly the APK size) but it still allow the library to be added manually. (blog here: Unity Blog)

Thus I’ve added the library inside Assets/Plugins/Android/ which then my Unity app is able to build successfully and generate the APK file.

The problem comes when I tried to open the app which supposedly start an activity that was defined in the android library. This particular activity uses appcompat library. I get the following error message from logcat

I/art     (19482): Rejecting re-init on previously-failed class java.lang.Class<android.support.v7.app.AppCompatActivity>
I/art     (19482): Rejecting re-init on previously-failed class java.lang.Class<android.support.v7.app.AppCompatActivity>
W/ActivityManager(  890):   Force finishing activity amillardo.test.blasterescopic/com.test.player.MainActivity
I/art     (19482): Rejecting re-init on previously-failed class java.lang.Class<android.support.v7.app.ActionBarActivity>
I/art     (19482): Rejecting re-init on previously-failed class java.lang.Class<android.support.v7.app.ActionBarActivity>
I/art     (19482): Rejecting re-init on previously-failed class java.lang.Class<com.test.player.MainActivity>
E/AndroidRuntime(19482): FATAL EXCEPTION: main
E/AndroidRuntime(19482): Process: amillardo.test.blasterescopic, PID: 19482
E/AndroidRuntime(19482): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{amillardo.test.blasterescopic/com.test.player.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.test.player.MainActivity" on path: DexPathList[[zip file "/data/app/amillardo.test.blasterescopic-1/base.apk"],nativeLibraryDirectories=[/data/app/amillardo.test.blasterescopic-1/lib/arm, /system/lib, /vendor/lib, system/vendor/lib, system/vendor/lib/egl, system/lib/hw]]
E/AndroidRuntime(19482):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2322)
E/AndroidRuntime(19482):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2474)
E/AndroidRuntime(19482):     at android.app.ActivityThread.access$800(ActivityThread.java:144)
E/AndroidRuntime(19482):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1359)
E/AndroidRuntime(19482):     at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(19482):     at android.os.Looper.loop(Looper.java:155)
E/AndroidRuntime(19482):     at android.app.ActivityThread.main(ActivityThread.java:5696)
E/AndroidRuntime(19482):     at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(19482):     at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(19482):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
E/AndroidRuntime(19482):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
E/AndroidRuntime(19482): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.test.player.MainActivity" on path: DexPathList[[zip file "/data/app/amillardo.test.blasterescopic-1/base.apk"],nativeLibraryDirectories=[/data/app/amillardo.test.blasterescopic-1/lib/arm, /system/lib, /vendor/lib, system/vendor/lib, system/vendor/lib/egl, system/lib/hw]]
E/AndroidRuntime(19482):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime(19482):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime(19482):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime(19482):     at android.app.Instrumentation.newActivity(Instrumentation.java:1083)
E/AndroidRuntime(19482):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2312)
E/AndroidRuntime(19482):     ... 10 more
E/AndroidRuntime(19482):     Suppressed: java.lang.NoClassDefFoundError: com.test.player.MainActivity
E/AndroidRuntime(19482):         at dalvik.system.DexFile.defineClassNative(Native Method)
E/AndroidRuntime(19482):         at dalvik.system.DexFile.defineClass(DexFile.java:226)
E/AndroidRuntime(19482):         at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
E/AndroidRuntime(19482):         at dalvik.system.DexPathList.findClass(DexPathList.java:321)
E/AndroidRuntime(19482):         at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
E/AndroidRuntime(19482):         ... 14 more
E/AndroidRuntime(19482):     Suppressed: java.lang.ClassNotFoundException: com.test.player.MainActivity
E/AndroidRuntime(19482):         at java.lang.Class.classForName(Native Method)
E/AndroidRuntime(19482):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime(19482):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime(19482):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime(19482):         ... 13 more
E/AndroidRuntime(19482):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
I/TrimMemoryManager( 1561): [trimMemory] 20
E/ActivityManager(  890): App crashed! Process: amillardo.test.blasterescopic

So yup I am stuck here. Anyone has any suggestion? Thanks!

1 Like

I finally got it working after trying all methods I can think of!

I suspect it is because the appcompat library actually requires or dependent on support-v4 library.

Initially I only imported the appcompat library from android sdk to my unity project. But when I imported the support-v4 library, the errors are no longer there!

So hope this helps anyone who need it.

1 Like

Hi I am just copying the appcompat folder to Android Unity folder but still facing same issue I thing I am doing something wrong like importing in wrong way as I didn’t find any jar or war

I am working on mac and some how I am able to find the jar file but still getting same error. Any path to find the desired jar files of support-v4 and appcompat-v7

Any details on this one? I am actually facing the same problem.

I use Android Studio 1.4.1 to export jar files for Unity, an empty jar which only has the bridge classes works fine, but whenever I add a 3rd party jar files, I’m starting to get similar errors reported above.

I added the android sdk of ACRCloud (https://www.acrcloud.com/) and added its dependencies on my gradle file. still the error occurs, any idea?

Ok, I got it working. dependencies of the android libraries are not included to the exported jar (which is fine to avoid duplicate files in jars that would cause error during dex conversion) all you need to do is include the jar dependencies of your custom jar to your Unity3D project.

Hi @ … Unfortunately, I am also facing the same issue here.
Whenever i extend my class from “AppCompatActivity”, I am getting the same ClassNotFoundException, but when I remove it, the error goes off.
I am not sure what I am doing wrong here.

Here’s my project structure in unity3D. I hope this helps you to figure out what I am doing wrong here.

sggninlib-release is the .aar that I have exported from Android studio. Please let me know If you need any other information.

@liortal Need your help in this problem.

contact me in private or via this link.

Just for future references :

Copy the Appcompat-v7 and Support -v4 folders to your Unity Asset/Plugin/Android folder right next to your classes.jar file .
Since Appcompat and Support folders also contain a Classes.jar file go ahead and rename those two.Build and Run now .
This will fix the missing libraries issue which are also called when you aded extend AppCompatActivity

Cheers!

where can I get Appcompat-v7 and Support -v4 folders ?

they are usually auto resolved by the play services resolver

Yourandroidprojectfolder\app\build\intermediates\exploded-aar\com.android.support

I am facing the same issue even after keeping the AppCompat folder inside Assets folder. Any idea how to solve?

Which files to rename? What to rename them to?

I, am mad. It is all uncompleted.