Search Unity

App Fails on launch - AAR plugin

Discussion in 'Android' started by bpritchard, Jul 25, 2016.

  1. bpritchard

    bpritchard

    Joined:
    Jan 29, 2009
    Posts:
    444
    Hey all, trying to get an AAR working that i've built but i get the infamous "Unfortunately... " and my app crashes on start.

    I've basically overriden the main unity activity and am not even working on the communication part at this point. here's my MainActivity...

    Code (JavaScript):
    1.  
    2.  
    3. package com.jpr.jprunityandroid;
    4.  
    5. import android.os.Bundle;
    6. import android.util.Log;
    7.  
    8. import com.unity3d.player.UnityPlayer;
    9. import com.unity3d.player.UnityPlayerActivity;
    10. import android.content.Context;
    11.  
    12. public class MainActivity extends UnityPlayerActivity {
    13.  
    14.  
    15.     @Override
    16.     protected void onCreate(Bundle bundle) {
    17.  
    18.  
    19.         // call UnityPlayerActivity.onCreate()
    20.         super.onCreate(bundle);
    21.  
    22.         // print debug message to logcat
    23.         Log.d("OverrideActivity", "onCreate called!");
    24.     }
    25. }
    26.  
    And my manifest
    Code (JavaScript):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.jpr.jprtest" android:versionName="1.0" android:versionCode="1">
    3.   <application android:icon="@drawable/app_icon" android:label="@string/app_name">
    4.     <activity android:name="com.jpr.jprtest.MainActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="landscape">
    5.       <meta-data android:name="android.app.lib_name" android:value="unity" />
    6.       <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
    7.       <intent-filter>
    8.         <action android:name="android.intent.action.MAIN" />
    9.         <category android:name="android.intent.category.LAUNCHER" />
    10.       </intent-filter>
    11.     </activity>
    12.   </application>
    13. </manifest>
    Not seeing anything out of the norm based on all the threads i've checked out.. but whenever i run it get an immediate crash.

    Code (CSharp):
    1. 7-24 22:15:38.806 19874-19874/? E/AndroidRuntime: FATAL EXCEPTION: main
    2.                                                    Process: com.jpr.jprtest, PID: 19874
    3.                                                    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.jpr.jprtest/com.jpr.jprtest.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.jpr.jprtest.MainActivity" on path: DexPathList[[zip file "/mnt/asec/com.jpr.jprtest-1/pkg.apk"],nativeLibraryDirectories=[/mnt/asec/com.jpr.jprtest-1/lib, /vendor/lib, /system/lib]]
    4.                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2412)
    5.                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2603)
    6.                                                       at android.app.ActivityThread.access$900(ActivityThread.java:174)
    7.                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1325)
    8.                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
    9.                                                       at android.os.Looper.loop(Looper.java:146)
    10.                                                       at android.app.ActivityThread.main(ActivityThread.java:5752)
    11.                                                       at java.lang.reflect.Method.invokeNative(Native Method)
    12.                                                       at java.lang.reflect.Method.invoke(Method.java:515)
    13.                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
    14.                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
    15.                                                       at dalvik.system.NativeStart.main(Native Method)
    16.                                                    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.jpr.jprtest.MainActivity" on path: DexPathList[[zip file "/mnt/asec/com.jpr.jprtest-1/pkg.apk"],nativeLibraryDirectories=[/mnt/asec/com.jpr.jprtest-1/lib, /vendor/lib, /system/lib]]
    17.                                                        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    18.                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    19.                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    20.                                                        at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
    21.                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403)
    22.                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2603)
    23.                                                        at android.app.ActivityThread.access$900(ActivityThread.java:174)
    24.                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1325)
    25.                                                        at android.os.Handler.dispatchMessage(Handler.java:102)
    26.                                                        at android.os.Looper.loop(Looper.java:146)
    27.                                                        at android.app.ActivityThread.main(ActivityThread.java:5752)
    28.                                                        at java.lang.reflect.Method.invokeNative(Native Method)
    29.                                                        at java.lang.reflect.Method.invoke(Method.java:515)
    30.                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
    31.                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
    32.                                                        at dalvik.system.NativeStart.main(Native Method)
    Appreciate any insight you may have!
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    You have defined your activity with 1 name, but then declared another name in the AndroidManifest.

    The full name must match (e.g: packagename.activityname)
     
    Yury-Habets likes this.
  3. bpritchard

    bpritchard

    Joined:
    Jan 29, 2009
    Posts:
    444
    Thanks @liortal,

    I tried that initially but it conflicts against the actual aar manifest i'm guessing. it fails in the manifest combiner portion, but only when i try and add that fill package name to the unity manifest.
     
  4. bpritchard

    bpritchard

    Joined:
    Jan 29, 2009
    Posts:
    444
    After a little more digging and taking the time to look at my functions i realized they weren't static methods. :| Sooooo... that now works once i made them all static.

    But now i've run into a bigger issue. basically what i'm working on in essentially a bridge to an existing toolset, that is delivered as an aar. So i've included the aar in my android project as a module (as i've done with a appcompat and design modules), then when i build it my output aar is only 54K. Obviously doesn't include all the aars that i added as modules. So i've copied them all into my Plugins/Android plugin. When i build and run it goes well until i call my functions which in turn call the functions included in the provided aar.

    First i get errors trying to access the functions in the provided aar from MY code...
    Code (CSharp):
    1. 07-25 21:59:58.352 1066-1089/? W/dalvikvm: Unable to resolve superclass of Lcom/jr/sdk/views/activities/LaunchActivity; (361)
    2. 07-25 21:59:58.352 1066-1089/? W/dalvikvm: Link of class 'Lcom/jr/sdk/views/activities/LaunchActivity;' failed
    3. 07-25 21:59:58.352 1066-1089/? E/dalvikvm: Could not find class 'com.jr.sdk.views.activities.LaunchActivity', referenced from method com.jr.sdk.JR.showDashboard
    4. 07-25 21:59:58.352 1066-1089/? W/dalvikvm: VFY: unable to resolve const-class 1844 (Lcom/jr/sdk/views/activities/LaunchActivity;) in Lcom/jr/sdk/JR;
    then a bunch of "Could not get typeface" exceptions. All of which leads to a java.lang.NullPointerException.

    Any thoughts on this? I'm sure its something to do with how my provided AAR's are being included but its getting to part of it.. not all of it.
     
  5. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Are you sure you included all the relevant libraries in the Unity project?
    What is this class? are you sure you're including the library it is declared in your Unity project ?
     
  6. bpritchard

    bpritchard

    Joined:
    Jan 29, 2009
    Posts:
    444
    Ok small update. I was able to properly build the aar with all classes (I think), put that in unity and have unity build correctly. Now i'm having the opposite issue. Its all there, and it builds just fine no errors but when i try and access the classes it doesn't do anything! I have unity log messages around that do fire, but the actual log messages from Android are not.

    Now.. i am making a BIG assumption that the manifest combiner is loading the necessary manifests from my aar but that might be incorrect. And it seems whenever i make a manifest it all comes crumbling down. I've tried making a default one and adding in the single function i need from android as <application> but no matter what i do at a manifest level it shuts the app down completely.
     
  7. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Please post some code sample showing how you are invoking your native Android code.

    What are you trying to do exactly? are you launching another activity? please specify.