flapigen-rs
flapigen-rs copied to clipboard
Can't compile android-example
I found this page https://dushistov.github.io/rust_swig/java-android-example.html and decided to try it.
Here is my installed Rust targets:
$ rustup show | grep android
aarch64-linux-android
arm-linux-androideabi
armv7-linux-androideabi
i686-linux-android
x86_64-linux-android
I added $CLANG_HOME to my $PATH:
$ ls -lah $CLANG_HOME/bin
-rwxr-xr-x. 1 root root 356K Jul 10 2018 bugpoint
-rwxr-xr-x. 1 root root 165K Jul 10 2018 c-index-test
lrwxrwxrwx. 1 root root 9 Jun 17 19:45 clang -> clang-5.0
lrwxrwxrwx. 1 root root 5 Jun 17 19:45 clang++ -> clang
# etc.
$ clang++ --version
clang version 5.0.1 (tags/RELEASE_501/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/rh/llvm-toolset-7/root/usr/bin
Then I try to invoke gradlew:
$ ./gradlew androidRelease
Task 'androidRelease' not found in root project 'android-example'.
Task assembleRelease is present, however. I run it and some time compilation is being performed.
It ends with the following error:
error: linker
aarch64-linux-android21-clang++not found
I open .cargo/config and replace both linkers with just clang++ (it's the only executable with this substring in my $CLANG_HOME/bin).
This time it fails with this error:
9nktu39b-cgu.0.rcgu.o: Relocations in generic ELF (EM: 183) /home/kirill/Code/rust_swig2/android-example/target/aarch64-linux-android/release/deps/mobcore.mobcore.9nktu39b-cgu.0.rcgu.o: error adding symbols: File in wrong format clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
How can I compile the project? Do I need specific version of clang or anything else?
clang for PC is useless in this case. You need clang from Android/NDK with exactly this name aarch64-linux-android21-clang++ if want compile for Android/arm64 bit CPU. See https://developer.android.com/ndk/guides to find out how to install Android/NDK
@Dushistov yeah, I just figured it out. Sorry, I have experience with Rust but not with Android. Right now I built the project with NDK clang and I see this APK:
./app/build/outputs/apk/release/app-release-unsigned.apk
But I can't install it with adb install:
adb: failed to install ./app/build/outputs/apk/release/app-release-unsigned.apk: Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES: Package /data/app/vmdl1604027349.tmp/base.apk has no certificates at entry AndroidManifest.xml]
And I don't succeed with run-on-android.sh as well:
$ ./run-on-android.sh ./app/build/outputs/apk/release/app-release-unsigned.apk
./app/build/outputs/apk/release/app-release-unsigned.apk: 1 file pushed. 5.6 MB/s (6834559 bytes in 1.163s)
/data/local/tmp/app-release-unsigned.apk[1]: syntax error: '(' unexpected
What should I do in order to test this example?
It is really hard to tell what is wrong, may be you don't activate "developer mode" on phone, there are several possible sources of problem: https://stackoverflow.com/questions/2914105/what-is-install-parse-failed-no-certificates-error/10083280
This is an emulated phone actually. With normal C++ app it works.
But why this APK is unsigned?
I finally got this to work on Arch Linux by using the following .cargo/config.
You can run: locate aarch64-linux-android21-clang++ etc.. to figure out where the prebuilt binaries are.
[target.aarch64-linux-android]
linker = "/home/username/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang++"
runner = "./run-on-android.sh"
[target.armv7-linux-androideabi]
linker = "/home/username/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang++"
runner = "./run-on-android.sh"
[target.x86_64-linux-android]
linker = "/home/username/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android21-clang++"
runner = "./run-on-android.sh"