Build from source for Android platforms

Please follow this guide to build and test WasmEdge from source code with Android NDK.

In current state, we only support the runtime for the interpreter mode.

Prepare the Environment

We recommand developers to use our Docker images and follow the steps to prepare the building environment.

Build WasmEdge for Android platforms

Get the WasmEdge source code.

  1. git clone https://github.com/WasmEdge/WasmEdge.git
  2. cd WasmEdge

Add the Android NDK path into the environment variable.

  1. export ANDROID_NDK_HOME=path/to/you/ndk/dir

Run the build script in WasmEdge source code. This script will automatically build the WasmEdge for Android, and the results are in the build folder.

  1. ./utils/android/standalone/build_for_android.sh

Test the WasmEdge CLI on Android platforms

  1. Connect the device by using a USB cable or Wi-Fi. Then you can check the attached devices via the adb devices command.

    1. $ adb devices
    2. List of devices attached
    3. 0a388e93 device
  2. Use the adb push command to push the entire build/tools/wasmedge folder into the /data/local/tmp folder on your Android device.

    1. cp -r examples build/tools/wasmedge/examples
    2. cd build
    3. adb push ./tools/wasmedge /data/local/tmp

Run WasmEdge CLI on Android platforms

  1. Please use the adb shell command to access into the Android device.
  2. Follow the steps to test the WasmEdge CLI on the Android device.
  1. $ cd /data/local/tmp/wasmedge/examples
  2. $ ../wasmedge hello.wasm 1 2 3
  3. hello
  4. 1
  5. 2
  6. 3
  7. $ ../wasmedge --reactor add.wasm add 2 2
  8. 4
  9. $ ../wasmedge --reactor fibonacci.wasm fib 8
  10. 34
  11. $ ../wasmedge --reactor factorial.wasm fac 12
  12. 479001600
  13. $ cd js
  14. $ ./../wasmedge --dir .:. qjs.wasm hello.js 1 2 3
  15. Hello 1 2 3

Notice

  • For the Android 10 or greater versions, SELinux will disallow the untrusted applications’ exec() system call to execute the binaries in home or /data/local/tmp folder.
  • The Android SELinux policy will disallow the untrusted applications to access the /data/local/tmp folder.