Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

App Fails on launch - AAR plugin

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

  1. bpritchard


    Jan 29, 2009
    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):
    3. package com.jpr.jprunityandroid;
    5. import android.os.Bundle;
    6. import android.util.Log;
    8. import com.unity3d.player.UnityPlayer;
    9. import com.unity3d.player.UnityPlayerActivity;
    10. import android.content.Context;
    12. public class MainActivity extends UnityPlayerActivity {
    15.     @Override
    16.     protected void onCreate(Bundle bundle) {
    19.         // call UnityPlayerActivity.onCreate()
    20.         super.onCreate(bundle);
    22.         // print debug message to logcat
    23.         Log.d("OverrideActivity", "onCreate called!");
    24.     }
    25. }
    And my manifest
    Code (JavaScript):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns: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: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
    5.                                                       at
    6.                                                       at$900(
    7.                                                       at$H.handleMessage(
    8.                                                       at android.os.Handler.dispatchMessage(
    9.                                                       at android.os.Looper.loop(
    10.                                                       at
    11.                                                       at java.lang.reflect.Method.invokeNative(Native Method)
    12.                                                       at java.lang.reflect.Method.invoke(
    13.                                                       at$
    14.                                                       at
    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(
    18.                                                        at java.lang.ClassLoader.loadClass(
    19.                                                        at java.lang.ClassLoader.loadClass(
    20.                                                        at
    21.                                                        at
    22.                                                        at
    23.                                                        at$900(
    24.                                                        at$H.handleMessage(
    25.                                                        at android.os.Handler.dispatchMessage(
    26.                                                        at android.os.Looper.loop(
    27.                                                        at
    28.                                                        at java.lang.reflect.Method.invokeNative(Native Method)
    29.                                                        at java.lang.reflect.Method.invoke(
    30.                                                        at$
    31.                                                        at
    32.                                                        at dalvik.system.NativeStart.main(Native Method)
    Appreciate any insight you may have!
  2. liortal


    Oct 17, 2012
    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


    Jan 29, 2009
    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


    Jan 29, 2009
    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


    Oct 17, 2012
    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


    Jan 29, 2009
    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


    Oct 17, 2012
    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.