You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
-[Demo Apps](https://github.com/meta-pytorch/executorch-examples/tree/main/dl3/android/DeepLabV3Demo#executorch-android-demo-app) - DeepLab v3 model for image segmentation
5
5
- {doc}`tutorial-arm-vgf` — Export a simple PyTorch model for the ExecuTorch VGF backend
@@ -61,7 +62,6 @@ See [Partitioner API](coreml-partitioner.md) for a reference on available partit
61
62
62
63
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.
63
64
64
-
65
65
## Backward compatibility
66
66
67
67
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(
91
91
92
92
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.
93
93
94
-
95
94
## Reference
96
95
97
-
**→{doc}`coreml-troubleshooting` — Debug common issues.**
96
+
**→{doc}`/backends/coreml/coreml-troubleshooting` — Debug common issues.**
Copy file name to clipboardExpand all lines: docs/source/using-executorch-android.md
+99-67Lines changed: 99 additions & 67 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,28 @@
1
+
1
2
# Using ExecuTorch on Android
2
3
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.
4
5
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.
6
8
7
9
## Installation
8
10
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.
10
18
11
19
### Contents of library
12
20
13
21
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.
- 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
18
26
- XNNPACK backend
19
27
- Portable kernels
20
28
- Optimized kernels
@@ -24,42 +32,52 @@ The AAR artifact contains the Java library for users to integrate with their Jav
24
32
25
33
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.
26
34
27
-
## Using AAR from Maven Central
35
+
XNNPACK backend
28
36
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.
30
43
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
32
45
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:
* 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
77
95
## Using AAR file
78
96
79
97
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:
82
101
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:
Now you can compile your app with the ExecuTorch Android library.
108
128
109
129
## Building from Source
110
130
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
+
```
114
134
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.
115
137
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).
116
139
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
120
141
export ANDROID_HOME=/path/to/sdk
121
142
export ANDROID_NDK=/path/to/ndk
122
143
sh scripts/build_android_library.sh
123
144
```
124
145
125
-
Currently, XNNPACK backend is always built with the script.
146
+
NOTE: Currently, XNNPACK backend is always built with the script.
126
147
127
148
### Optional environment variables
128
149
129
-
Optionally, set these environment variables before running `build_android_library.sh`.
150
+
Optionally, set these environment variables before running build_android_library.sh.
130
151
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
134
157
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
137
169
sh scripts/build_android_library.sh
138
170
```
139
171
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.
142
175
143
-
#### Using MediaTek backend
176
+
-__Using MediaTek backend__
144
177
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.
147
179
148
-
#### Using Qualcomm AI Engine Backend
180
+
-__Using Qualcomm AI Engine Backend__
149
181
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.
152
183
153
-
#### Using Vulkan Backend
184
+
-__Using Vulkan Backend__
154
185
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.
157
187
158
188
## Android Backends
159
189
@@ -166,6 +196,7 @@ The following backends are available for Android:
166
196
|[Qualcomm AI Engine](https://www.qualcomm.com/developer/software/qualcomm-ai-engine-direct-sdk)| NPU |[Doc](backends-qualcomm.md)|
0 commit comments