-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Patch manifest #4687
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
base: tauri
Are you sure you want to change the base?
Patch manifest #4687
Changes from 14 commits
fc31a5e
ae221c4
b6b31db
74a3266
983a9cf
c2163bd
0533869
a801f59
cadf39f
eb441f4
8c93e03
b1c3154
0a60f3e
2eb9aaa
cd6aa1f
2f2e9ab
e9c511e
3d13b6e
d71a7c1
04b8256
99642e8
aa9ddc8
8d87c20
37fb1b6
6d79317
a826b93
4a32b85
b85212b
792d918
735ac48
1d19205
9416e32
1331237
4435a99
bb84552
90cecf7
83122fc
7e03458
b7f391a
0a0bf83
62f9c41
05bc006
5ec9332
cb3680a
5f31190
a93186b
8e779cd
72173cf
56f041f
4dfd15e
c19e84c
bf62596
220037c
0e4c4c7
6dea4b3
7e5ce52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| name: Test Android Manifest Patch | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| test-patch: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@v5 | ||
| with: | ||
| node-version-file: '.nvmrc' | ||
| cache: 'yarn' | ||
|
|
||
| - name: Install dependencies | ||
| run: yarn install --frozen-lockfile | ||
|
|
||
| - name: Setup Java 21 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: 'temurin' | ||
| java-version: '21' | ||
|
|
||
| - name: Setup Android SDK | ||
| uses: android-actions/setup-android@v3 | ||
|
|
||
| - name: Install Rust | ||
| uses: dtolnay/rust-toolchain@stable | ||
|
|
||
| - name: Install Rust Android targets | ||
| run: | | ||
| rustup target add aarch64-linux-android | ||
| rustup target add armv7-linux-androideabi | ||
| rustup target add i686-linux-android | ||
| rustup target add x86_64-linux-android | ||
| - name: Build web assets (Vite) | ||
| run: yarn build | ||
|
|
||
| - name: Initialize Tauri Android project | ||
| run: yarn tauri android init --ci | ||
|
|
||
| - name: Show generated manifest BEFORE patch | ||
| run: | | ||
| echo "=== MANIFEST BEFORE PATCH ===" | ||
| cat src-tauri/gen/android/app/src/main/AndroidManifest.xml || echo "Manifest not found" | ||
| echo "" | ||
| echo "=== APP BUILD.GRADLE.KTS BEFORE PATCH ===" | ||
| cat src-tauri/gen/android/app/build.gradle.kts || echo "build.gradle.kts not found" | ||
| - name: Patch Android manifest for USB support | ||
| run: bash scripts/patch-android-manifest.sh | ||
|
|
||
| - name: Show files after patch | ||
| run: | | ||
| echo "=== AndroidManifest.xml AFTER patch ===" | ||
| cat src-tauri/gen/android/app/src/main/AndroidManifest.xml | ||
| echo "" | ||
| echo "=== Checking for USB permissions ===" | ||
| grep -i "usb" src-tauri/gen/android/app/src/main/AndroidManifest.xml || echo "No USB permissions found!" | ||
| echo "" | ||
| echo "=== device_filter.xml ===" | ||
| cat src-tauri/gen/android/app/src/main/res/xml/device_filter.xml || echo "device_filter.xml not found!" | ||
| echo "" | ||
| echo "=== MainActivity.kt ===" | ||
| cat src-tauri/gen/android/app/src/main/java/com/betaflight/configurator/MainActivity.kt || echo "MainActivity.kt not found!" | ||
| echo "" | ||
| echo "=== app/build.gradle.kts dependencies ===" | ||
| grep -A 10 "dependencies {" src-tauri/gen/android/app/build.gradle.kts || echo "No dependencies block found!" | ||
| - name: Ensure JitPack repository | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| FILE="src-tauri/gen/android/build.gradle.kts" | ||
| if [ -f "$FILE" ]; then | ||
| echo "=== ROOT BUILD.GRADLE.KTS BEFORE JITPACK ===" | ||
| cat "$FILE" | ||
| echo "" | ||
| echo "Ensuring JitPack repository in $FILE..." | ||
| if ! grep -q "jitpack.io" "$FILE"; then | ||
| echo "Adding JitPack repository..." | ||
| printf '\nallprojects {\n repositories {\n maven(url = "https://jitpack.io")\n }\n}\n' >> "$FILE" | ||
| fi | ||
| echo "" | ||
| echo "=== ROOT BUILD.GRADLE.KTS AFTER JITPACK ===" | ||
| cat "$FILE" | ||
| fi | ||
|
||
| - name: Upload generated Android files | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: android-generated-files | ||
| path: | | ||
| src-tauri/gen/android/app/src/main/AndroidManifest.xml | ||
| src-tauri/gen/android/app/src/main/res/xml/device_filter.xml | ||
| src-tauri/gen/android/app/build.gradle.kts | ||
| src-tauri/gen/android/build.gradle.kts | ||
| retention-days: 7 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # Android USB Serial Support | ||
|
|
||
| ## Current Status (v2.16.0) | ||
|
|
||
| The `tauri-plugin-serialplugin` version 2.16.0 includes Android support, but requires additional runtime permission handling to actually detect USB devices. | ||
|
|
||
| ## What's Working | ||
|
|
||
| ✅ **Build**: APK compiles successfully | ||
| ✅ **Manifest Permissions**: USB permissions are patched into AndroidManifest.xml | ||
| ✅ **Plugin**: Version 2.16.0 has Android Kotlin code | ||
| ✅ **Dependencies**: `usb-serial-for-android` library is added via Gradle | ||
| ✅ **Device Filter**: USB device VID/PID filter is created | ||
| ✅ **Intent Filter**: App launches when USB device is attached | ||
|
|
||
| ## Custom MainActivity | ||
|
|
||
| We've added a custom `MainActivity.kt` that handles USB permission requests properly: | ||
|
|
||
| ### What it does: | ||
| 1. **Registers USB broadcast receivers** for device attach/detach events | ||
| 2. **Automatically requests permission** when a USB device is detected | ||
| 3. **Checks for already connected devices** on app launch | ||
| 4. **Handles the permission dialog** and logs the result | ||
| 5. **Manages app lifecycle** (onCreate, onDestroy, onNewIntent) | ||
|
|
||
| ### How it works: | ||
| ```kotlin | ||
| // When USB device is attached: | ||
| 1. Android broadcasts ACTION_USB_DEVICE_ATTACHED | ||
| 2. MainActivity receives the broadcast | ||
| 3. Checks if we have permission for the device | ||
| 4. If not, shows permission dialog to user | ||
| 5. User grants/denies permission | ||
| 6. Result is broadcast back to MainActivity | ||
| 7. Plugin can now enumerate and open the port | ||
| ``` | ||
|
|
||
| ## The Problem We Solved | ||
|
|
||
| Even with manifest permissions, Android apps need to **request permission at runtime** for each USB device. The stock Tauri activity doesn't do this automatically, so we added: | ||
|
|
||
| - Custom `MainActivity.kt` that extends `TauriActivity` | ||
| - USB broadcast receivers for attach/detach events | ||
| - Runtime permission request handling | ||
| - Logging to help debug USB issues | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Building for Android | ||
|
|
||
| 1. Initialize the Android project (if not already done): | ||
| ```bash | ||
| cd src-tauri | ||
| cargo tauri android init | ||
| ``` | ||
|
|
||
| 2. **Run the patch script** before building: | ||
| ```bash | ||
| ./scripts/patch-android-manifest.sh | ||
| ``` | ||
|
|
||
| 3. Build the Android APK: | ||
| ```bash | ||
| cd src-tauri | ||
| cargo tauri android build | ||
| ``` | ||
|
|
||
| ### Automated Workflow | ||
|
|
||
| You can combine these steps: | ||
|
|
||
| ```bash | ||
| # From the project root | ||
| cd src-tauri | ||
| cargo tauri android init | ||
| cd .. | ||
| ./scripts/patch-android-manifest.sh | ||
| cd src-tauri | ||
| cargo tauri android build | ||
| ``` | ||
|
|
||
| ## What the Script Does | ||
|
|
||
| 1. Checks if the Android manifest exists at `src-tauri/gen/android/app/src/main/AndroidManifest.xml` | ||
| 2. Adds USB permissions if not already present | ||
| 3. Adds USB device attach intent filter | ||
| 4. Creates `device_filter.xml` with all Betaflight-compatible USB device IDs | ||
| 5. Creates a backup of the original manifest | ||
|
|
||
| ## Future Improvements | ||
|
|
||
| Ideally, `tauri-plugin-serialplugin` should handle Android permissions automatically. If this becomes available in a future version, this workaround will no longer be necessary. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Script fails with "manifest not found" | ||
| Run `cargo tauri android init` first to generate the Android project. | ||
|
|
||
| ### Permissions not working after build | ||
| Make sure you run the patch script **after** `android init` but **before** `android build`. | ||
|
|
||
| ### Need to rebuild | ||
| If you run `cargo tauri android init` again (which regenerates the manifest), you must run the patch script again before building. |
Uh oh!
There was an error while loading. Please reload this page.