Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Getting error trying "extending UnityPlayerActivity" example

Discussion in 'Android' started by gsibley, Oct 14, 2011.

  1. gsibley

    gsibley

    Joined:
    Oct 14, 2011
    Posts:
    3
    I'm trying to get the example of extending UnityPlayerActivity to work, but the app just has to be force-quit as soon as it's started.

    The manifest is in Assets/Plugins/Android alongside OverrideExample.jar, which contains OverrideExample.class. I'm not really familiar with Android / Java development, is there something trivial I'm missing?

    Here's logcat's output:
    Code (csharp):
    1. I/ActivityManager(  111): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.company.product/.OverrideExample } from pid 2369
    2. I/ActivityManager(  111): Start proc com.company.product for activity com.company.product/.OverrideExample: pid=5745 uid=10054 gids={3003, 1015}
    3. D/AndroidRuntime( 5745): Shutting down VM
    4. W/dalvikvm( 5745): threadid=1: thread exiting with uncaught exception (group=0x40015560)
    5. E/AndroidRuntime( 5745): FATAL EXCEPTION: main
    6. E/AndroidRuntime( 5745): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.company.product/com.company.product.OverrideExample}: java.lang.ClassNotFoundException: com.company.product.OverrideExample in loader dalvik.system.PathClassLoader[/data/app/com.company.product-1.apk]
    7. E/AndroidRuntime( 5745):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
    8. E/AndroidRuntime( 5745):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
    9. E/AndroidRuntime( 5745):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    10. E/AndroidRuntime( 5745):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
    11. E/AndroidRuntime( 5745):    at android.os.Handler.dispatchMessage(Handler.java:99)
    12. E/AndroidRuntime( 5745):    at android.os.Looper.loop(Looper.java:130)
    13. E/AndroidRuntime( 5745):    at android.app.ActivityThread.main(ActivityThread.java:3683)
    14. E/AndroidRuntime( 5745):    at java.lang.reflect.Method.invokeNative(Native Method)
    15. E/AndroidRuntime( 5745):    at java.lang.reflect.Method.invoke(Method.java:507)
    16. E/AndroidRuntime( 5745):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    17. E/AndroidRuntime( 5745):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    18. E/AndroidRuntime( 5745):    at dalvik.system.NativeStart.main(Native Method)
    19. E/AndroidRuntime( 5745): Caused by: java.lang.ClassNotFoundException: com.company.product.OverrideExample in loader dalvik.system.PathClassLoader[/data/app/com.company.product-1.apk]
    20. E/AndroidRuntime( 5745):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
    21. E/AndroidRuntime( 5745):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
    22. E/AndroidRuntime( 5745):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    23. E/AndroidRuntime( 5745):    at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
    24. E/AndroidRuntime( 5745):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
    25. E/AndroidRuntime( 5745):    ... 11 more
    26. W/ActivityManager(  111):   Force finishing activity com.company.product/.OverrideExample
    27. V/RenderScript_jni( 2369): surfaceDestroyed
    28. W/ActivityManager(  111): Activity pause timeout for HistoryRecord{4051a998 com.company.product/.OverrideExample}
    29.  
    And AndroidManifest.xml:
    Code (csharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.company.product">
    3.     <application android:icon="@drawable/app_icon" android:label="@string/app_name">
    4.         <activity android:name=".OverrideExample"
    5.             android:label="@string/app_name">
    6.             <intent-filter>
    7.                 <action android:name="android.intent.action.MAIN" />
    8.                 <category android:name="android.intent.category.LAUNCHER" />
    9.             </intent-filter>
    10.         </activity>
    11.     </application>
    12. </manifest>
     
  2. juls85

    juls85

    Joined:
    Aug 11, 2011
    Posts:
    7
    Hi gsibley,
    Did you follow the guide step by step???
    Did you add the classes.jar file to the path before you created the 'OverrideExample.jar'???
    You just weren't talking about that part up there. I recently got followed that guide and got it working fine for me. :)

    Regards
    Julian
     
  3. gsibley

    gsibley

    Joined:
    Oct 14, 2011
    Posts:
    3
    Yes, I added the classes.jar.
    I'm compiling using
    Code (csharp):
    1. javac -cp /Applications/Unity/Unity.app/Contents/PlaybackEngines/AndroidPlayer/bin/classes.jar:InAppSDK-Purchasing.jar:/android-sdk-mac_x86/platforms/android-13/android.jar OverrideExample.java
    and then compressing it into a jar with
    Code (csharp):
    1. jar cf OverrideExample.jar OverrideExample.class
     
  4. juls85

    juls85

    Joined:
    Aug 11, 2011
    Posts:
    7
    OK so you copied the OverrideExample.java file from the guide as well?
    Usually you get this type of error if you didn't name something correctly somewhere either in your manifest file or you java file or in the unity player settings bundle identifier.
    Assuming they are all the same, that is really weird.
     
  5. gsibley

    gsibley

    Joined:
    Oct 14, 2011
    Posts:
    3
    OK, thanks to help from Erique on IRC I've found out the cause of this problem: When the .class files are jar'd up they must be in a directory tree that matches the package name. So for the example, you'd have to have OverrideExample.class in the com/company/product directory, and then
    Code (csharp):
    1. jar cf OverrideExample.jar com
    to package the whole directory.
     
  6. deepak

    deepak

    Joined:
    Aug 10, 2010
    Posts:
    44
    Hi All,

    We got an error message from Android Market as

    "java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.nextwave.BowlingWizards/com.unity3d.player.UnityPlayerActivity}: java.lang.ClassNotFoundException: com.unity3d.player.UnityPlayerActivity in loader dalvik.system.PathClassLoader[/mnt/asec/com.nextwave.BowlingWizards-1/pkg.apk]
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2590)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2684)
    at android.app.ActivityThread.access$2300(ActivityThread.java:126)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4632)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:861)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:619)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.ClassNotFoundException: com.unity3d.player.UnityPlayerActivity in loader dalvik.system.PathClassLoader[/mnt/asec/com.nextwave.BowlingWizards-1/pkg.apk]
    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2582)"

    Anyone had an idea about it?
     
  7. Kartack

    Kartack

    Joined:
    Nov 7, 2012
    Posts:
    11
    I was getting this same exception on game launch after trying to follow the instructions on page listed above. I followed the advice above and placed the java (and class file after compiling with javac) into directories com/company/product but the exception kept being thrown. It appears that the package name needs to match your Bundle Identifier in your Project Settings -> Player window. I'm not sure if the Bundle Identifier in the player window needs to match the package name in your custom AndroidManifest file as well (likely it does), but certainly the package value there didn't seem to control what package the Android OS was looking in at run time.
     
  8. zzd

    zzd

    Joined:
    Jul 6, 2012
    Posts:
    3
    the tips is very clear ,cannot find the class that you will to instantiate ,just check the bunldle name/path .