rust-windowing / glutin

A low-level library for OpenGL context creation
Apache License 2.0
2k stars 478 forks source link

Unable to load native library for native activity on Android 5.1 #1644

Closed fr-an-k closed 6 days ago

fr-an-k commented 1 year ago

The Android 5.1 device that I need to support fails to load a minimal example (feature "android-native-activity", no default), whatever I try, but works on other devices like 8.1. I used cargo apk.

It's not able to load libandroid.so

The only hint are warnings about unused DT entries, but I don't think that's the cause. Any ideas on what step I could take?

``` FATAL EXCEPTION: main Process: ... java.lang.RuntimeException: Unable to start activity ComponentInfo{.../android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/app/...-2/lib/arm64/libandroid.so at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2534) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2608) at android.app.ActivityThread.access$800(ActivityThread.java:178) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5637) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754) Caused by: java.lang.IllegalArgumentException: Unable to load native library: /data/app/com.unovica.glow-2/lib/arm64/libandroid.so at android.app.NativeActivity.onCreate(NativeActivity.java:182) at android.app.Activity.performCreate(Activity.java:6092) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2608)  at android.app.ActivityThread.access$800(ActivityThread.java:178)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)  at android.os.Handler.dispatchMessage(Handler.java:111)  at android.os.Looper.loop(Looper.java:194)  at android.app.ActivityThread.main(ActivityThread.java:5637)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)  ```

This was based on https://github.com/rust-windowing/glutin with this added to glutin_examples/Cargo.toml:

[package.metadata.android.sdk]
min_sdk_version = 22 # instead of default 23

Then:

cargo apk r -p glutin_examples --example android

Which causes the issue; when I strip it to the minimum, the issue remains.

MarijnS95 commented 1 year ago

Transferring to glutin as this has nothing to do with winit.


It used to be the case that naming the Rust library libandroid.so caused trouble ^1, because Android... also provides libandroid.so. But it seems https://github.com/rust-windowing/glutin/commit/26a21fe73a3d6b4b403d1256b2e184ea2568d921#diff-f7f21ed25a8ba280480db849c25c183fc06f9f8bae3c7200bca2b2076af5ecf5 slipped through the cracks, as if this is no longer a problem on recent Android.

Can you test out https://github.com/MarijnS95/glutin/compare/android-app-lib-name just in case (replace the command with --example android_app)? Those errors back then used to be a bit different, perhaps there's different incompatibilities that would need to be solved on the xbuild/cargo-apk side though I doubt anyone is going to help out supporting an Android version that's EOL for well over 8 years.

  https://github.com/rust-mobile/ndk/issues/250#issuecomment-1076228905
  https://github.com/rust-mobile/ndk/issues/143#issuecomment-829500467
fr-an-k commented 1 year ago

I followed the readme exactly, with the min_sdk_version set one lower for 5.1. I renamed it to android2 the same way as your changes, but it didn't do the trick. I know 5.1 is nasty, that's why I'm going low-level. It's just strange that no reason is given why the native library won't load, maybe someone had an idea.

``` 2023-11-01 00:24:50.689 5183-5183 art rust.example.android2 I Late-enabling -Xcheck:jni 2023-11-01 00:24:50.690 752-3163 ActivityManager system_process I Start proc 5183:rust.example.android2/u0a90 for activity rust.example.android2/android.app.NativeActivity 2023-11-01 00:24:50.691 1507-1507 ActivityThread com.android.launcher3 D ACT-PAUSE_ACTIVITY handled : 1 / android.os.BinderProxy@460cde0 2023-11-01 00:24:50.691 1507-1507 Launcher3 com.android.launcher3 D BubbleTextView, drawUnreadEvent() this = com.android.launcher3.BubbleTextView{178f4bc6 VFED..CL ...P.... 400,0-600,189 #2} 2023-11-01 00:24:50.691 1507-1507 Launcher3 com.android.launcher3 D BubbleTextView, drawDeleteButton() mDeleteButtonVisiable = false, this = com.android.launcher3.BubbleTextView{178f4bc6 VFED..CL ...P.... 400,0-600,189 #2} 2023-11-01 00:24:50.693 317-317 ADB_SERVICES pid-317 D Adding socket 40 pid 5183 to jdwp process list 2023-11-01 00:24:50.696 1507-1507 Launcher3 com.android.launcher3 D BubbleTextView, drawUnreadEvent() this = com.android.launcher3.BubbleTextView{178f4bc6 VFED..CL ........ 400,0-600,189 #2} 2023-11-01 00:24:50.696 1507-1507 Launcher3 com.android.launcher3 D BubbleTextView, drawDeleteButton() mDeleteButtonVisiable = false, this = com.android.launcher3.BubbleTextView{178f4bc6 VFED..CL ........ 400,0-600,189 #2} 2023-11-01 00:24:50.696 317-317 ADB_SERVICES pid-317 W create_local_service_socket() name=jdwp:5183 2023-11-01 00:24:50.696 317-317 ADB_SERVICES pid-317 W service_to_fd() name=jdwp:5183 2023-11-01 00:24:50.697 317-317 ADB_SERVICES pid-317 W looking for pid 5183 in JDWP process list return fds0(43) fds1(45) 2023-11-01 00:24:50.697 317-317 ADB_SERVICES pid-317 W LS(146): bound to 'jdwp:5183' via 43 2023-11-01 00:24:50.697 317-317 ADB_SERVICES pid-317 W trying to write to JDWP socket=40 pid=5183 count=1 out_fds=45 2023-11-01 00:24:50.697 1507-1629 Surface com.android.launcher3 D Surface::setBuffersDimensions(this=0x7f9620c600,w=800,h=1280) 2023-11-01 00:24:50.698 317-317 ADB_SERVICES pid-317 D adb socket write list (36) (51) (47) (50) (52) (56) (53) (57) (58) (59) (60) (61) (62) (63) (64) (66) (65) (67) (68) (69) (70) (72) (71) (73) (75) (74) (76) (78) (77) (79) (48) (80) (82) (40) (43) 2023-11-01 00:24:50.698 317-317 ADB_SERVICES pid-317 D write_data=44530185 2023-11-01 00:24:50.705 1507-1629 Surface com.android.launcher3 D Surface::setBuffersDimensions(this=0x7f9620c600,w=800,h=1280) 2023-11-01 00:24:50.709 752-769 InputReader system_process D InputReader:: getSwitchState lock 2023-11-01 00:24:50.710 752-769 InputReader system_process D InputReader::getStateLocked:: return 2023-11-01 00:24:50.710 752-769 libPerfService system_process I perfSetFavorPid - pid:5183, 143f 2023-11-01 00:24:50.712 752-769 FeatureProxyBase system_process D FeatureProxyBase class constructor 2023-11-01 00:24:50.712 752-769 MultiWindow system_process D MultiWindowProxy constructor. 2023-11-01 00:24:50.712 752-769 FeatureProxyBase system_process D getService(), serviceName = multiwindow_service_v1 2023-11-01 00:24:50.713 752-769 FeatureProxyBase system_process D FeatureProxyBase class constructor 2023-11-01 00:24:50.714 752-769 MultiWindow system_process D MultiWindowProxy constructor. 2023-11-01 00:24:50.714 752-769 FeatureProxyBase system_process D getService(), serviceName = multiwindow_service_v1 2023-11-01 00:24:50.715 752-769 FeatureProxyBase system_process D FeatureProxyBase class constructor 2023-11-01 00:24:50.715 752-769 MultiWindow system_process D MultiWindowProxy constructor. 2023-11-01 00:24:50.715 752-769 FeatureProxyBase system_process D getService(), serviceName = multiwindow_service_v1 2023-11-01 00:24:50.716 1137-1137 PhoneStatusBar com.android.systemui D hiding the MENU button 2023-11-01 00:24:50.717 752-769 FeatureProxyBase system_process D FeatureProxyBase class constructor 2023-11-01 00:24:50.717 752-769 MultiWindow system_process D MultiWindowProxy constructor. 2023-11-01 00:24:50.717 752-769 FeatureProxyBase system_process D getService(), serviceName = multiwindow_service_v1 2023-11-01 00:24:50.718 1507-1629 OpenGLRenderer com.android.launcher3 D Flushing caches (mode 0) 2023-11-01 00:24:50.719 1507-1629 Surface com.android.launcher3 D Surface::disconnect(this=0x7f9620c600,api=1) 2023-11-01 00:24:50.719 1507-1629 GraphicBuffer com.android.launcher3 D unregister, handle(0x7f7ccceec0) (w:800 h:1280 s:800 f:0x1 u:0x000b00) 2023-11-01 00:24:50.719 1507-1629 GraphicBuffer com.android.launcher3 D unregister, handle(0x7f7cccef60) (w:800 h:1280 s:800 f:0x1 u:0x000b00) 2023-11-01 00:24:50.719 1507-1629 GraphicBuffer com.android.launcher3 D unregister, handle(0x7f8b97be20) (w:800 h:1280 s:800 f:0x1 u:0x000b00) 2023-11-01 00:24:50.720 255-1002 BufferQueueProducer pid-255 I [com.android.launcher3/com.android.launcher3.Launcher](this:0x7f95bcd000,id:46,api:1,p:-1,c:255) disconnect(P): api 1 2023-11-01 00:24:50.720 255-1002 BufferQueueConsumer pid-255 I [com.android.launcher3/com.android.launcher3.Launcher](this:0x7f95bcd000,id:46,api:1,p:-1,c:255) getReleasedBuffers: returning mask 0xfffffffffffffffb 2023-11-01 00:24:50.720 255-1002 GraphicBuffer pid-255 D free, handle(0x7f9c412480) (w:800 h:1280 s:800 f:0x1 u:0x000b00) 2023-11-01 00:24:50.720 1507-1629 OpenGLRenderer com.android.launcher3 D Flushing caches (mode 0) 2023-11-01 00:24:50.737 255-255 GraphicBuffer pid-255 D free, handle(0x7f9c412c00) (w:800 h:1280 s:800 f:0x1 u:0x000b00) 2023-11-01 00:24:50.737 752-1506 FeatureProxyBase system_process D FeatureProxyBase class constructor 2023-11-01 00:24:50.737 752-778 libPerfService system_process I perfSetFavorPid - pid:5183, 143f 2023-11-01 00:24:50.737 752-1506 MultiWindow system_process D MultiWindowProxy constructor. 2023-11-01 00:24:50.737 752-1506 FeatureProxyBase system_process D getService(), serviceName = multiwindow_service_v1 2023-11-01 00:24:50.738 752-778 NetworkStats system_process V setKernelCounterSet uid=10090 set=1 2023-11-01 00:24:50.738 752-1008 ConnectivityService system_process D onUidRulesChanged(uid=10090, uidRules=0) 2023-11-01 00:24:50.739 752-1506 FeatureProxyBase system_process D FeatureProxyBase class constructor 2023-11-01 00:24:50.739 752-1506 MultiWindow system_process D MultiWindowProxy constructor. 2023-11-01 00:24:50.739 752-1506 FeatureProxyBase system_process D getService(), serviceName = multiwindow_service_v1 2023-11-01 00:24:50.740 752-1024 PerfServiceManager system_process D [PerfService] MESSAGE_TIMER_SCN_APP_LAUNCH 2023-11-01 00:24:50.740 752-1024 libPerfService system_process I 8: set: 3 2023-11-01 00:24:50.740 752-1024 libPerfService system_process I 8: set freq: 819000 2023-11-01 00:24:50.740 5183-5183 SettingsInterface rust.example.android2 V invalidate [system]: current 2 != cached 0 2023-11-01 00:24:50.740 752-1082 ActivityManager system_process D getContentProviderImpl: from caller=android.app.ApplicationThreadProxy@3e3cdcac (pid=5183, userId=0) to get content provider settings cpr=ContentProviderRecord{22ea02de u0 com.android.providers.settings/.SettingsProvider} 2023-11-01 00:24:50.741 752-1082 ActivityManager system_process D getContentProviderImpl: updateLruProcessLocked cpr.proc=ProcessRecord{200b927d 752:system/1000} 2023-11-01 00:24:50.741 752-784 FeatureProxyBase system_process D FeatureProxyBase class constructor 2023-11-01 00:24:50.741 5183-5183 ActivityThread rust.example.android2 D hoder:android.app.IActivityManager$ContentProviderHolder@140dd8b0,provider,holder.Provider:android.content.ContentProviderProxy@a0b1329 2023-11-01 00:24:50.741 752-784 MultiWindow system_process D MultiWindowProxy constructor. 2023-11-01 00:24:50.741 752-784 FeatureProxyBase system_process D getService(), serviceName = multiwindow_service_v1 2023-11-01 00:24:50.742 752-1504 SettingsProvider system_process V call(system:anr_debugging_mechanism) for 0 2023-11-01 00:24:50.742 752-1504 SettingsProvider system_process D lookupValue table system cache contains Key anr_debugging_mechanism , value = Bundle[{value=1}] 2023-11-01 00:24:50.747 5183-5183 Proxy rust.example.android2 D setHttpRequestCheckHandler 2023-11-01 00:24:50.748 5183-5183 ActivityThread rust.example.android2 D BIND_APPLICATION handled : 0 / AppBindData{appInfo=ApplicationInfo{ddf9c4f rust.example.android2}} 2023-11-01 00:24:50.748 5183-5183 ActivityThread rust.example.android2 V Handling launch of ActivityRecord{3defcfdc token=android.os.BinderProxy@1098b8e5 {rust.example.android2/android.app.NativeActivity}} 2023-11-01 00:24:50.749 5183-5183 ActivityThread rust.example.android2 V ActivityRecord{3defcfdc token=android.os.BinderProxy@1098b8e5 {rust.example.android2/android.app.NativeActivity}}: app=android.app.Application@12980dc8, appName=rust.example.android2, pkg=rust.example.android2, comp={rust.example.android2/android.app.NativeActivity}, dir=/data/app/rust.example.android2-1/base.apk 2023-11-01 00:24:50.750 5183-5183 FeatureProxyBase rust.example.android2 D FeatureProxyBase class constructor 2023-11-01 00:24:50.750 5183-5183 MultiWindow rust.example.android2 D MultiWindowProxy constructor. 2023-11-01 00:24:50.750 5183-5183 FeatureProxyBase rust.example.android2 D getService(), serviceName = multiwindow_service_v1 2023-11-01 00:24:50.751 5183-5183 FeatureProxyBase rust.example.android2 D FeatureProxyBase class constructor 2023-11-01 00:24:50.751 5183-5183 MultiWindow rust.example.android2 D MultiWindowProxy constructor. 2023-11-01 00:24:50.751 5183-5183 FeatureProxyBase rust.example.android2 D getService(), serviceName = multiwindow_service_v1 2023-11-01 00:24:50.752 5183-5183 FeatureProxyBase rust.example.android2 D FeatureProxyBase class constructor 2023-11-01 00:24:50.752 5183-5183 MultiWindow rust.example.android2 D MultiWindowProxy constructor. 2023-11-01 00:24:50.752 5183-5183 FeatureProxyBase rust.example.android2 D getService(), serviceName = multiwindow_service_v1 2023-11-01 00:24:50.758 5183-5183 AccessibilityManager rust.example.android2 D setStateLocked: wasEnabled = false, mIsEnabled = false, wasTouchExplorationEnabled = false, mIsTouchExplorationEnabled = false, wasHighTextContrastEnabled = false, mIsHighTextContrastEnabled = false java.lang.Throwable: setStateLocked at android.view.accessibility.AccessibilityManager.setStateLocked(AccessibilityManager.java:553) at android.view.accessibility.AccessibilityManager.tryConnectToServiceLocked(AccessibilityManager.java:636) at android.view.accessibility.AccessibilityManager.(AccessibilityManager.java:226) at android.view.accessibility.AccessibilityManager.getInstance(AccessibilityManager.java:206) at android.view.View.setFlags(View.java:9843) at android.view.ViewGroup.initViewGroup(ViewGroup.java:536) at android.view.ViewGroup.(ViewGroup.java:525) at android.view.ViewGroup.(ViewGroup.java:520) at android.view.ViewGroup.(ViewGroup.java:516) at android.view.ViewGroup.(ViewGroup.java:512) at android.widget.FrameLayout.(FrameLayout.java:119) at com.android.internal.policy.impl.PhoneWindow$DecorView.(PhoneWindow.java:2326) at com.android.internal.policy.impl.PhoneWindow.generateDecor(PhoneWindow.java:3463) at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3849) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:440) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:431) at android.app.Activity.setContentView(Activity.java:2195) at android.app.NativeActivity.onCreate(NativeActivity.java:144) at android.app.Activity.performCreate(Activity.java:6092) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2608) at android.app.ActivityThread.access$800(ActivityThread.java:178) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5637) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754) 2023-11-01 00:24:50.759 255-255 Surface pid-255 D Surface::setBuffersDimensions(this=0x7f9cdf5e00,w=800,h=1280) 2023-11-01 00:24:50.762 255-255 BufferQueueProducer pid-255 I [FrameBufferSurface_0](this:0x7f9cd73000,id:0,api:1,p:255,c:255) queueBuffer: fps=14.66 dur=1159.42 max=794.23 min=20.37 2023-11-01 00:24:50.771 5183-5183 linker rust.example.android2 W /data/app/rust.example.android2-1/lib/arm64/libandroid2.so: unused DT entry: type 0x6ffffef5 arg 0xe60 2023-11-01 00:24:50.771 5183-5183 linker rust.example.android2 W /data/app/rust.example.android2-1/lib/arm64/libandroid2.so: unused DT entry: type 0x6ffffffe arg 0xe1c 2023-11-01 00:24:50.771 5183-5183 linker rust.example.android2 W /data/app/rust.example.android2-1/lib/arm64/libandroid2.so: unused DT entry: type 0x6fffffff arg 0x2 2023-11-01 00:24:50.771 5183-5183 AndroidRuntime rust.example.android2 D Shutting down VM 2023-11-01 00:24:50.772 5183-5183 AndroidRuntime rust.example.android2 E FATAL EXCEPTION: main Process: rust.example.android2, PID: 5183 java.lang.RuntimeException: Unable to start activity ComponentInfo{rust.example.android2/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/app/rust.example.android2-1/lib/arm64/libandroid2.so at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2534) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2608) at android.app.ActivityThread.access$800(ActivityThread.java:178) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5637) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754) Caused by: java.lang.IllegalArgumentException: Unable to load native library: /data/app/rust.example.android2-1/lib/arm64/libandroid2.so at android.app.NativeActivity.onCreate(NativeActivity.java:182) at android.app.Activity.performCreate(Activity.java:6092) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2608)  at android.app.ActivityThread.access$800(ActivityThread.java:178)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)  at android.os.Handler.dispatchMessage(Handler.java:111)  at android.os.Looper.loop(Looper.java:194)  at android.app.ActivityThread.main(ActivityThread.java:5637)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)  ```
kchibisov commented 6 days ago

closing since it's an ndk issue and not glutin.

MarijnS95 commented 6 days ago

Yeah, fine to close this as it doesn't seem to be caused by the libandroid.so naming conflict inside Glutin. And this Android version is completely EOL anyway.

If anyone is interested in debugging this they should see if C++ NativeActivity apps compiled via official tooling actually work, and then try to use said toolchain - at least the linker - in Rust to have a more-or-less apples-to-apples comparison. Though technically cargo-apk already utilizes min_sdk_version to select the right cross-compiler/linker from the toolchain.