Skip to content

Commit 7040058

Browse files
committed
Update scripts
1 parent 7e03458 commit 7040058

File tree

2 files changed

+38
-94
lines changed

2 files changed

+38
-94
lines changed

scripts/build-android-local.sh

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,47 @@ if [[ "$MODE" == "validate" ]]; then
103103
exit 0
104104
fi
105105

106+
# Helper to select Android device for dev builds
107+
select_android_device() {
108+
if ! command -v adb >/dev/null 2>&1; then
109+
echo "adb not found. Please install Android SDK and ensure adb is in PATH."
110+
exit 1
111+
fi
112+
113+
echo "==> Checking for connected Android devices..."
114+
local devices
115+
devices=$(adb devices | grep -v "List of devices" | grep -v "^$" | awk '{print $1}')
116+
117+
if [[ -z "$devices" ]]; then
118+
echo "No devices connected. Please connect your tablet via wireless ADB."
119+
echo "Run: adb connect <tablet_ip>:<port>"
120+
exit 1
121+
fi
122+
123+
local device_count
124+
device_count=$(echo "$devices" | wc -l)
125+
126+
if [[ $device_count -eq 1 ]]; then
127+
local device_id
128+
device_id=$(echo "$devices" | head -1)
129+
echo "Using device: $device_id"
130+
export ANDROID_SERIAL="$device_id"
131+
else
132+
echo "Multiple devices found. Select one:"
133+
select device_id in $devices; do
134+
if [[ -n "$device_id" ]]; then
135+
echo "Selected: $device_id"
136+
export ANDROID_SERIAL="$device_id"
137+
break
138+
fi
139+
done
140+
fi
141+
}
142+
106143
echo "==> Checking Android project generation"
107144
if [[ ! -f "$MANIFEST_PATH" ]]; then
108145
echo " Android project not found, initializing..."
109146
run_tauri android init --ci
110-
else
111-
echo " Android project already initialized"
112147
fi
113148

114149
# Always patch after init (init may regenerate files)
@@ -124,10 +159,7 @@ if [[ "$MODE" == "dev" || "$MODE" == "debug" ]]; then
124159
echo " Building web assets (vite)"
125160
yarn build
126161
fi
127-
# Help the device reach the dev server on port 8000
128-
if command -v yarn >/dev/null 2>&1; then
129-
yarn android:adb:reverse || true
130-
fi
162+
select_android_device
131163
run_tauri android dev
132164
echo "==> Dev build complete and should be installed on the device."
133165
exit 0

scripts/patch-android-manifest.sh renamed to scripts/tauri-patch-android.sh

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -108,91 +108,6 @@ echo "✓ USB device filter created successfully!"
108108
# The manifest intent filters and permissions are sufficient for device discovery
109109
echo "Skipping custom MainActivity (not needed for USB serial permissions)"
110110

111-
# Add USB serial library dependency to app build.gradle.kts
112-
if [ -f "$APP_BUILD_GRADLE" ]; then
113-
# Add JitPack repository directly to app build.gradle.kts (fallback if settings.gradle.kts injection fails)
114-
echo "Adding JitPack repository to app build.gradle.kts..."
115-
if ! grep -q "jitpack.io" "$APP_BUILD_GRADLE"; then
116-
# Insert repositories block at the top of the file, after any existing buildscript/plugins blocks
117-
awk '
118-
BEGIN { inserted=0 }
119-
{
120-
print
121-
# Insert after plugins or buildscript block closes, or before first line if no such blocks
122-
if (!inserted && (NR==1 || $0 ~ /^plugins \{/ || $0 ~ /^buildscript \{/)) {
123-
if ($0 ~ /^\}/ || NR==1) {
124-
print ""
125-
print "repositories {"
126-
print " maven { url = uri(\"https://jitpack.io\") }"
127-
print "}"
128-
print ""
129-
inserted=1
130-
}
131-
}
132-
}
133-
END {
134-
if (!inserted) {
135-
print ""
136-
print "repositories {"
137-
print " maven { url = uri(\"https://jitpack.io\") }"
138-
print "}"
139-
print ""
140-
}
141-
}
142-
' "$APP_BUILD_GRADLE" > "$APP_BUILD_GRADLE.tmp" && mv "$APP_BUILD_GRADLE.tmp" "$APP_BUILD_GRADLE"
143-
echo "✓ JitPack repository added to app build.gradle.kts"
144-
else
145-
echo "JitPack repository already present in app build.gradle.kts"
146-
fi
147-
148-
echo "Adding USB serial library dependency..."
149-
if ! grep -q "usb-serial-for-android" "$APP_BUILD_GRADLE"; then
150-
# Check if dependencies block exists
151-
if grep -q "^dependencies {" "$APP_BUILD_GRADLE"; then
152-
echo "Inserting into existing dependencies block..."
153-
# Use awk to insert after the dependencies { line (portable)
154-
awk '/^dependencies \{/ {
155-
print
156-
print " // USB Serial library for Android - explicit version to override plugin transitive 3.8.1"
157-
print " implementation(\"com.github.mik3y:usb-serial-for-android:3.8.0\")"
158-
next
159-
}
160-
{ print }' "$APP_BUILD_GRADLE" > "$APP_BUILD_GRADLE.tmp" && mv "$APP_BUILD_GRADLE.tmp" "$APP_BUILD_GRADLE"
161-
echo "✓ USB serial library dependency added!"
162-
else
163-
echo "No dependencies block found, appending new block..."
164-
cat >> "$APP_BUILD_GRADLE" << 'EOF'
165-
166-
dependencies {
167-
// USB Serial library for Android - explicit version to override plugin transitive 3.8.1
168-
implementation("com.github.mik3y:usb-serial-for-android:3.8.0")
169-
}
170-
EOF
171-
echo "✓ USB serial library dependency added!"
172-
fi
173-
else
174-
echo "USB serial library dependency already present"
175-
fi
176-
177-
# Add resolution strategy to force version 3.8.0
178-
echo "Adding version resolution strategy..."
179-
if ! grep -q "resolutionStrategy" "$APP_BUILD_GRADLE"; then
180-
cat >> "$APP_BUILD_GRADLE" << 'EOF'
181-
182-
configurations.all {
183-
resolutionStrategy {
184-
force("com.github.mik3y:usb-serial-for-android:3.8.0")
185-
}
186-
}
187-
EOF
188-
echo "✓ Resolution strategy added to force version 3.8.0"
189-
else
190-
echo "Resolution strategy already present"
191-
fi
192-
else
193-
echo "Warning: $APP_BUILD_GRADLE not found, skipping dependency addition"
194-
fi
195-
196111
echo ""
197112
echo "✓ Android USB support configuration complete!"
198113
echo "You can now build the Android app with: cargo tauri android build"
@@ -218,7 +133,4 @@ pluginManagement {
218133
}
219134
}
220135
EOF
221-
echo "✓ settings.gradle.kts created and injected with JitPack and required repositories."
222-
else
223-
echo "settings.gradle.kts already exists, checking for JitPack and required blocks..."
224136
fi

0 commit comments

Comments
 (0)