Skip to content

Update LlamaDemo AAR build docs #10086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,31 @@ The Mediatek runner (`examples/mediatek/executor_runner/mtk_llama_runner.cpp`) c


## Build AAR Library
1. Open a terminal window and navigate to the root directory of the executorch
2. Set the following environment variables:
```sh
export ANDROID_NDK=<path_to_android_ndk>
export ANDROID_ABIS=arm64-v8a
export NEURON_BUFFER_ALLOCATOR_LIB=<path_to_neuron_buffer_allocator_lib>
```
*Note: <path_to_android_ndk> is the root for the NDK, which is usually under ~/Library/Android/sdk/ndk/XX.Y.ZZZZZ for macOS, and contains NOTICE and README.md. We use <path_to_android_ndk>/build/cmake/android.toolchain.cmake for CMake to cross-compile.*

Next we need to build and compile the MediaTek backend and MediaTek Llama runner. By setting `NEURON_BUFFER_ALLOCATOR_LIB`, the script will build the MediaTek backend.
3. Create a directory to hold the AAR
```sh
mkdir -p aar-out
export BUILD_AAR_DIR=aar-out
```

4. Run the following command to build the AAR:
```sh
sh scripts/build_android_library.sh
```

**Output**: This will generate an .aar file that is already imported into the expected directory for the Android app. It will live in `examples/demo-apps/android/Llamademo/app/libs`.
5. Copy the AAR to the app:
```sh
mkdir -p examples/demo-apps/android/LlamaDemo/app/libs
cp aar-out/executorch.aar examples/demo-apps/android/LlamaDemo/app/libs/executorch.aar
```

If you were to unzip the .aar file or open it in Android Studio, verify it contains the following related to MediaTek backend:
* libneuron_buffer_allocator.so
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,30 +178,38 @@ adb push tokenizer.bin /data/local/tmp/llama


## Build AAR Library
Open a terminal window and navigate to the root directory of the executorch.
1. Open a terminal window and navigate to the root directory of the executorch
Set the following environment variables:
```
```sh
export ANDROID_NDK=<path_to_android_ndk>
export ANDROID_ABI=arm64-v8a
```
Note: <path_to_android_ndk> is the root for the NDK, which is usually under ~/Library/Android/sdk/ndk/XX.Y.ZZZZZ for macOS, and contains NOTICE and README.md. We use <path_to_android_ndk>/build/cmake/android.toolchain.cmake for CMake to cross-compile.
Build the Android Java extension code:
export ANDROID_ABIS=arm64-v8a
export QNN_SDK_ROOT=<path_to_qnn_sdk>
```
pushd extension/android
./gradlew build
popd

*Note: <path_to_android_ndk> is the root for the NDK, which is usually under ~/Library/Android/sdk/ndk/XX.Y.ZZZZZ for macOS, and contains NOTICE and README.md. We use <path_to_android_ndk>/build/cmake/android.toolchain.cmake for CMake to cross-compile.*

3. Create a directory to hold the AAR
```sh
mkdir -p aar-out
export BUILD_AAR_DIR=aar-out
```
Run the following command set up the required JNI library:

4. Run the following command to build the AAR:
```sh
sh scripts/build_android_library.sh
```
pushd examples/demo-apps/android/LlamaDemo
./gradlew :app:setupQnn
popd

5. Copy the AAR to the app:
```sh
mkdir -p examples/demo-apps/android/LlamaDemo/app/libs
cp aar-out/executorch.aar examples/demo-apps/android/LlamaDemo/app/libs/executorch.aar
```

Alternative you can also just run the shell script directly as in the root directory:
```
```sh
sh examples/demo-apps/android/LlamaDemo/setup-with-qnn.sh
```
This is running the shell script which configures the required core ExecuTorch, Llama2/3, and Android libraries, builds them, and copies them to jniLibs.
This is running the shell script which configures the required core ExecuTorch, Llama2/3, and Android libraries, builds them into AAR, and copies it to the app.
Note: If you are building the Android app mentioned in the next section on a separate machine (i.e. MacOS but building and exporting for QNN backend on Linux), make sure you copy the aar file generated from setup-with-qnn script to “examples/demo-apps/android/LlamaDemo/app/libs” before building the Android app.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,30 +132,35 @@ adb push tokenizer.bin /data/local/tmp/llama
## Build AAR Library
1. Open a terminal window and navigate to the root directory of the executorch
2. Set the following environment variables:
```
```sh
export ANDROID_NDK=<path_to_android_ndk>
export ANDROID_ABI=arm64-v8a
export ANDROID_ABIS=arm64-v8a
```
*Note: <path_to_android_ndk> is the root for the NDK, which is usually under ~/Library/Android/sdk/ndk/XX.Y.ZZZZZ for macOS, and contains NOTICE and README.md. We use <path_to_android_ndk>/build/cmake/android.toolchain.cmake for CMake to cross-compile.*

3. Build the Android Java extension code:
```
pushd extension/android
./gradlew build
popd
3. Create a directory to hold the AAR
```sh
mkdir -p aar-out
export BUILD_AAR_DIR=aar-out
```
4. Run the following command set up the required JNI library:

4. Run the following command to build the AAR:
```sh
sh scripts/build_android_library.sh
```
pushd examples/demo-apps/android/LlamaDemo
./gradlew :app:setup
popd

5. Copy the AAR to the app:
```sh
mkdir -p examples/demo-apps/android/LlamaDemo/app/libs
cp aar-out/executorch.aar examples/demo-apps/android/LlamaDemo/app/libs/executorch.aar
```

Alternative you can also just run the shell script directly as in the root directory:
```
```sh
sh examples/demo-apps/android/LlamaDemo/setup.sh
```

This is running the shell script which configures the required core ExecuTorch, Llama2/3, and Android libraries, builds them, and copies them to jniLibs.
This is running the shell script which configures the required core ExecuTorch, Llama2/3, and Android libraries, builds them into AAR, and copies it to the app.

**Output**: The executorch.aar file will be generated in a newly created folder in the example/demo-apps/android/LlamaDemo/app/libs directory. This is the path that the Android app expects it to be in.

Expand Down
Loading