2

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: http://blogs.unity3d.com/2015/07/16/android-themes-in-unity/)

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!

CodingBird
  • 705
  • 2
  • 11
  • 22
  • Is it included in your MainActivity defined as an activity in the plugin manifest? – Puneet Aug 28 '15 at 03:36
  • @Puneet what I meant with defined is, it is an activity in the android library I've created. and yup I've declared it in the manifest file. by the way, I've solved it alrd. :) Thanks anyway. – CodingBird Aug 28 '15 at 05:50

1 Answers1

1

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.

CodingBird
  • 705
  • 2
  • 11
  • 22
  • Hello CodingBird. Can you please tell me how did you include the support libraries? I include boths jars (v4 and v7) in the libs folder under Assets\Plugins\Android butit doesn't work. The app crashes with no significant message. – Souhaib Guitouni Dec 28 '15 at 11:15
  • Hi @SouhaibGuitouni i just simply drag and drop the jars into the Assets/Plugin/Android/ folder – CodingBird Dec 29 '15 at 06:08
  • HI @CodingBird, I am also facing the same issue. I have rechecked it again but I am still getting the same error. Please let me know if you can help me in this. – Siddharth-Verma Jun 24 '17 at 14:42
  • Following is the log that I am getting. https://www.dropbox.com/s/2h1nxc8wsawv5uz/androidlog?dl=0 – Siddharth-Verma Jun 24 '17 at 14:50
  • Hi @Siddharth-Verma from the log, it looks like you haven't declared the activity in the manifest? Sorry I can't help you much, can only help based on the log as I no longer active in Unity development. – CodingBird Jun 27 '17 at 02:18
  • I have added the activity in the AndroidManifest.xml but still I am facing the issue. – Siddharth-Verma Jun 27 '17 at 10:05
  • May I know how were you calling the other activity(extending the app compat activity) from unity? Let me try one thing, I'll call my XYZActivity(extends from AppCompatActivity) from other class via lntent and I'll check that too and will update here. – Siddharth-Verma Jun 29 '17 at 06:04