Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
fc31a5e
Patch manifest
haslinghuis Oct 29, 2025
ae221c4
Updte workflow
haslinghuis Oct 29, 2025
b6b31db
Use tauri-plugin-serialplugin
haslinghuis Oct 29, 2025
74a3266
Fix build
haslinghuis Oct 29, 2025
983a9cf
Use Kotlin DSL syntax, not Groovy
haslinghuis Oct 29, 2025
c2163bd
Replace sed with awk
haslinghuis Oct 29, 2025
0533869
Downgrade tauri-plugin-serialplugin to 2.10.0 in Cargo.lock
haslinghuis Oct 29, 2025
a801f59
Upgrade to tauri-plugin-serialplugin 2.16.0 for Android USB support
haslinghuis Oct 29, 2025
cadf39f
Add Android USB debugging tools and updated documentation
haslinghuis Oct 29, 2025
eb441f4
Fix manifest patching: replace sed with awk for cross-platform compat…
haslinghuis Oct 29, 2025
8c93e03
Add custom MainActivity with USB runtime permission handling
haslinghuis Oct 29, 2025
b1c3154
Update debugging docs with MainActivity testing instructions
haslinghuis Oct 29, 2025
0a60f3e
Fix MainActivity import: add missing TauriActivity import
haslinghuis Oct 29, 2025
2eb9aaa
Nitpicks
haslinghuis Oct 29, 2025
cd6aa1f
Fix JitPack repository injection: use settings.gradle.kts with Kotlin…
haslinghuis Oct 29, 2025
2f2e9ab
Move JitPack repository injection into patch script
haslinghuis Oct 29, 2025
e9c511e
Inject JitPack into dependencyResolutionManagement.repositories in se…
haslinghuis Oct 29, 2025
3d13b6e
Revert usb-serial-for-android to 3.8.0 and harden JitPack injection
haslinghuis Oct 29, 2025
d71a7c1
Fix grep alternation and duplicate -n in JitPack repo preview
haslinghuis Oct 29, 2025
04b8256
Force usb-serial-for-android to 3.8.0 and remove FAIL_ON_PROJECT_REPO…
haslinghuis Oct 29, 2025
99642e8
Fix Kotlin DSL syntax error - use resolutionStrategy instead of isForce
haslinghuis Oct 29, 2025
aa9ddc8
Add debug output to show settings.gradle.kts before and after JitPack…
haslinghuis Oct 29, 2025
8d87c20
Add JitPack repository directly to app build.gradle.kts as fallback
haslinghuis Oct 29, 2025
37fb1b6
Remove custom MainActivity - not needed for USB serial permissions
haslinghuis Oct 29, 2025
6d79317
Add extensive debug logging for Android USB enumeration
haslinghuis Oct 29, 2025
a826b93
Add ADB wireless debugging setup for Android USB testing
haslinghuis Oct 29, 2025
4a32b85
Fix ADB wireless setup script to support IPv6 addresses
haslinghuis Oct 29, 2025
b85212b
Add comprehensive next steps guide for Android USB debugging
haslinghuis Oct 29, 2025
792d918
Add local Android build script: init + patch + dev/release + signing …
haslinghuis Oct 29, 2025
735ac48
feat(android): enable USB serial support with debugging capabilities
haslinghuis Oct 29, 2025
1d19205
docs: add Android USB serial status and progress tracking
haslinghuis Oct 29, 2025
9416e32
Shell improvement
haslinghuis Oct 29, 2025
1331237
Default is not needed when using explicit permissions
haslinghuis Oct 29, 2025
4435a99
No need for HMR_HOST
haslinghuis Oct 29, 2025
bb84552
Forgot to include
haslinghuis Oct 29, 2025
90cecf7
Address 'Warning: src-tauri/gen/android/settings.gradle.kts not found…
haslinghuis Oct 30, 2025
83122fc
Address 'Warning: src-tauri/gen/android/settings.gradle.kts not found…
haslinghuis Oct 30, 2025
7e03458
little cleanup
haslinghuis Oct 30, 2025
b7f391a
Update scripts
haslinghuis Nov 3, 2025
0a0bf83
Fix android debugging
haslinghuis Nov 3, 2025
62f9c41
???
haslinghuis Nov 3, 2025
05bc006
Add dependency for usb-serial-for-android
haslinghuis Nov 3, 2025
5ec9332
Address CR nitpick
haslinghuis Nov 3, 2025
cb3680a
After running cargo update
haslinghuis Nov 3, 2025
5f31190
Fix working versions
haslinghuis Nov 3, 2025
a93186b
Dependency hell
haslinghuis Nov 3, 2025
8e779cd
Which version works ???
haslinghuis Nov 3, 2025
72173cf
Fix script portability
haslinghuis Nov 3, 2025
56f041f
modify the patch script to add the repository directly to build.gradl…
haslinghuis Nov 3, 2025
4dfd15e
refactor scripts for single responsibility
haslinghuis Nov 3, 2025
c19e84c
Using js API instead of Rust invoke
haslinghuis Nov 6, 2025
bf62596
Fix USB permission issue
haslinghuis Nov 6, 2025
220037c
Fix port enumeration
haslinghuis Nov 6, 2025
0e4c4c7
Some cleanup
haslinghuis Nov 6, 2025
6dea4b3
Read is not solved
haslinghuis Nov 6, 2025
7e5ce52
Apply custom MainActivity.kt
haslinghuis Nov 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions ANDROID_USB.md
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.
82 changes: 82 additions & 0 deletions scripts/patch-android-manifest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/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"

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!"
echo ""
echo "You can now build the Android app with: cargo tauri android build"