Build WasmEdge for Android

The WasmEdge Runtime releases come with pre-built binaries for the Android OS. Why WasmEdge on Android?

However, the WasmEdge installer does not support Android. The user must download the release files to a computer, and then use the adb tool to transfer the files to an Android device or simulator. We will show you how to do that.

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.

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

Add the Android NDK path into the environment variable.

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.

./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.

    $ adb devices
    List of devices attached
    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.

    cp -r examples build/tools/wasmedge/examples
    cd build
    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.
$ cd /data/local/tmp/wasmedge/examples
$ ../wasmedge hello.wasm 1 2 3
hello
1
2
3

$ ../wasmedge --reactor add.wasm add 2 2
4

$ ../wasmedge --reactor fibonacci.wasm fib 8
34

$ ../wasmedge --reactor factorial.wasm fac 12
479001600

$ cd js
$ ./../wasmedge --dir .:. qjs.wasm hello.js 1 2 3
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.