-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to load native library for native activity on Android 5.1 #144
Comments
You should at the very least share the exact command that you are running together with the log output so that we can take a closer look. Otherwise it's not more than guesswork as these examples are only tested on more recent versions of Android. |
I reduced it to exporting an empty ANativeActivity_onCreate function with the correct arguments, but the issue still occurs, so I guess it's out of the scope of this project. Maybe an issue in cargo apk. Edit: apparently you replaced cargo apk with cargo xbuild; I'll have to try that. I guess this project's readme should be updated to use cargo xbuild instead of cargo apk? |
Maybe check what libraries/symbols the resulting library needs with |
output:
output:
The code:
Cargo.toml
src/lib.rs
build:
rustup 1.26.0 Is there documentation on how to use cargo xbuild with android target? The readme mentions json files for targets but not what to put in them. |
The release variant has the same issue btw
|
The issue occurs on an emulated Lollipop device (when adding the target to Cargo.toml, i686-linux-android in my case). The bionic libc seems to export these functions. The apk contains libna_mainloop.so |
I think I found it; it seems to be a bug that was solved in sdk 24. The workaround is to use a Java class extending NativeActivity and manually load the so file: https://www.androidbugfix.com/2022/01/javalangillegalargumentexception-unable.html?m=1 So ideally that would need to be done by android-activity, if it's possible to include a java class (maybe just a binary class in the repository). This might also be a good opportunity to add the JNI functions not available in NativeActivity. Or perhaps better: the workaround would be done by cargo apk/xbuild when min_sdk < 24 and when the ANativeActivity_onCreate export is detected. |
Doing this gets you past the error, but the next error is that the ELF symbol table is in the new GNU style, which is only supported for api > 22. Using cargo rustflags I managed to pass "--hash-style=both" to the linker, but then it says "ld.exe: unrecognized option '--eh-frame-hdr'"; looks like a cross-compiling issue. I might have a closer look at getting cargo xbuild to work (right now it says the NativeActivity class doesn't exist). |
i'm trying to use this crate, but because my build were not works on my own phone (api 21) i uploaded the apk to my friend and it worked, i tryed to find out what is going wrong, and i thing it's an undefined symbol called: __system_property_read_callback the way i found this i build my cargo project using staticlib insted of cdylib and then created the apk using android studio throw linking the .a file using CMakeList.txt
gradle error logs
when i'm was trying to make this works i increased the minSdk to 26 and it starts to building without error also i tryed cargo-ndk and cargo-apk and xbuild too, cargo-ndk and cargo-apk was able to build apk file but with xbuild i'm ws getting this error
and this is the xbuild doctor logs
tell me if you need more information (btw because the errors on my phone and emulator was the same i'm was testing on x86_64 api v21 emulator) |
It's an unrelated issue; my issue is caused by legacy library loading issues that would require a workaround in android-activity. (__system_property_read_callback function appears in API 26 so it's not going to work on older phones) |
api 21 is android 5.0, and api 22 is android 5.1 and they just support android 8 (api 26) and newer. |
I can confirm that android-activity compiles for sdk 22, it's a bug in the library loading process that prevents me from using it. |
actually i'm not adding anything to it, just a cargo with android-activity that say hello to logcat and then exit(0), then linking it throw CMakeList.txt insted of letting cargo-ndk/apk building it. so if there is a solution that helps you, maybe it will help me too ? after that, if nothing works i'll open another one. |
i tryed to link libc statically from the api 21 ones availble in ndk 26 aarch64 and it compiled but got fatal error when tryed to run on my phone, but when i teyed to link with shared libc one i got the same undefined symbole, but when i tryed to compile using shared libc from api 26 it compied, i think it's either libc's fault or android-activity. |
In the end I got it to work with GameActivity; it seems that is the better choice. |
Running the example from the README, with this added to Cargo.toml:
I get an exception on Android 5.1 arm64-v8a that it's unable to load the so file, no further clues.
I had the same issue with winit:
rust-windowing/glutin#1644
Any ideas on how to proceed?
The text was updated successfully, but these errors were encountered: