-
-
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 3 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,77 @@ | ||
| # Android USB Serial Support | ||
|
|
||
| ## Problem | ||
|
|
||
| The Betaflight Configurator uses `tauri-plugin-serialplugin` to access serial ports. On Linux, this works without special configuration, but **Android requires explicit USB permissions** that must be declared in the `AndroidManifest.xml`. | ||
|
|
||
| Since the Android project in `src-tauri/gen/android/` is **regenerated at build time**, manual changes to the manifest are lost. | ||
|
|
||
| ## Solution | ||
|
|
||
| We've created a patch script that automatically adds the required USB permissions and device filters to the generated Android manifest. | ||
|
|
||
| ### Required Permissions | ||
|
|
||
| The script adds: | ||
| - `android.permission.USB_PERMISSION` - Required to access USB devices | ||
| - `android.hardware.usb.host` - Declares USB host mode support | ||
| - USB device intent filter - Prompts user when compatible USB device is connected | ||
| - USB device filter - Lists all Betaflight-compatible USB devices (FTDI, STM32, CP210x, etc.) | ||
|
|
||
| ## 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| #!/bin/bash | ||
| # Script to patch the Android manifest with USB permissions after generation | ||
| # This should be run after 'cargo tauri android init' or 'cargo tauri android build' | ||
|
|
||
| set -e | ||
|
|
||
| MANIFEST_PATH="src-tauri/gen/android/app/src/main/AndroidManifest.xml" | ||
| DEVICE_FILTER_PATH="src-tauri/gen/android/app/src/main/res/xml/device_filter.xml" | ||
| APP_BUILD_GRADLE="src-tauri/gen/android/app/build.gradle.kts" | ||
|
|
||
| if [ ! -f "$MANIFEST_PATH" ]; then | ||
| echo "Error: Android manifest not found at $MANIFEST_PATH" | ||
| echo "Please run 'cargo tauri android init' first" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Patching Android manifest for USB serial support..." | ||
|
|
||
| # Backup original manifest | ||
| cp "$MANIFEST_PATH" "$MANIFEST_PATH.bak" | ||
|
|
||
| # Check if USB permissions already added | ||
| if grep -q "android.permission.USB_PERMISSION" "$MANIFEST_PATH"; then | ||
| echo "USB permissions already present in manifest" | ||
| else | ||
| # Add USB permissions before </manifest> | ||
| sed -i '/<\/manifest>/i \ <!-- USB permissions for serial communication -->\n <uses-permission android:name="android.permission.USB_PERMISSION" />\n <uses-feature android:name="android.hardware.usb.host" android:required="false" />' "$MANIFEST_PATH" | ||
| echo "Added USB permissions to manifest" | ||
| fi | ||
|
|
||
| # Check if USB intent filter already added | ||
| if grep -q "USB_DEVICE_ATTACHED" "$MANIFEST_PATH"; then | ||
| echo "USB intent filter already present in manifest" | ||
| else | ||
| # Add USB device intent filter and metadata before </activity> | ||
| sed -i '0,/<\/activity>/s|</activity>|\n <!-- Intent filter for USB device attach -->\n <intent-filter>\n <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />\n </intent-filter>\n\n <!-- USB device filter metadata -->\n <meta-data\n android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"\n android:resource="@xml/device_filter" />\n </activity>|' "$MANIFEST_PATH" | ||
| echo "Added USB intent filter to manifest" | ||
| fi | ||
|
|
||
| # Create device filter XML | ||
| echo "Creating USB device filter..." | ||
| mkdir -p "$(dirname "$DEVICE_FILTER_PATH")" | ||
| cat > "$DEVICE_FILTER_PATH" << 'EOF' | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
| <!-- USB device filters for Betaflight-compatible devices --> | ||
| <!-- FT232R USB UART --> | ||
| <usb-device vendor-id="1027" product-id="24577" /> | ||
| <!-- STM32 devices --> | ||
| <usb-device vendor-id="1155" product-id="12886" /> <!-- STM32 in HID mode --> | ||
| <usb-device vendor-id="1155" product-id="14158" /> <!-- STLink Virtual COM Port (NUCLEO boards) --> | ||
| <usb-device vendor-id="1155" product-id="22336" /> <!-- STM Electronics Virtual COM Port --> | ||
| <usb-device vendor-id="1155" product-id="57105" /> <!-- STM Device in DFU Mode --> | ||
| <!-- CP210x devices --> | ||
| <usb-device vendor-id="4292" product-id="60000" /> | ||
| <usb-device vendor-id="4292" product-id="60001" /> | ||
| <usb-device vendor-id="4292" product-id="60002" /> | ||
| <!-- GD32 devices --> | ||
| <usb-device vendor-id="10473" product-id="394" /> <!-- GD32 VCP --> | ||
| <usb-device vendor-id="10473" product-id="393" /> <!-- GD32 DFU Bootloader --> | ||
| <!-- AT32 devices --> | ||
| <usb-device vendor-id="11836" product-id="22336" /> <!-- AT32 VCP --> | ||
| <usb-device vendor-id="11836" product-id="57105" /> <!-- AT32F435 DFU Bootloader --> | ||
| <!-- APM32 devices --> | ||
| <usb-device vendor-id="12619" product-id="22336" /> <!-- APM32 VCP --> | ||
| <usb-device vendor-id="12619" product-id="262" /> <!-- APM32 DFU Bootloader --> | ||
| <!-- Raspberry Pi Pico devices --> | ||
| <usb-device vendor-id="11914" product-id="9" /> <!-- Raspberry Pi Pico VCP --> | ||
| <usb-device vendor-id="11914" product-id="15" /> <!-- Raspberry Pi Pico in Bootloader mode --> | ||
| </resources> | ||
| EOF | ||
|
|
||
| echo "✓ Android manifest patched successfully!" | ||
| echo "✓ USB device filter created successfully!" | ||
|
|
||
| # Add USB serial library dependency to app build.gradle.kts | ||
| if [ -f "$APP_BUILD_GRADLE" ]; then | ||
| echo "Adding USB serial library dependency..." | ||
| if ! grep -q "usb-serial-for-android" "$APP_BUILD_GRADLE"; then | ||
| cat >> "$APP_BUILD_GRADLE" << 'EOF' | ||
| dependencies { | ||
| // USB Serial library for Android | ||
| implementation("com.github.mik3y:usb-serial-for-android:3.8.0") | ||
| } | ||
| EOF | ||
| echo "✓ USB serial library dependency added!" | ||
| else | ||
| echo "USB serial library dependency already present" | ||
| fi | ||
| else | ||
| echo "Warning: $APP_BUILD_GRADLE not found, skipping dependency addition" | ||
| fi | ||
|
||
|
|
||
| echo "" | ||
| echo "✓ Android USB support configuration complete!" | ||
| echo "You can now build the Android app with: cargo tauri android build" | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.