This project contains a Dockerfile to build the onnxruntime Android library. It is based on this image that contains all the prerequisites https://github.com/subparticles/onnxruntime-ci.
The build can take several minutes (30-90 minutes) to complete and the size of the produced image is almost 20 GB.
Example of build command:
docker build . -t onnxruntime_build:1.7.2-android-arm64
Create a container to extract the aar
id=$(docker create onnxruntime_build:1.7.2-android-arm64)
docker cp $id:/home/user/code/onnxruntime/build/Android/Debug/java/build/android/outputs/aar .
See below a copy of the Android build procedure taken from https://www.onnxruntime.ai/docs/how-to/build.html#android
The SDK and NDK packages can be installed via Android Studio or the sdkmanager command line tool. Android Studio is more convenient but a larger installation. The command line tools are smaller and usage can be scripted, but are a little more complicated to setup. They also require a Java runtime environment to be available.
Resources:
If necessary install the Java Runtime Environment and set the JAVA_HOME environment variable to point to it
For sdkmanager to work it needs a certain directory structure. First create the top level directory for the Android infrastructure.
.../Android/Download the command line tools from the ‘Command line tools only’ section towards the bottom of https://developer.android.com/studio
Create a directory called ‘cmdline-tools’ under your top level directory
.../Android/cmdline-toolsExtract the ‘tools’ directory from the command line tools zip file into this directory
giving .../Android/cmdline-tools/tools
Windows note: preferably extract using 7-zip. If using the built in Windows zip extract tool you will need to fix the directory structure by moving the jar files from
tools\lib\_
up to
tools\lib
You should now be able to run Android/cmdline-tools/bin/sdkmanager[.bat] successfully
Run .../Android/cmdline-tools/bin/sdkmanager --list to see the packages available
Install the SDK Platform
Generally installing the latest is fine. You pick an API level when compiling the code and the latest platform will support many recent API levels e.g.
sdkmanager --install "platforms;android-29"
This will install into the ‘platforms’ directory of our top level directory, the Android directory in our example
The SDK path to use as --android_sdk_path when building is this top level directory
Install the NDK
sdkmanager --listsdkmanager --install "ndk;21.1.6352462".../Android/ndk/21.1.6352462.../Android/ndk-bundle as there’s no version numberThe Ninja generator needs to be used to build on Windows as the Visual Studio generator doesn’t support Android.
./build.bat --android --android_sdk_path <android sdk path> --android_ndk_path <android ndk path> --android_abi <android abi, e.g., arm64-v8a (default) or armeabi-v7a> --android_api <android api level, e.g., 27 (default)> --cmake_generator Ninja
e.g. using the paths from our example
./build.bat --android --android_sdk_path .../Android --android_ndk_path .../Android/ndk/21.1.6352462 --android_abi arm64-v8a --android_api 27 --cmake_generator Ninja
./build.sh --android --android_sdk_path <android sdk path> --android_ndk_path <android ndk path> --android_abi <android abi, e.g., arm64-v8a (default) or armeabi-v7a> --android_api <android api level, e.g., 27 (default)>
Android Archive (AAR) files, which can be imported directly in Android Studio, will be generated in your_build_dir/java/build/outputs/aar, by using the above building commands with --build_java
To build on Windows with --build_java enabled you must also:
set JAVA_HOME to the path to your JDK install
$env:JAVA_HOME="C:\Program Files\Java\jdk-15" CMD: set JAVA_HOME=C:\Program Files\Java\jdk-15install
Gradle
and add the directory to the PATH
$env:PATH="$env:PATH;C:\Gradle\gradle-6.6.1\bin" CMD: set PATH=%PATH%;C:\Gradle\gradle-6.6.1\binrun the build from an admin window
If you want to use NNAPI Execution Provider on Android, see NNAPI Execution Provider.
Android NNAPI Execution Provider can be built using building commands in Android Build instructions with --use_nnapi
Content type
Image
Digest
Size
6.9 GB
Last updated
over 5 years ago
docker pull subparticles/onnxruntime-build