Open fr-an-k opened 10 months ago
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 nm
? If it's the tools' fault we can always transfer this issue.
nm .\target\aarch64-linux-android\release\libna_mainloop.so > nm.txt
output:
nm .\target\aarch64-linux-android\debug\libna_mainloop.so
output:
The code:
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
objdump -T .\target\aarch64-linux-android\release\libna_mainloop.so
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
cmake_minimum_required(VERSION 3.22.1)
project("myapplicationrust04")
add_library(native_app_glue STATIC
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
target_include_directories(native_app_glue PUBLIC
${ANDROID_NDK}/sources/android/native_app_glue)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u android_main")
add_library(${CMAKE_PROJECT_NAME} SHARED
native-lib.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME}
android
#native_app_glue
EGL
GLESv1_CM
log
"C:/Users/Administrator/Documents/IdeaProjectsAndroid/rust-android-test-03/target/x86_64-linux-android/debug/librust_android_test_03.a"
)
gradle error logs
cmd.exe /C "cd . && C:\Users\Administrator\AppData\Local\Android\Sdk\ndk\25.1.8937393\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=x86_64-none-linux-android24 --sysroot=C:/Users/Administrator/AppData/Local/Android/Sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fno-limit-debug-info -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Wl,--gc-sections -Wl,--no-undefined -Qunused-arguments -u ANativeActivity_onCreate -u android_main -shared -Wl,-soname,libmyapplicationrust04.so -o C:\Users\Administrator\Documents\AndroidStudioProjects\MyApplicationRust04\app\build\intermediates\cxx\Debug\1832614v\obj\x86_64\libmyapplicationrust04.so CMakeFiles/myapplicationrust04.dir/native-lib.cpp.o -landroid -lEGL -lGLESv1_CM -llog C:/Users/Administrator/Documents/IdeaProjectsAndroid/rust-android-test-03/target/x86_64-linux-android/debug/librust_android_test_03.a -latomic -lm && cd ."
ld: error: undefined symbol: __system_property_read_callback
>>> referenced by mod.rs:28 (src\android/mod.rs:28)
>>> android_properties-1c7aacace499d228.android_properties.58923fe8a79da236-cgu.0.rcgu.o:(android_properties::android::foreach_property_callback::hfeb79979115df261) in archive C:/Users/Administrator/Documents/IdeaProjectsAndroid/rust-android-test-03/target/x86_64-linux-android/debug/librust_android_test_03.a
>>> referenced by mod.rs:68 (src\android/mod.rs:68)
>>> android_properties-1c7aacace499d228.android_properties.58923fe8a79da236-cgu.0.rcgu.o:(android_properties::android::plat_getprop::h5a385560b42fb536) in archive C:/Users/Administrator/Documents/IdeaProjectsAndroid/rust-android-test-03/target/x86_64-linux-android/debug/librust_android_test_03.a
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
> x build --platform android --arch arm64 --debug
[1/3] Fetch precompiled artifacts
info: component 'rust-std' for target 'aarch64-linux-android' is up to date
[1/3] Fetch precompiled artifacts [119ms]
[2/3] Build rust `template`
Finished dev [unoptimized + debuginfo] target(s) in 0.55s
[2/3] Build rust `template` [630ms]
[3/3] Create apk
Error: program not found
and this is the xbuild doctor logs
> x doctor
--------------------clang/llvm toolchain--------------------
clang 7.1.0 C:\Program Files\LLVM\bin\clang.exe
clang++ 7.1.0 C:\Program Files\LLVM\bin\clang++.exe
llvm-ar unknown C:\Program Files\LLVM\bin\llvm-ar.exe
llvm-lib unknown C:\Program Files\LLVM\bin\llvm-lib.exe
llvm-readobj 14.0.7git C:\Users\Administrator\AppData\Local\Android\Sdk\ndk\25.2.9519653\toolchains\llvm\prebuilt\windows-x86_64\bin\llvm-readobj.exe
lld 7.1.0 C:\Program Files\LLVM\bin\lld.exe
lld-link 7.1.0 C:\Program Files\LLVM\bin\lld-link.exe
lldb unknown C:\Users\Administrator\AppData\Local\Android\Sdk\ndk\25.2.9519653\toolchains\llvm\prebuilt\windows-x86_64\bin\lldb.exe
lldb-server not found
----------------------------rust----------------------------
rustup 1.26.0 C:\Users\Administrator\.cargo\bin\rustup.exe
cargo 1.74.0 C:\Users\Administrator\.cargo\bin\cargo.exe
--------------------------android---------------------------
C:\Users\Administrator\AppData\Local\Android\Sdk\platform-tools\adb.exe
C:\Program Files\BellSoft\LibericaJDK-17-Full\bin\javac.exe
java 17.0.7 C:\Program Files\BellSoft\LibericaJDK-17-Full\bin\java.exe
kotlin unknown C:\tools\kotlin-compiler-1.9.21\kotlinc\bin\kotlin.bat
gradle unknown C:\tools\gradle-8.3\bin\gradle.bat
----------------------------ios-----------------------------
idevice_id not found
ideviceinfo not found
ideviceinstaller not found
ideviceimagemounter not found
idevicedebug not found
idevicedebugserverproxy not found
---------------------------linux----------------------------
mksquashfs not found
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. in my point of view the issue is the same but maybe with different results.
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. So the issue is different from yours. It seems like your case is caused by another dependency that you use; I suggest creating a repository with a minimal setup that reproduces the issue.
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. let me know if it's unrelated to this issue i'll open a new one.
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: https://github.com/rust-windowing/glutin/issues/1644
Any ideas on how to proceed?