Hello,
I’m trying to use a third party native (C++) library that requires a JNIEnv pointer for initialization.
I decided to try and start from the beginning with a simple test application where I’d use Android Studio to create a library with a JNI call to C++ code. In fact, if I just use Android Studio to auto-generate a project for me, and I build and deploy it to my Android phones, it works fine with a “Hello from C++!” message.
However, when I try and build it as a library and drop the AAR file into a blank Unity 2017.2 project, then try and Build&Run it, I get a popup saying “Failure to Initialize! Your hardware does not support this application, sorry!”
If I remove the AAR file, the project builds and runs fine. Adding it back in, and I get that failure popup again. This happens both on a Pixel XL (Android 8.0) and a Lenovo Phab 2 (Android 6.0).
Considering that this error is triggered by the mere existense of the AAR file (I don’t even have any code in the Unity project, it’s a brand new project with no other action taken other than to switch the platform to Android), I’m a bit stumped on where to go from here.
Are there any existing examples out there on how to call a C++ library that requires a JNIEnv pointer?
Sounds like your .so can’t be loaded.
Logcat may be helpful.
Unity - Manual: Native plug-ins for Android - here you can find a native plugin example - please let us know if it doesn’t work for you.
Well, yes, directly accessing a .so library with DllImport works, so that’s not an issue. It’s the fact I need a JNIEnv pointer that’s troublesome for me because that means adding a Java wrapper to get the pointer, then pass that to C++.
So that means DllImport isn’t an option. I’d have to communicate with the C++ native library through the Java layer.
Unless there’s some other way I missed, which allows me to skip a Java layer and directly communicate with the C++ library using an IntPtr?
Here’s a logcat of when I try to launch the app and got that hardware not supported error:
Logcat
11-15 09:52:24.488 1410 4474 I ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.xxxxx.jnihelper/com.unity3d.player.UnityPlayerActivity (has extras)} from uid 10027 on display 0
11-15 09:52:24.490 5002 5005 E ANDR-PERF-MPCTL: Invalid profile no. 0, total profiles 0 only
11-15 09:52:24.505 1410 1444 W BroadcastQueue: Permission Denial: broadcasting Intent { act=com.android.launcher3.action.LAUNCH flg=0x10 (has extras) } from com.android.launcher3 (pid=8217, uid=10027) requires com.google.android.launcher.permission.RECEIVE_LAUNCH_BROADCASTS due to receiver com.google.android.gms/.icing.proxy.ApplicationLauncherReceiver
11-15 09:52:24.505 1410 1444 W BroadcastQueue: Permission Denial: receiving Intent { act=com.android.launcher3.action.LAUNCH flg=0x10 (has extras) } to com.google.android.gms/.chimera.GmsIntentOperationService$GmsExternalReceiver requires com.android.launcher3.permission.RECEIVE_LAUNCH_BROADCASTS due to sender com.android.launcher3 (uid 10027)
11-15 09:52:24.506 540 3605 E audio_route: audio_route_apply_and_update_path:name(speaker-protected)
11-15 09:52:24.506 540 3605 I soundtrigger: audio_extn_sound_trigger_update_device_status: device 0x64 of type 1 for Event 1, with Raise=0
11-15 09:52:24.506 540 3605 E audio_route: audio_route_apply_and_update_path:name(vi-feedback)
11-15 09:52:24.506 540 3605 E voice : voice_is_in_call_rec_stream: input stream is NULL
11-15 09:52:24.506 540 3605 E ACDB-LOADER: Error: ACDB AudProc vol returned = -19
11-15 09:52:24.506 540 3605 E audio_route: audio_route_apply_and_update_path:name(spkr-vi-record)
11-15 09:52:24.515 540 3605 E voice : voice_is_in_call_rec_stream: input stream is NULL
11-15 09:52:24.516 540 3605 E ACDB-LOADER: Error: ACDB_CMD_GET_AUDPROC_COMMON_TABLE_SIZE Returned = -19
11-15 09:52:24.516 540 3605 E ACDB-LOADER: Error: ACDB audproc returned = -19
11-15 09:52:24.516 540 3605 E ACDB-LOADER: Error: ACDB AudProc vol returned = -19
11-15 09:52:24.516 28361 28361 I art : Late-enabling -Xcheck:jni
11-15 09:52:24.516 540 3605 E ACDB-LOADER: Error: ACDB AFE returned = -19
11-15 09:52:24.517 540 3605 I audio_hw_primary: select_devices Selected apptype: 69937
11-15 09:52:24.517 540 3605 I audio_hw_utils: audio_extn_utils_send_app_type_cfg app_type 69937, acdb_dev_id 101, sample_rate 48000
11-15 09:52:24.517 540 3605 E audio_route: audio_route_apply_and_update_path:name(low-latency-playback speaker-protected)
11-15 09:52:24.519 1410 4383 I ActivityManager: Start proc 28361:com.xxxxx.jnihelper/u0a136 for activity com.xxxxx.jnihelper/com.unity3d.player.UnityPlayerActivity
11-15 09:52:24.550 28361 28361 E Unity : Unable to find main
11-15 09:52:24.603 28361 28373 I Adreno : QUALCOMM build : 36240ec, Id385c0b2ba
11-15 09:52:24.603 28361 28373 I Adreno : Build Date : 05/25/16
11-15 09:52:24.603 28361 28373 I Adreno : OpenGL ES Shader Compiler Version: XE031.06.00.02
11-15 09:52:24.603 28361 28373 I Adreno : Local Branch : mybranch19954368
11-15 09:52:24.603 28361 28373 I Adreno : Remote Branch : quic/LA.BR.1.3.4_rb1.12
11-15 09:52:24.603 28361 28373 I Adreno : Remote Branch : NONE
11-15 09:52:24.603 28361 28373 I Adreno : Reconstruct Branch : NOTHING
11-15 09:52:24.606 28361 28373 I OpenGLRenderer: Initialized EGL, version 1.4
11-15 09:52:24.645 1410 1449 I ActivityManager: Displayed com.xxxxx.jnihelper/com.unity3d.player.UnityPlayerActivity: +138ms
--------- beginning of crash
11-15 09:52:29.579 28361 28361 E AndroidRuntime: FATAL EXCEPTION: main
11-15 09:52:29.579 28361 28361 E AndroidRuntime: Process: com.xxxxx.jnihelper, PID: 28361
11-15 09:52:29.579 28361 28361 E AndroidRuntime: java.lang.Error: FATAL EXCEPTION [main]
11-15 09:52:29.579 28361 28361 E AndroidRuntime: Unity version : 2017.2.0f3
11-15 09:52:29.579 28361 28361 E AndroidRuntime: Device model : LENOVO Lenovo PB2-690Y
11-15 09:52:29.579 28361 28361 E AndroidRuntime: Device fingerprint: Lenovo/phinny_na/PB2PRO:6.0.1/MMB29M/PB2-690Y_S200032_161214:user/release-keys
11-15 09:52:29.579 28361 28361 E AndroidRuntime:
11-15 09:52:29.579 28361 28361 E AndroidRuntime: Caused by: java.lang.RuntimeException: Unable to destroy activity {com.xxxxx.jnihelper/com.unity3d.player.UnityPlayerActivity}: java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean android.os.Handler.sendMessage(android.os.Message)’ on a null object reference
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3832)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3850)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at android.app.ActivityThread.access$1500(ActivityThread.java:150)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5418)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean android.os.Handler.sendMessage(android.os.Message)’ on a null object reference
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at android.os.Message.sendToTarget(Message.java:416)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at com.unity3d.player.UnityPlayer$c.a(Unknown Source)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at com.unity3d.player.UnityPlayer$c.a(Unknown Source)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at com.unity3d.player.UnityPlayer.quit(Unknown Source)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at com.unity3d.player.UnityPlayerActivity.onDestroy(Unknown Source)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at android.app.Activity.performDestroy(Activity.java:6456)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1143)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3819)
11-15 09:52:29.579 28361 28361 E AndroidRuntime: … 9 more
11-15 09:52:29.597 1410 1428 W InputMethodManagerService: Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@755adef attribute=null, token = android.os.BinderProxy@994bdd2
11-15 09:52:29.620 1410 3993 I OpenGLRenderer: Initialized EGL, version 1.4
11-15 09:52:29.850 1410 1447 E WallpaperManagerService: onEvent:settings_system.xml.bak,changedFile:/data/system/users/0/settings_system.xml.bak
11-15 09:52:29.865 1410 1447 E WallpaperManagerService: onEvent:settings_system.xml,changedFile:/data/system/users/0/settings_system.xml
11-15 09:52:29.868 1410 1447 E WallpaperManagerService: onEvent:settings_system.xml.bak,changedFile:/data/system/users/0/settings_system.xml.bak
11-15 09:52:29.973 711 711 I MSM-irqbalance: Decided to move IRQ222 from CPU0 to CPU2
11-15 09:52:31.561 28361 28361 I Process : Sending signal. PID: 28361 SIG: 9
11-15 09:52:31.578 1410 3920 W InputMethodManagerService: Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4cdf83 attribute=null, token = android.os.BinderProxy@994bdd2
11-15 09:52:31.633 1410 4469 I WindowState: WIN DEATH: Window{cfbf6a0 u0 com.xxxxx.jnihelper/com.unity3d.player.UnityPlayerActivity}
11-15 09:52:31.643 1410 4415 I ActivityManager: Process com.xxxxx.jnihelper (pid 28361) has died
Just about the only clue I have is this line:
11-15 09:52:24.550 28361 28361 E Unity : Unable to find main
It’s a library though… and a pretty barebones one at that (autogenerated projects by Android Studio and Unity). What could Unity be looking for?
Also a reminder that I see this issue on a Pixel XL, which should be supported even if the Lenovo isn’t.
I’ve had a similar problem. Verify that you are not building your AAR library with 64-bit support.
You can check if you have these files by extracting the AAR file (it’s a zip file) and looking in the JNI folder. For ARM support there should be a folder “armeabi-v7a” in there. If there is a “arm64-v8a” then that means it has been build with 64 bit support as well (which doesn’t work).
In Android Studio you control which architectures are built by adding the ndk part below for that project in the Gradle files.
defaultConfig {
…
ndk {
abiFilters “armeabi-v7a”
}
}
You can also add other architectures if you also need to build for x86 and similar to make it work in the editor as well.
1 Like