Skip to content

Commit 4f38afb

Browse files
authored
Android Documentation Improvements and other fixes (#15260)
1. Make Android doc more Dev focused / friendly (Quick Start Navigation , More Clear Pathfinding & Logical Flow for Devs) 3. Update links to be relevant in Android sections 4. Fix the broken vulkan & coreML links from Android & iOS flow 5. Fix navigation related issues ### Summary [PLEASE REMOVE] See [CONTRIBUTING.md's Pull Requests](https://github.com/pytorch/executorch/blob/main/CONTRIBUTING.md#pull-requests) for ExecuTorch PR guidelines. [PLEASE REMOVE] If this PR closes an issue, please add a `Fixes #<issue-id>` line. [PLEASE REMOVE] If this PR introduces a fix or feature that should be the upcoming release notes, please add a "Release notes: <area>" label. For a list of available release notes labels, check out [CONTRIBUTING.md's Pull Requests](https://github.com/pytorch/executorch/blob/main/CONTRIBUTING.md#pull-requests). ### Test plan [PLEASE REMOVE] How did you test this PR? Please write down any manual commands you used and note down tests that you have written if applicable.
1 parent f80916e commit 4f38afb

File tree

7 files changed

+113
-79
lines changed

7 files changed

+113
-79
lines changed

docs/source/android-examples.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Examples & Demos
22

3-
- [Working with LLMs - Android Examples](https://github.com/meta-pytorch/executorch-examples/tree/main/llm/android)
4-
- [Demo Apps](https://github.com/meta-pytorch/executorch-examples/tree/main/dl3/android/DeepLabV3Demo#executorch-android-demo-app)
3+
- [Working with LLMs - Android Examples](https://github.com/meta-pytorch/executorch-examples/blob/main/llm/android/LlamaDemo/README.md) - ExecuTorch Llama Android Demo App
4+
- [Demo Apps](https://github.com/meta-pytorch/executorch-examples/tree/main/dl3/android/DeepLabV3Demo#executorch-android-demo-app) - DeepLab v3 model for image segmentation
55
- {doc}`tutorial-arm-vgf` — Export a simple PyTorch model for the ExecuTorch VGF backend
66

77
```{toctree}

docs/source/android-vulkan.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
```{include} backends-vulkan.md
1+
```{include} backends/vulkan/vulkan-overview.md

docs/source/backends/coreml/coreml-overview.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Core ML delegate is the ExecuTorch solution to take advantage of Apple's [Core M
1010
## Target Requirements
1111

1212
Below are the minimum OS requirements on various hardware for running a Core ML-delegated ExecuTorch model:
13+
1314
- [macOS](https://developer.apple.com/macos) >= 13.0
1415
- [iOS](https://developer.apple.com/ios/) >= 16.0
1516
- [iPadOS](https://developer.apple.com/ipados/) >= 16.0
@@ -61,7 +62,6 @@ See [Partitioner API](coreml-partitioner.md) for a reference on available partit
6162

6263
The Core ML delegate can also be used as a backend to execute quantized models. See [Core ML Quantization](coreml-quantization.md) for more information on available quantization schemes and APIs.
6364

64-
6565
## Backward compatibility
6666

6767
Core ML supports backward compatibility via the [`minimum_deployment_target`](coreml-partitioner.md#coreml-compilespec) option. A model exported with a specific deployment target is guaranteed to work on all deployment targets >= the specified deployment target. For example, a model exported with `coremltools.target.iOS17` will work on iOS 17 or higher.
@@ -91,16 +91,15 @@ target_link_libraries(
9191

9292
No additional steps are necessary to use the backend beyond linking the target. A Core ML-delegated .pte file will automatically run on the registered backend.
9393

94-
9594
## Reference
9695

97-
**→{doc}`coreml-troubleshooting` — Debug common issues.**
96+
**→{doc}`/backends/coreml/coreml-troubleshooting` — Debug common issues.**
9897

99-
**→{doc}`coreml-partitioner` — Partitioner options.**
98+
**→{doc}`/backends/coreml/coreml-partitioner` — Partitioner options.**
10099

101-
**→{doc}`coreml-quantization` — Supported quantization schemes.**
100+
**→{doc}`/backends/coreml/coreml-quantization` — Supported quantization schemes.**
102101

103-
**→{doc}`coreml-op-support` — Supported operators.**
102+
**→{doc}`/backends/coreml/coreml-op-support` — Supported operators.**
104103

105104
```{toctree}
106105
:maxdepth: 2

docs/source/backends/vulkan/vulkan-overview.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ Any Vulkan-delegated .pte file will automatically run on the registered backend.
144144

145145
## Additional Resources
146146

147-
**→{doc}`vulkan-partitioner`**
147+
**→{doc}`/backends/vulkan/vulkan-partitioner`**
148148

149-
**→{doc}`vulkan-quantization`**
149+
**→{doc}`/backends/vulkan/vulkan-quantization`**
150150

151-
**→{doc}`vulkan-troubleshooting`**
151+
**→{doc}`/backends/vulkan/vulkan-troubleshooting`**
152152

153153
```{toctree}
154154
:maxdepth: 2

docs/source/edge-platforms-section.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Key features:
5959
## Next Steps
6060

6161
After choosing your platform:
62+
6263
- **{doc}`backends-section`** - Deep dive into backend selection and optimization
6364
- **{doc}`llm/working-with-llms`** - Working with Large Language Models on edge devices
6465

docs/source/using-executorch-android.md

Lines changed: 99 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1+
12
# Using ExecuTorch on Android
23

3-
To use from Android, ExecuTorch provides Java/Kotlin API bindings and Android platform integration, available as an AAR file.
4+
🚀 Quick Start: __New to ExecuTorch__ ? Jump to [Using AAR from Maven Central](#using-aar-from-maven-central) for the fastest setup, then see the [Runtime Integration](#runtime-integration) example.
45

5-
Note: This page covers Android app integration through the AAR library. The ExecuTorch C++ APIs can also be used from Android native, and the documentation can be found on [this page about cross compilation](using-executorch-building-from-source.md#cross-compilation).
6+
To use from Android, ExecuTorch provides Java/Kotlin API bindings and Android platform integration, available as an AAR file.
7+
Note: This page covers Android app integration through the AAR library. The ExecuTorch C++ APIs can also be used from Android native, and the documentation can be found on this page about cross compilation.
68

79
## Installation
810

9-
All ExecuTorch Android libraries are packaged into an [Android library (AAR)](https://developer.android.com/studio/projects/android-library), `executorch.aar` for both generic (image/audio processing) and LLM (LLaMA) use case. In each release, prebuilt AAR artifacts are uploaded to [Maven](https://repo.maven.apache.org/maven2/org/pytorch/executorch-android/) and S3. Users can also build the AAR from source.
11+
__Choose your installation method:__
12+
13+
- __[Maven Central](#using-aar-from-maven-central)__ (recommended): Easiest for most developers
14+
- __[Direct AAR file](#using-aar-file-directly)__: For specific versions or offline development
15+
- __[Build from source](#building-from-source)__: For custom backends or contributions
16+
17+
All ExecuTorch Android libraries are packaged into an Android library (AAR), executorch.aar for both generic (image/audio processing) and LLM (LLaMA) use case. In each release, prebuilt AAR artifacts are uploaded to Maven and S3. Users can also build the AAR from source.
1018

1119
### Contents of library
1220

1321
The AAR artifact contains the Java library for users to integrate with their Java/Kotlin application code, as well as the corresponding JNI library (.so file), which is loaded by the Java code during initialization.
1422

1523
- [Java library](https://github.com/pytorch/executorch/tree/main/extension/android/executorch_android/src/main/java/org/pytorch/executorch)
1624
- JNI contains the JNI binding for the corresponding Java code, and ExecuTorch native library, including
17-
- core ExecuTorch runtime libraries
25+
- Core ExecuTorch runtime libraries
1826
- XNNPACK backend
1927
- Portable kernels
2028
- Optimized kernels
@@ -24,42 +32,52 @@ The AAR artifact contains the Java library for users to integrate with their Jav
2432

2533
The AAR library can be used for generic Android device with arm64-v8a or x86_64 architecture. It can be used across form factors, including phones, tablets, tv boxes, etc, as it does not contain any UI components.
2634

27-
## Using AAR from Maven Central
35+
XNNPACK backend
2836

29-
ExecuTorch is available on [Maven Central](https://mvnrepository.com/artifact/org.pytorch/executorch-android).
37+
Portable kernels
38+
Optimized kernels
39+
Quantized kernels
40+
LLaMa-specific Custom ops library.
41+
Comes with two ABI variants, arm64-v8a and x86_64.
42+
The AAR library can be used for generic Android device with arm64-v8a or x86_64 architecture. It can be used across form factors, including phones, tablets, tv boxes, etc, as it does not contain any UI components.
3043

31-
Simply add the target [`org.pytorch:executorch-android:${executorch_version}`](https://repo.maven.apache.org/maven2/org/pytorch/executorch-android/${executorch_version}/) to your Android app dependency (build.gradle), and build your app.
44+
## Using AAR from Maven Central
3245

33-
For example:
34-
```
35-
# app/build.gradle.kts
46+
✅ Recommended for most developers
47+
ExecuTorch is available on Maven Central.
48+
Simply add the target org.pytorch:executorch-android:${executorch_version} to your Android app dependency (build.gradle), and build your app. For example:
49+
50+
```kotlin
51+
app/build.gradle.kts
3652
dependencies {
37-
implementation("org.pytorch:executorch-android:${executorch_version}")
53+
implementation("org.pytorch:executorch-android:${executorch_version}")
3854
}
3955
```
4056

41-
Note: If you want to use release v0.5.0, please use dependency `org.pytorch:executorch-android:0.5.1`.
42-
43-
Click the screenshot below to watch the *demo video* on how to add the package and run a simple ExecuTorch model with Android Studio.
57+
Note: If you want to use release v1.0.0, please use dependency org.pytorch:executorch-android:1.0.0.
58+
Click the screenshot below to watch the demo video on how to add the package and run a simple ExecuTorch model with Android Studio.
4459
<a href="_static/img/android_studio.mp4">
45-
<img src="_static/img/android_studio.jpeg" width="800" alt="Integrating and Running ExecuTorch on Android">
60+
<img src="_static/img/android_studio.jpeg" width="800" alt="Integrating and Running ExecuTorch on Android">
4661
</a>
4762

4863
## Using AAR file directly
4964

5065
You can also directly specify an AAR file in the app. We upload pre-built AAR to S3 during each release, or as a snapshot.
5166

52-
### Released versions (recommended)
67+
### Released versions (Recommended)
5368

5469
| Version | AAR | SHASUMS |
5570
| ------- | --- | ------- |
56-
| [${executorch_version}](https://github.com/pytorch/executorch/releases/tag/${executorch_version}) | [executorch.aar](https://ossci-android.s3.amazonaws.com/executorch/release/${executorch_version}/executorch.aar) | [executorch.aar.sha256sums](https://ossci-android.s3.amazonaws.com/executorch/release/${executorch_version}/executorch.aar.sha256sums) |
71+
| [v1.0.0](https://github.com/pytorch/executorch/releases/tag/v1.0.0) | [executorch.aar](https://ossci-android.s3.amazonaws.com/executorch/release/v1.0.0/executorch.aar) | [executorch.aar.sha256sums](https://ossci-android.s3.amazonaws.com/executorch/release/v1.0.0/executorch.aar.sha256sums) |
72+
| [v0.7.0](https://github.com/pytorch/executorch/releases/tag/v0.7.0) | [executorch.aar](https://ossci-android.s3.amazonaws.com/executorch/release/v0.7.0/executorch.aar) | [executorch.aar.sha256sums](https://ossci-android.s3.amazonaws.com/executorch/release/v0.7.0/executorch.aar.sha256sums) |
5773
| [v0.6.0](https://github.com/pytorch/executorch/releases/tag/v0.6.0) | [executorch.aar](https://ossci-android.s3.amazonaws.com/executorch/release/v0.6.0/executorch.aar) | [executorch.aar.sha256sums](https://ossci-android.s3.amazonaws.com/executorch/release/v0.6.0/executorch.aar.sha256sums) |
5874
| [v0.5.0](https://github.com/pytorch/executorch/releases/tag/v0.5.0) | [executorch.aar](https://ossci-android.s3.amazonaws.com/executorch/release/v0.5.0-rc3/executorch.aar) | [executorch.aar.sha256sums](https://ossci-android.s3.amazonaws.com/executorch/release/v0.5.0-rc3/executorch.aar.sha256sums) |
5975

76+
6077
### Snapshots from main branch
6178

6279
Starting from 2025-04-12, you can download nightly `main` branch snapshots:
80+
6381
* `executorch.aar`: `https://ossci-android.s3.amazonaws.com/executorch/release/snapshot-{YYYYMMDD}/executorch.aar`
6482
* `executorch.aar.sha256sums`: `https://ossci-android.s3.amazonaws.com/executorch/release/snapshot-{YYYYMMDD}/executorch.aar.sha256sums`
6583
* Replace `YYYYMMDD` with the actual date you want to use.
@@ -77,83 +95,95 @@ We aim to make every daily snapshot available and usable. However, for best stab
7795
## Using AAR file
7896

7997
To add the AAR file to your app:
80-
1. Download the AAR.
81-
2. Add it to your gradle build rule as a file path.
98+
Download the AAR.
99+
Add it to your gradle build rule as a file path.
100+
An AAR file itself does not contain dependency info, unlike the Maven one which bundled with pom.xml. The Java package requires fbjni and soloader, and currently requires users to explicitly declare the dependency. Therefore, two more dependencies in gradle rule is required:
82101

83-
An AAR file itself does not contain dependency info, unlike the Maven one which bundled with pom.xml. The Java package requires `fbjni` and `soloader`, and currently requires users to explicitly declare the dependency. Therefore, two more `dependencies` in gradle rule is required:
84-
```
102+
```kotlin
85103
implementation("com.facebook.soloader:soloader:0.10.5")
86104
implementation("com.facebook.fbjni:fbjni:0.7.0")
87105
```
88106

89107
### Example usage
90108

91109
In your app working directory, such as executorch-examples/llm/android/LlamaDemo,
92-
```
110+
111+
```sh
93112
mkdir -p app/libs
94113
curl https://ossci-android.s3.amazonaws.com/executorch/release/${executorch_version}/executorch.aar -o app/libs/executorch.aar
95114
```
96115

97116
And include it in gradle:
98-
```
99-
# app/build.gradle.kts
117+
118+
```kotlin
119+
app/build.gradle.kts
100120
dependencies {
101-
implementation(files("libs/executorch.aar"))
102-
implementation("com.facebook.soloader:soloader:0.10.5")
103-
implementation("com.facebook.fbjni:fbjni:0.7.0")
121+
implementation(files("libs/executorch.aar"))
122+
implementation("com.facebook.soloader:soloader:0.10.5")
123+
implementation("com.facebook.fbjni:fbjni:0.7.0")
104124
}
105125
```
106126

107127
Now you can compile your app with the ExecuTorch Android library.
108128

109129
## Building from Source
110130

111-
`scripts/build_android_library.sh` is a helper script to build the Java library (into .jar), native library (into .so), and the packaged AAR file.
112-
113-
You need Android [SDK](https://developer.android.com/studio) and [NDK](https://developer.android.com/ndk/downloads) to use it.
131+
```text
132+
scripts/build_android_library.sh
133+
```
114134

135+
is a helper script to build the Java library (into .jar), native library (into .so), and the packaged AAR file.
136+
You need Android SDK and NDK to use it.
115137
Current NDK version used in ExecuTorch CI: r28c.
138+
You need to set ANDROID_HOME to Android SDK home and ANDROID_NDK to the correct NDK root (containing NOTICE file).
116139

117-
You need to set `ANDROID_HOME` to Android SDK home and `ANDROID_NDK` to the correct NDK root (containing NOTICE file).
118-
119-
```
140+
```sh
120141
export ANDROID_HOME=/path/to/sdk
121142
export ANDROID_NDK=/path/to/ndk
122143
sh scripts/build_android_library.sh
123144
```
124145

125-
Currently, XNNPACK backend is always built with the script.
146+
NOTE: Currently, XNNPACK backend is always built with the script.
126147

127148
### Optional environment variables
128149

129-
Optionally, set these environment variables before running `build_android_library.sh`.
150+
Optionally, set these environment variables before running build_android_library.sh.
130151

131-
#### ANDROID_ABIS
132-
Set environment variable `ANDROID_ABIS` to either `arm64-v8a` or `x86_64` if you only need to build the native library for one ABI only.
133-
```
152+
- __ANDROID_ABIS__
153+
154+
Set environment variable ANDROID_ABIS to either arm64-v8a or x86_64 if you only need to build the native library for one ABI only.
155+
156+
```sh
134157
export ANDROID_ABIS=arm64-v8a
135-
# or
136-
# export ANDROID_ABIS=x86_64
158+
```
159+
160+
(Or)
161+
162+
```sh
163+
export ANDROID_ABIS=x86_64
164+
```
165+
166+
And then run the script.
167+
168+
```sh
137169
sh scripts/build_android_library.sh
138170
```
139171

140-
#### EXECUTORCH_CMAKE_BUILD_TYPE
141-
Set environment variable `EXECUTORCH_CMAKE_BUILD_TYPE` to `Release` or `Debug` based on your needs.
172+
- __EXECUTORCH_CMAKE_BUILD_TYPE__
173+
174+
Set environment variable EXECUTORCH_CMAKE_BUILD_TYPE to Release or Debug based on your needs.
142175

143-
#### Using MediaTek backend
176+
- __Using MediaTek backend__
144177

145-
To use [MediaTek backend](backends-mediatek.md),
146-
after installing and setting up the SDK, set `NEURON_BUFFER_ALLOCATOR_LIB` and `NEURON_USDK_ADAPTER_LIB` to the corresponding path.
178+
To use MediaTek backend, after installing and setting up the SDK, set NEURON_BUFFER_ALLOCATOR_LIB and NEURON_USDK_ADAPTER_LIB to the corresponding path.
147179

148-
#### Using Qualcomm AI Engine Backend
180+
- __Using Qualcomm AI Engine Backend__
149181

150-
To use [Qualcomm AI Engine Backend](backends-qualcomm.md#qualcomm-ai-engine-backend),
151-
after installing and setting up the SDK, set `QNN_SDK_ROOT` to the corresponding path.
182+
To use Qualcomm AI Engine Backend, after installing and setting up the SDK, set QNN_SDK_ROOT to the corresponding path.
152183

153-
#### Using Vulkan Backend
184+
- __Using Vulkan Backend__
154185

155-
To use [Vulkan Backend](backends-vulkan.md#vulkan-backend),
156-
set `EXECUTORCH_BUILD_VULKAN` to `ON`.
186+
To use Vulkan Backend, set EXECUTORCH_BUILD_VULKAN to ON.
157187

158188
## Android Backends
159189

@@ -166,6 +196,7 @@ The following backends are available for Android:
166196
| [Qualcomm AI Engine](https://www.qualcomm.com/developer/software/qualcomm-ai-engine-direct-sdk) | NPU | [Doc](backends-qualcomm.md) |
167197
| [Vulkan](https://www.vulkan.org/) | GPU | [Doc](backends-vulkan.md) |
168198

199+
Start with XNNPACK (CPU backend) for maximum compatibility, then add hardware-specific backends for optimization.
169200

170201
## Runtime Integration
171202

@@ -175,26 +206,27 @@ Here is an example code sample in Java that demonstrates how to integrate ExecuT
175206
import org.pytorch.executorch.EValue;
176207
import org.pytorch.executorch.Module;
177208
import org.pytorch.executorch.Tensor;
178-
179209
public class MainActivity extends Activity {
180-
private Module module;
181-
182-
@Override
183-
protected void onCreate(Bundle savedInstanceState) {
184-
super.onCreate(savedInstanceState);
185-
// Load the ExecuTorch module
186-
Module module = Module.load("/data/local/tmp/add.pte");
187-
Tensor tensor1 = Tensor.fromBlob(new float[] {1.0f}, new long[] {1});
188-
Tensor tensor2 = Tensor.fromBlob(new float[] {20.0f}, new long[] {1});
189-
190-
EValue eValue1 = EValue.from(tensor1);
191-
EValue eValue2 = EValue.from(tensor2);
192-
float result = module.forward(eValue1, eValue2)[0].toTensor().getDataAsFloatArray()[0];
193-
}
210+
private Module module;
211+
212+
@Override
213+
protected void onCreate(Bundle savedInstanceState) {
214+
super.onCreate(savedInstanceState);
215+
// Load the ExecuTorch module
216+
Module module = Module.load("/data/local/tmp/add.pte");
217+
218+
Tensor tensor1 = Tensor.fromBlob(new float[] {1.0f}, new long[] {1});
219+
Tensor tensor2 = Tensor.fromBlob(new float[] {20.0f}, new long[] {1});
220+
221+
EValue eValue1 = EValue.from(tensor1);
222+
EValue eValue2 = EValue.from(tensor2);
223+
224+
float result = module.forward(eValue1, eValue2)[0].toTensor().getDataAsFloatArray()[0];
194225
}
195226
```
196227

197-
Push the corresponding pte file to the phone:
228+
Push the corresponding pte file to your Android device:
229+
198230
```sh
199231
adb push extension/module/test/resources/add.pte /data/local/tmp/
200232
```

docs/source/using-executorch-building-from-source.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Even if you don't use CMake directly, CMake can emit scripts for other format
55
like Make, Ninja or Xcode. For information, see [cmake-generators(7)](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html).
66

77
## System Requirements
8+
89
### Operating System
910

1011
ExecuTorch is tested on the following systems, although it should also work in similar environments.
@@ -20,6 +21,7 @@ ExecuTorch is tested on the following systems, although it should also work in s
2021
* Windows 10+ with Visual Studio 2022+ (experimental)
2122

2223
### Software Requirements
24+
2325
* `conda` or another virtual environment manager
2426
- `conda` is recommended as it provides cross-language
2527
support and integrates smoothly with `pip` (Python's built-in package manager)

0 commit comments

Comments
 (0)