How to build a Andriod Apk with Rust

2024-01-05

It's no common to develop an Android with Rust. However, there are some wways and resource to help you reach this goal. I will show you the main steps to build a Android Apk with rust.

  • install opnejdk: sudo pacman -S jdk17-openjdk

  • set env for opnejdk: export JAVA_HOME=/usr/lib/jvm/java-17-openjdk

  • install Android Sdk and Ndk from developer.android

  • set evn from Sdk and Ndk: export ANDROID_HOME=/Path/to/Android/Sdk and export ANDROID_NDK_HOME=/Path/to/Android/Ndk

  • download examples from this github page

  • enter one of the examples and follow the README.md build step. Or follow the below command to build and install the Apk

    rustup target add aarch64-linux-android
    cargo install cargo-ndk
    
    cargo ndk -t arm64-v8a -o app/src/main/jniLibs/  build
    ./gradlew build
    ./gradlew installDebug
    adb shell am start -n co.realfit.naegui/.MainActivity
    
    

Reference