-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(android): model size display, download speed, cached indicator, and Termux build guide #1083
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
Open
sigsegv0x0b
wants to merge
2
commits into
qualcomm:main
Choose a base branch
from
sigsegv0x0b:androidExampleImporovemnets
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| # Building on Termux (aarch64) | ||
|
|
||
| Termux provides a full Linux environment on Android — you can clone, edit, | ||
| compile, and sideload APKs entirely on-device without a desktop machine. | ||
| This guide covers the extra steps needed to build the GenieX Android demo on | ||
| aarch64 Termux, where the standard Android build toolchain has pitfalls. | ||
|
|
||
| ## Why build on Termux? | ||
|
|
||
| - **No desktop required** — develop and build directly on your phone or tablet. | ||
| - **Faster iteration** — edit a Kotlin file, `gradlew assembleDebug`, install | ||
| the APK, run it. All on the same device. | ||
| - **Keep everything on-device** — models, SDK, and source all live under one | ||
| filesystem; no adb push/pull dance. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| ### Packages | ||
|
|
||
| ``` | ||
| pkg install openjdk-21 gradle aapt2 | ||
| ``` | ||
|
|
||
| You also need `git` (usually pre-installed) and `python3` for scripting. | ||
|
|
||
| ### Android SDK | ||
|
|
||
| Install the Android SDK at `$HOME/android-sdk`. The easiest path is | ||
| `cmdline-tools` + `sdkmanager`: | ||
|
|
||
| ```bash | ||
| mkdir -p ~/android-sdk/cmdline-tools | ||
| # Download latest command-line tools from developer.android.com | ||
| # Extract into ~/android-sdk/cmdline-tools/latest/ | ||
| export ANDROID_HOME=$HOME/android-sdk | ||
| ~/android-sdk/cmdline-tools/latest/bin/sdkmanager --install \ | ||
| "platforms;android-34" \ | ||
| "platforms;android-35" \ | ||
| "platforms;android-36" \ | ||
| "build-tools;34.0.0" \ | ||
| "build-tools;34.0.4" \ | ||
| "build-tools;35.0.1" \ | ||
| "build-tools;36.0.0" | ||
| ``` | ||
|
|
||
| Exact contents of `$HOME/android-sdk/build-tools/` after setup: | ||
|
|
||
| ``` | ||
| 34.0.0/ 34.0.4/ 35.0.0/ 35.0.1/ 36.0.0/ | ||
| ``` | ||
|
|
||
| And `$HOME/android-sdk/platforms/`: | ||
|
|
||
| ``` | ||
| android-33/ android-34/ android-35/ android-36/ | ||
| ``` | ||
|
|
||
| ## Workarounds | ||
|
|
||
| Three things must be changed for the build to succeed on aarch64 Termux. | ||
|
|
||
| ### 1. local.properties | ||
|
|
||
| Create `local.properties` pointing at the SDK: | ||
|
|
||
| ```properties | ||
| sdk.dir=/data/data/com.termux/files/home/android-sdk | ||
| ``` | ||
|
|
||
| > **Never commit this file.** It is already in `.gitignore`. | ||
|
|
||
| ### 2. aapt2 override (gradle.properties) | ||
|
|
||
| The aarch64 aapt2 binary shipped with build-tools older than 34.x **cannot | ||
| load platform JARs >= 35**. AGP also bundles an x86_64 aapt2 that won't run | ||
| on aarch64. The fix is to tell Gradle to use the build-tools 34.0.4 aapt2, | ||
| which is aarch64-native: | ||
|
|
||
| ```properties | ||
| android.aapt2FromMavenOverride=/data/data/com.termux/files/home/android-sdk/build-tools/34.0.4/aapt2 | ||
| ``` | ||
|
|
||
| The system `aapt2` from `pkg install aapt2` also works and is sometimes | ||
| newer — if your build fails during resource linking, try swapping. | ||
|
|
||
| ### 3. compileSdk must be 34 | ||
|
|
||
| Because of the aapt2 limitation above, `compileSdk` and `targetSdk` in | ||
| `build.gradle` must be 34: | ||
|
|
||
| ```groovy | ||
| ANDROID_COMPILE_API = 34 | ||
| ANDROID_TARGET_API = 34 | ||
| ``` | ||
|
|
||
| > With compileSdk 35 or higher, processDebugResources fails with: | ||
| > `AAPT: error: failed to load include path .../android-35/android.jar` | ||
|
|
||
| ### 4. NDK version | ||
|
|
||
| The `build.gradle` declares `ANDROID_NDK_VERSION = '29.0.14206865'`, but | ||
| the example has **no native code** — AGP skips the NDK entirely. If you | ||
| later add C/C++ code, install the matching NDK: | ||
|
|
||
| ```bash | ||
| sdkmanager --install "ndk;29.0.14206865" | ||
| ``` | ||
|
|
||
| ## Build | ||
|
|
||
| ```bash | ||
| cd examples/android | ||
| ANDROID_HOME=$HOME/android-sdk ./gradlew assembleDebug | ||
| ``` | ||
|
|
||
| First build downloads Gradle 9.1.0 and all dependencies — ~2-3 minutes on | ||
| a warm cache, longer on first run. | ||
|
|
||
| APK output: `build/outputs/apk/debug/app-debug.apk` | ||
|
|
||
| ### Incremental rebuilds | ||
|
|
||
| ```bash | ||
| ./gradlew assembleDebug | ||
| ``` | ||
|
|
||
| ### Clean rebuild (if you switch aapt2 or compileSdk) | ||
|
|
||
| ```bash | ||
| rm -rf ~/.gradle/caches/*/transforms/*aapt* | ||
| ./gradlew assembleDebug --no-build-cache | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| | Symptom | Fix | | ||
| |---|---| | ||
| | `AAPT: error: failed to load include path .../android-35/android.jar` | Set compileSdk to 34 in `build.gradle` | | ||
| | `java.lang.UnsatisfiedLinkError` for aapt2 | Check `android.aapt2FromMavenOverride` points to the aarch64 aapt2 | | ||
| | Gradle can't find SDK | Create `local.properties` with correct `sdk.dir` | | ||
| | NDK not found | Remove or update `ANDROID_NDK_VERSION` in `build.gradle` (no native code = not needed) | | ||
| | Out of memory during dex | Reduce `-Xmx` in `gradle.properties` or close other apps | | ||
|
|
||
| ## Installing the APK | ||
|
|
||
| ```bash | ||
| # If you have the APK on the same device: | ||
| termux-open build/outputs/apk/debug/app-debug.apk | ||
|
|
||
| # Or from adb (if you have a second device / PC): | ||
| adb install build/outputs/apk/debug/app-debug.apk | ||
| ``` | ||
|
|
||
| ## Reference | ||
|
|
||
| - [browseragent TERMUX.md](https://github.com/sigsegv0x0b/browseragent) — | ||
| similar aarch64 build setup, originally solved many of these issues. | ||
| - [Android SDK CLI tools](https://developer.android.com/studio#command-line-tools-only) — | ||
| official download page. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| org.gradle.jvmargs=-Xmx4G -Dfile.encoding=UTF-8 | ||
| android.useAndroidX=true | ||
| android.nonTransitiveRClass=true | ||
| android.aapt2FromMavenOverride=/data/data/com.termux/files/home/android-sdk/build-tools/34.0.4/aapt2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
model manager api provided size info, so we do not need hard code size anymore