Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

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

Discussion in 'Android' started by amillardo, Aug 27, 2015.

  1. amillardo

    amillardo

    Joined:
    Jul 30, 2015
    Posts:
    5
    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

    Code (CSharp):
    1. I/art     (19482): Rejecting re-init on previously-failed class java.lang.Class<android.support.v7.app.AppCompatActivity>
    2. I/art     (19482): Rejecting re-init on previously-failed class java.lang.Class<android.support.v7.app.AppCompatActivity>
    3. W/ActivityManager(  890):   Force finishing activity amillardo.test.blasterescopic/com.test.player.MainActivity
    4. I/art     (19482): Rejecting re-init on previously-failed class java.lang.Class<android.support.v7.app.ActionBarActivity>
    5. I/art     (19482): Rejecting re-init on previously-failed class java.lang.Class<android.support.v7.app.ActionBarActivity>
    6. I/art     (19482): Rejecting re-init on previously-failed class java.lang.Class<com.test.player.MainActivity>
    7. E/AndroidRuntime(19482): FATAL EXCEPTION: main
    8. E/AndroidRuntime(19482): Process: amillardo.test.blasterescopic, PID: 19482
    9. 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]]
    10. E/AndroidRuntime(19482):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2322)
    11. E/AndroidRuntime(19482):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2474)
    12. E/AndroidRuntime(19482):     at android.app.ActivityThread.access$800(ActivityThread.java:144)
    13. E/AndroidRuntime(19482):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1359)
    14. E/AndroidRuntime(19482):     at android.os.Handler.dispatchMessage(Handler.java:102)
    15. E/AndroidRuntime(19482):     at android.os.Looper.loop(Looper.java:155)
    16. E/AndroidRuntime(19482):     at android.app.ActivityThread.main(ActivityThread.java:5696)
    17. E/AndroidRuntime(19482):     at java.lang.reflect.Method.invoke(Native Method)
    18. E/AndroidRuntime(19482):     at java.lang.reflect.Method.invoke(Method.java:372)
    19. E/AndroidRuntime(19482):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
    20. E/AndroidRuntime(19482):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
    21. 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]]
    22. E/AndroidRuntime(19482):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    23. E/AndroidRuntime(19482):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    24. E/AndroidRuntime(19482):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    25. E/AndroidRuntime(19482):     at android.app.Instrumentation.newActivity(Instrumentation.java:1083)
    26. E/AndroidRuntime(19482):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2312)
    27. E/AndroidRuntime(19482):     ... 10 more
    28. E/AndroidRuntime(19482):     Suppressed: java.lang.NoClassDefFoundError: com.test.player.MainActivity
    29. E/AndroidRuntime(19482):         at dalvik.system.DexFile.defineClassNative(Native Method)
    30. E/AndroidRuntime(19482):         at dalvik.system.DexFile.defineClass(DexFile.java:226)
    31. E/AndroidRuntime(19482):         at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
    32. E/AndroidRuntime(19482):         at dalvik.system.DexPathList.findClass(DexPathList.java:321)
    33. E/AndroidRuntime(19482):         at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
    34. E/AndroidRuntime(19482):         ... 14 more
    35. E/AndroidRuntime(19482):     Suppressed: java.lang.ClassNotFoundException: com.test.player.MainActivity
    36. E/AndroidRuntime(19482):         at java.lang.Class.classForName(Native Method)
    37. E/AndroidRuntime(19482):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
    38. E/AndroidRuntime(19482):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
    39. E/AndroidRuntime(19482):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
    40. E/AndroidRuntime(19482):         ... 13 more
    41. E/AndroidRuntime(19482):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
    42. I/TrimMemoryManager( 1561): [trimMemory] 20
    43. E/ActivityManager(  890): App crashed! Process: amillardo.test.blasterescopic
    44.  
    So yup I am stuck here. Anyone has any suggestion? Thanks!
     
    Last edited: Aug 28, 2015
    raraavis likes this.
  2. amillardo

    amillardo

    Joined:
    Jul 30, 2015
    Posts:
    5
    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.
     
    ayyappa likes this.
  3. Contract-killer

    Contract-killer

    Joined:
    Sep 21, 2012
    Posts:
    41
    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
     
  4. Contract-killer

    Contract-killer

    Joined:
    Sep 21, 2012
    Posts:
    41
    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
     
  5. Deleted User

    Deleted User

    Guest

    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?


    gradle.png
     
  6. Deleted User

    Deleted User

    Guest

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

    iamsidv

    Joined:
    Jan 24, 2013
    Posts:
    17
    Hi @ariessanchezsulit .. 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.

    https://www.dropbox.com/s/k8x4ufqsl81yfw1/Screenshot 2017-06-24 21.05.32.png?dl=0

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

    iamsidv

    Joined:
    Jan 24, 2013
    Posts:
    17
    @liortal Need your help in this problem.
     
  9. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,318
  10. Roshanpanahi

    Roshanpanahi

    Joined:
    Apr 10, 2018
    Posts:
    3

    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!
     
  11. brookt

    brookt

    Joined:
    Apr 19, 2016
    Posts:
    1
    where can I get Appcompat-v7 and Support -v4 folders ?
     
  12. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,318
    they are usually auto resolved by the play services resolver
     
  13. Roshanpanahi

    Roshanpanahi

    Joined:
    Apr 10, 2018
    Posts:
    3

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

    abhineetp99

    Joined:
    Jul 1, 2019
    Posts:
    2
    I am facing the same issue even after keeping the AppCompat folder inside Assets folder. Any idea how to solve?
     
  15. abhineetp99

    abhineetp99

    Joined:
    Jul 1, 2019
    Posts:
    2
    Which files to rename? What to rename them to?