Android project with Unity JNI libraries crash aft

2019-06-04 17:59发布

问题:

I have android app where I embed game that I make in Unity 3D. Other part of app is written in Cordova/Ionic and I need to use Crosswalk to support older android phones.

But when I add Crosswalk to my project, app crashes right after start with following output:

W/chromium: [WARNING:xwalk_external_extension.cc(58)] Error loading extension '/data/app/com.example.app-2/lib/arm/libmono.so': couldn't get XW_Initialize function.
W/chromium: [WARNING:xwalk_extension_server.cc(407)] Failed to initialize extension: /data/app/com.example.app-2/lib/arm/libmono.so
W/chromium: [WARNING:xwalk_external_extension.cc(58)] Error loading extension '/data/app/com.example.app-2/lib/arm/libxwalkcore.so': couldn't get XW_Initialize function.
W/chromium: [WARNING:xwalk_extension_server.cc(407)] Failed to initialize extension: /data/app/com.example.app-2/lib/arm/libxwalkcore.so
I/chromium: [INFO:xwalk_extension_renderer_controller.cc(42)] EXTENSION PROCESS DISABLED.
W/chromium: [WARNING:xwalk_external_extension.cc(58)] Error loading extension '/data/app/com.example.app-2/lib/arm/libVuforiaWrapper.so': couldn't get XW_Initialize function.
W/chromium: [WARNING:xwalk_extension_server.cc(407)] Failed to initialize extension: /data/app/com.example.app-2/lib/arm/libVuforiaWrapper.so
W/chromium: [WARNING:xwalk_external_extension.cc(58)] Error loading extension '/data/app/com.example.app-2/lib/arm/libunity.so': couldn't get XW_Initialize function.
32398-32443/com.example.app A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 32443 (Chrome_FileThre)
I/DEBUG: property debug.db.uid not set; NOT waiting for gdb.
I/DEBUG: HINT: adb shell setprop debug.db.uid 100000
I/DEBUG: HINT: adb forward tcp:5039 tcp:5039
A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
A/DEBUG: Build fingerprint: 'google/razor/flo:6.0.1/MMB29Q/2480792:user/release-keys'
A/DEBUG: Revision: '0'
A/DEBUG: ABI: 'arm'
A/DEBUG: pid: 32398, tid: 32443, name: Chrome_FileThre  >>> com.example.app <<<
A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
A/DEBUG:     r0 00000000  r1 98034abc  r2 00000002  r3 0013064c
A/DEBUG:     r4 00000000  r5 00130630  r6 00001000  r7 9771a0a0
A/DEBUG:     r8 b5b27000  r9 b5b27dc4  sl b6cfc444  fp 0000000c
A/DEBUG:     ip 00007ebb  sp 9b1fffe8  lr 9771a0e0  pc 9771ac38  cpsr 600f0010
A/DEBUG: backtrace:
A/DEBUG:     #00 pc 00498c38  /data/app/com.example.app-2/lib/arm/libunity.so
A/DEBUG:     #01 pc 004980dc  /data/app/com.example.app-2/lib/arm/libunity.so
A/DEBUG:     #02 pc 00491f88  /data/app/com.example.app-2/lib/arm/libunity.so
A/DEBUG:     #03 pc 004980a8  /data/app/com.example.app-2/lib/arm/libunity.so
A/DEBUG:     #04 pc 00047f9f  /system/lib/libc.so (__cxa_finalize+138)
A/DEBUG:     #05 pc 00002559  /system/bin/linker (__dl__ZN6soinfo13call_functionEPKcPFvvE+48)
A/DEBUG:     #06 pc 00002623  /system/bin/linker (__dl__ZN6soinfo10call_arrayEPKcPPFvvEjb+134)
A/DEBUG:     #07 pc 000026e3  /system/bin/linker (__dl__ZN6soinfo16call_destructorsEv+58)
A/DEBUG:     #08 pc 0000668b  /system/bin/linker (__dl__ZL13soinfo_unloadP6soinfo+266)
A/DEBUG:     #09 pc 000068d7  /system/bin/linker (__dl__Z10do_dlcloseP6soinfo+14)
A/DEBUG:     #10 pc 00001b89  /system/bin/linker (__dl_dlclose+16)
A/DEBUG:     #11 pc 00287de5  /data/app/com.example.app-2/lib/arm/libxwalkcore.so

So, obviously, libunity.so have some kind of problem with libxwalkcore.so

I believe that it is because of Crosswalk is trying to find "XW_Initialize function" in libunity.so and somehow it cause crash of whole app.

When I Use Crosswalk-Lite Everything works fine, except web video (disabled in crosswalk-lite), which I, unfortunately, need.

Is there any way to tell crosswalk not to load libunity.so as a extension?

Or is there any possibility to have Unity JNI libraries in one folder and Crosswalk libraries in second?

Thanks :)

回答1:

It is a little late, but when I installed Crosswalk using this command, it worked:

cordova plugin add cordova-plugin-crosswalk-webview --variable XWALK_VERSION="15" --variable XWALK_MODE="lite"

Why; I don't know. However, I am almost sure that it is not about the mysterious "XW_Initialize" function as crosswalk gives similar warnings for non-Unity .so files as well (for me, at least).

EDIT:

Apparently, settings version to 15 is not necessary; just settings mode to Lite is enough:

cordova plugin add cordova-plugin-crosswalk-webview  --variable XWALK_MODE="lite"


回答2:

I have had the same problem with crosswalk crashing when it reads Unity's libunity.so, but after being stuck on this for days I found a solution:

If Unity's library is loaded before crosswalk is loaded, crosswalk doesn't crash on it.

To achieve this you need to load Unity's library by calling

System.loadLibrary("unity");

before calling loadUrl(launchUrl); in your MainActivity's onCreate.

This worked on my setup with Cordova 7.0.1, Crosswalk webview plugin 2.3.0 and Unity 5.6.4p3