Skip to content

Commit 56f041f

Browse files
committed
modify the patch script to add the repository directly to build.gradle.kts instead of relying on the project-level settings.gradle.kts
1 parent 72173cf commit 56f041f

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

scripts/tauri-patch-android.sh

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,24 +248,62 @@ fi
248248

249249
# Idempotent app/build.gradle.kts dependency injection
250250
APP_BUILD_GRADLE="src-tauri/gen/android/app/build.gradle.kts"
251-
echo "Ensuring usb-serial-for-android dependency in app/build.gradle.kts..."
251+
echo "Ensuring usb-serial-for-android dependency and repositories in app/build.gradle.kts..."
252252

253253
if [ -f "$APP_BUILD_GRADLE" ]; then
254+
# Add repositories block to app/build.gradle.kts if missing
255+
if ! grep -q "^repositories {" "$APP_BUILD_GRADLE"; then
256+
echo "Adding repositories block to app/build.gradle.kts..."
257+
# Insert repositories block after plugins block
258+
awk '
259+
/^plugins \{/ {
260+
print $0
261+
in_plugins=1
262+
next
263+
}
264+
in_plugins && /^\}/ {
265+
print $0
266+
print ""
267+
print "repositories {"
268+
print " maven { url = uri(\"https://jitpack.io\") }"
269+
print "}"
270+
in_plugins=0
271+
next
272+
}
273+
{ print }
274+
' "$APP_BUILD_GRADLE" > "$APP_BUILD_GRADLE.tmp" && mv "$APP_BUILD_GRADLE.tmp" "$APP_BUILD_GRADLE"
275+
else
276+
# Check if jitpack.io is already in repositories
277+
if ! grep -A 10 "^repositories {" "$APP_BUILD_GRADLE" | grep -q "jitpack.io"; then
278+
echo "Adding jitpack.io repository to existing repositories block..."
279+
# Insert jitpack.io repository into existing repositories block
280+
awk '
281+
/^repositories \{/ {
282+
print $0
283+
print " maven { url = uri(\"https://jitpack.io\") }"
284+
found=1
285+
next
286+
}
287+
{ print }
288+
' "$APP_BUILD_GRADLE" > "$APP_BUILD_GRADLE.tmp" && mv "$APP_BUILD_GRADLE.tmp" "$APP_BUILD_GRADLE"
289+
fi
290+
fi
291+
254292
if ! grep -q "usb-serial-for-android" "$APP_BUILD_GRADLE"; then
255293
echo "Adding usb-serial-for-android dependency to app module..."
256294
# Find the dependencies block and add the dependency
257295
if grep -q "^dependencies {" "$APP_BUILD_GRADLE"; then
258296
# Insert after the opening dependencies { line
259297
sed -i '/^dependencies {/a\
260-
implementation("com.github.mik3y:usb-serial-for-android:3.8.1")
298+
implementation("com.github.mik3y:usb-serial-for-android:3.8.0")
261299
' "$APP_BUILD_GRADLE"
262300
else
263301
# Create dependencies block if it doesn't exist
264302
echo "Creating dependencies block with usb-serial-for-android..."
265303
cat >> "$APP_BUILD_GRADLE" << 'EOF'
266304
267305
dependencies {
268-
implementation("com.github.mik3y:usb-serial-for-android:3.8.1")
306+
implementation("com.github.mik3y:usb-serial-for-android:3.8.0")
269307
}
270308
EOF
271309
fi

0 commit comments

Comments
 (0)