-
-
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
Open
haslinghuis
wants to merge
56
commits into
betaflight:tauri
Choose a base branch
from
haslinghuis:tauri-test
base: tauri
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.
+2,193
−595
Open
Patch manifest #4687
Changes from 4 commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
fc31a5e
Patch manifest
haslinghuis ae221c4
Updte workflow
haslinghuis b6b31db
Use tauri-plugin-serialplugin
haslinghuis 74a3266
Fix build
haslinghuis 983a9cf
Use Kotlin DSL syntax, not Groovy
haslinghuis c2163bd
Replace sed with awk
haslinghuis 0533869
Downgrade tauri-plugin-serialplugin to 2.10.0 in Cargo.lock
haslinghuis a801f59
Upgrade to tauri-plugin-serialplugin 2.16.0 for Android USB support
haslinghuis cadf39f
Add Android USB debugging tools and updated documentation
haslinghuis eb441f4
Fix manifest patching: replace sed with awk for cross-platform compat…
haslinghuis 8c93e03
Add custom MainActivity with USB runtime permission handling
haslinghuis b1c3154
Update debugging docs with MainActivity testing instructions
haslinghuis 0a60f3e
Fix MainActivity import: add missing TauriActivity import
haslinghuis 2eb9aaa
Nitpicks
haslinghuis cd6aa1f
Fix JitPack repository injection: use settings.gradle.kts with Kotlin…
haslinghuis 2f2e9ab
Move JitPack repository injection into patch script
haslinghuis e9c511e
Inject JitPack into dependencyResolutionManagement.repositories in se…
haslinghuis 3d13b6e
Revert usb-serial-for-android to 3.8.0 and harden JitPack injection
haslinghuis d71a7c1
Fix grep alternation and duplicate -n in JitPack repo preview
haslinghuis 04b8256
Force usb-serial-for-android to 3.8.0 and remove FAIL_ON_PROJECT_REPO…
haslinghuis 99642e8
Fix Kotlin DSL syntax error - use resolutionStrategy instead of isForce
haslinghuis aa9ddc8
Add debug output to show settings.gradle.kts before and after JitPack…
haslinghuis 8d87c20
Add JitPack repository directly to app build.gradle.kts as fallback
haslinghuis 37fb1b6
Remove custom MainActivity - not needed for USB serial permissions
haslinghuis 6d79317
Add extensive debug logging for Android USB enumeration
haslinghuis a826b93
Add ADB wireless debugging setup for Android USB testing
haslinghuis 4a32b85
Fix ADB wireless setup script to support IPv6 addresses
haslinghuis b85212b
Add comprehensive next steps guide for Android USB debugging
haslinghuis 792d918
Add local Android build script: init + patch + dev/release + signing …
haslinghuis 735ac48
feat(android): enable USB serial support with debugging capabilities
haslinghuis 1d19205
docs: add Android USB serial status and progress tracking
haslinghuis 9416e32
Shell improvement
haslinghuis 1331237
Default is not needed when using explicit permissions
haslinghuis 4435a99
No need for HMR_HOST
haslinghuis bb84552
Forgot to include
haslinghuis 90cecf7
Address 'Warning: src-tauri/gen/android/settings.gradle.kts not found…
haslinghuis 83122fc
Address 'Warning: src-tauri/gen/android/settings.gradle.kts not found…
haslinghuis 7e03458
little cleanup
haslinghuis b7f391a
Update scripts
haslinghuis 0a0bf83
Fix android debugging
haslinghuis 62f9c41
???
haslinghuis 05bc006
Add dependency for usb-serial-for-android
haslinghuis 5ec9332
Address CR nitpick
haslinghuis cb3680a
After running cargo update
haslinghuis 5f31190
Fix working versions
haslinghuis a93186b
Dependency hell
haslinghuis 8e779cd
Which version works ???
haslinghuis 72173cf
Fix script portability
haslinghuis 56f041f
modify the patch script to add the repository directly to build.gradl…
haslinghuis 4dfd15e
refactor scripts for single responsibility
haslinghuis c19e84c
Using js API instead of Rust invoke
haslinghuis bf62596
Fix USB permission issue
haslinghuis 220037c
Fix port enumeration
haslinghuis 0e4c4c7
Some cleanup
haslinghuis 6dea4b3
Read is not solved
haslinghuis 7e5ce52
Apply custom MainActivity.kt
haslinghuis 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
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,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. |
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,113 @@ | ||
| #!/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 | ||
| # Check if dependencies block exists | ||
| if grep -q "^dependencies {" "$APP_BUILD_GRADLE"; then | ||
| echo "Inserting into existing dependencies block..." | ||
| # Insert after the dependencies { line | ||
| sed -i '/^dependencies {/a\ \/\/ USB Serial library for Android\n implementation("com.github.mik3y:usb-serial-for-android:3.8.0")' "$APP_BUILD_GRADLE" | ||
| echo "✓ USB serial library dependency added!" | ||
| else | ||
| echo "No dependencies block found, appending new block..." | ||
| 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!" | ||
| fi | ||
| 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 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.