Repository: flutter
Issue: local.properties and build.gradle versionCode and versionName problem
Labels: platform-android,tool,a: build,P2,team-android,triaged-android

### Steps to reproduce

1. Edit local.properties to remove errors and set suitable versionCode and versionName
2. Edit android/app/build.gradle to remove warnings
3. `flutter build` resets local.properties and fails

### Expected results

local.properties is not reset and the values from there are used in android/app/build.gradle

### Actual results

local.properties is reset and the build fails

### Code sample

<details open><summary>What is happening</summary>

I have in local.properties:
```
flutter.sdk=D:\\Android\\flutter-dart-sdk
sdk.dir=D:\\Android\\Sdk
flutter.buildMode=release
flutter.minSdkVersion=16
flutter.targetSdkVersion=35
flutter.versionCode=1
flutter.versionName=1.0.0
```
This causes 2 errors:
![image](https://github.com/user-attachments/assets/e7124d5f-da32-473a-af58-d23de2b5850d)
```
Windows file separators (`\`) and drive letter separators (':') must be escaped (`\\`) in property files; use D\\:\\\\Android\\\\flutter-dart-sdk
Windows file separators (`\`) and drive letter separators (':') must be escaped (`\\`) in property files; use D\\:\\\\Android\\\\Sdk
```
**The errors are not corresponding to the visual.** The error is a missing slash (`\`) only before colon (`:`) and nothing else is wrong!

In /android/app/build.gradle I have this code and **it causes 2 warnings**:
```
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1' // WARNING: Assignment is not used
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0' // WARNING: Assignment is not used
}

android {
    ...
    defaultConfig {
        ...
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion 35
        versionCode 69
        versionName "3.6.1"
    }
    ...
}
```

I can set In build.gradle
```
android {
    ...
    defaultConfig {
        ...
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode
        versionName flutterVersionName
    }
    ...
}
```
so that build.gradle warnings are gone.
Also I can fix errors in local.properties by adding slashes and changing versionCode and versionName accordingly
```
flutter.sdk=D\:\\Android\\flutter-dart-sdk
sdk.dir=D\:\\Android\\Sdk
flutter.buildMode=release
flutter.minSdkVersion=16
flutter.targetSdkVersion=35
flutter.versionCode=69
flutter.versionName=3.6.1
```
so that local.properties errors are gone.
BUT while `flutter build` local.properties `flutter.sdk`, `sdk.dir`, `flutter.versionCode` and `flutter.versionName` are reset to
```
flutter.sdk=D:\\Android\\flutter-dart-sdk
sdk.dir=D:\\Android\\Sdk
flutter.buildMode=release
flutter.minSdkVersion=16
flutter.targetSdkVersion=35
flutter.versionCode=1
flutter.versionName=1.0.0
```
and the build fails:
```
FAILURE: Build failed with an exception.

* Where:
Build file '...\android\app\build.gradle' line: 62

* What went wrong:
A problem occurred evaluating project ':app'.
> Value is null

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 1s
Running Gradle task 'bundleRelease'...                           1,261ms
Gradle task bundleRelease failed with exit code 1
```
On line 62 I have `versionCode flutterVersionCode` which is not null by any of these files.
In `local.properties` it's `flutter.versionCode=1` instead of `flutter.versionCode=69` and build.gradle states
```
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}
```
</details>


### Screenshots or Video

_No response_

### Logs

_No response_

### Flutter Doctor output

<details open><summary>Doctor output</summary>

```
[√] Flutter (Channel stable, 3.27.0, on Microsoft Windows [Version 10.0.19045.5131], locale en-US)
    • Flutter version 3.27.0 on channel stable at D:\Android\flutter-dart-sdk
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 8495dee1fd (35 hours ago), 2024-12-10 14:23:39 -0800
    • Engine revision 83bacfc525
    • Dart version 3.6.0
    • DevTools version 2.40.2

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at D:\Android\Sdk
    • Platform android-35, build-tools 35.0.0
    • ANDROID_HOME = D:\Android\Sdk
    • ANDROID_SDK_ROOT = D:\Android\Sdk
    • Java binary at: D:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.12.1)
    • Visual Studio at D:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.12.35514.174
    • Windows 10 SDK version 10.0.26100.0

[√] Android Studio (version 2024.2)
    • Android Studio at D:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)

[√] VS Code (version 1.95.3)
    • VS Code at C:\Users\Aktiviteet\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.100.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19045.5131]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 131.0.6778.109
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 131.0.2903.70

[√] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>