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.
- Download and extract the Android NDK 23b.
- Check the cmake for CMake 3.21 or greater version.
- Download and install the ADB platform tools.
- If you use the debian or ubuntu Linux distributions, you can install the ADB platform tools via
apt
.
- If you use the debian or ubuntu Linux distributions, you can install the ADB platform tools via
- An Android device which is enabled developer options and USB debugging and with at least Android 6.0 or higher system version.
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
Push the WasmEdge CLI and related test data onto Android platforms
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
Use the
adb push
command to push the entirebuild/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
- Please use the
adb shell
command to access into the Android device. - 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 inhome
or/data/local/tmp
folder. - The Android SELinux policy will disallow the untrusted applications to access the
/data/local/tmp
folder.