-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_flutter_android.bat
More file actions
97 lines (81 loc) · 3.38 KB
/
update_flutter_android.bat
File metadata and controls
97 lines (81 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
@echo off
setlocal enabledelayedexpansion
REM ----------------------------------------
REM Configuration - update these as needed
set DESIRED_GRADLE_VERSION=8.11.1
set DESIRED_JAVA_VERSION=17
set DESIRED_NDK_VERSION=27.0.12077973
set DESIRED_TARGET_SDK=35
set DESIRED_MIN_SDK_VERSION=24
set DESIRED_ANDROID_APPLICATION_VERSION=8.9.1
REM ----------------------------------------
REM Check if pubspec.yaml exists in current directory (Flutter project check)
if not exist "pubspec.yaml" (
echo This is not a Flutter project (pubspec.yaml missing).
exit /b 1
)
REM Check if android folder exists
if not exist android (
echo Android directory not found.
exit /b 1
)
cd android
REM Backup important files
echo Backing up important files...
copy gradle\wrapper\gradle-wrapper.properties gradle\wrapper\gradle-wrapper.properties.bak >nul
if exist app\build.gradle (
copy app\build.gradle app\build.gradle.bak >nul
)
if exist app\build.gradle.kts (
copy app\build.gradle.kts app\build.gradle.kts.bak >nul
)
if exist settings.gradle (
copy settings.gradle settings.gradle.bak >nul
)
if exist settings.gradle.kts (
copy settings.gradle.kts settings.gradle.kts.bak >nul
)
REM Update Gradle version using Gradle wrapper command
echo Updating Gradle wrapper version to %DESIRED_GRADLE_VERSION%...
call gradlew wrapper --gradle-version=%DESIRED_GRADLE_VERSION% --distribution-type=all
REM Determine build file type (Groovy or Kotlin)
set BUILD_GRADLE_FILE=
if exist app\build.gradle.kts (
set BUILD_GRADLE_FILE=app\build.gradle.kts
) else if exist app\build.gradle (
set BUILD_GRADLE_FILE=app\build.gradle
) else (
echo No app build.gradle(.kts) file found.
exit /b 1
)
REM Function to replace line in a file (Windows supports PowerShell, use that for safer regex replace)
REM Update Java version, NDK version, minSdk and targetSdk in build.gradle(.kts)
echo Updating project settings in %BUILD_GRADLE_FILE%...
powershell -Command ^
"(gc %BUILD_GRADLE_FILE%) -replace 'JavaVersion\.VERSION_[0-9_]+', 'JavaVersion.VERSION_%DESIRED_JAVA_VERSION%' | ^
Set-Content %BUILD_GRADLE_FILE%"
powershell -Command ^
"(gc %BUILD_GRADLE_FILE%) -replace 'ndkVersion\s*=\s*\"[^\"]+\"', 'ndkVersion = \"%DESIRED_NDK_VERSION%\"' | ^
Set-Content %BUILD_GRADLE_FILE%"
powershell -Command ^
"(gc %BUILD_GRADLE_FILE%) -replace 'minSdk\s*=\s*[0-9]+', 'minSdk = %DESIRED_MIN_SDK_VERSION%' | ^
Set-Content %BUILD_GRADLE_FILE%"
powershell -Command ^
"(gc %BUILD_GRADLE_FILE%) -replace 'targetSdk\s*=\s*[0-9]+', 'targetSdk = %DESIRED_TARGET_SDK%' | ^
Set-Content %BUILD_GRADLE_FILE%"
REM Update Android Gradle Plugin version in settings.gradle or settings.gradle.kts
if exist settings.gradle.kts (
powershell -Command ^
"(gc settings.gradle.kts) -replace 'id\\(\"com.android.application\"\\) version \\\"[\\d\\.]+\\\" apply false',^
'id(\"com.android.application\") version \"%DESIRED_ANDROID_APPLICATION_VERSION%\" apply false' | Set-Content settings.gradle.kts"
) else if exist settings.gradle (
powershell -Command ^
"(gc settings.gradle) -replace 'id \"com.android.application\" version \"[\\d\\.]+\" apply false',^
'id \"com.android.application\" version \"%DESIRED_ANDROID_APPLICATION_VERSION%\" apply false' | Set-Content settings.gradle"
)
echo Android project updated successfully.
echo Remember to run:
echo flutter clean
echo flutter pub get
echo To ensure project builds correctly after updates.
endlocal