Skip to content

Commit 7360828

Browse files
bartekpaciareidbaker
authored andcommitted
Flutter Gradle Plugin: add versionName and versionCode to FlutterExtension (flutter#146044)
This PR is a follow-up of a previous PR of mine: flutter#141417. It was unfinished, i.e. I only implemented it and used it in `examples/hello_world`. No "flutter create" templates were modified. This change is theoretically breaking, but in practice, I am pretty sure nobody uses this. It was not accounced anywhere, the only app using it is `examples/hello_world`. I did not do that (that=update docs and templates) because I wanted a solution that is idiomatic in both Gradle and Kotlin, and only now I found time to do this. ### Without this change ```groovy defaultConfig { applicationId = "io.flutter.examples.hello_world" minSdk = flutter.minSdkVersion targetSdk = flutter.targetSdkVersion versionCode = flutter.versionCode() versionName = flutter.versionName() } ``` ### With this change ```groovy defaultConfig { applicationId = "io.flutter.examples.hello_world" minSdk = flutter.minSdkVersion targetSdk = flutter.targetSdkVersion versionCode = flutter.versionCode versionName = flutter.versionName } ``` Idiomatic getter - yay! It's consistent between assignment of all four props. ### Issue fixes flutter#146067 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Reid Baker <reidbaker@google.com>
1 parent 86646a1 commit 7360828

File tree

5 files changed

+9
-27
lines changed

5 files changed

+9
-27
lines changed

examples/flutter_view/android/app/build.gradle

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,6 @@ plugins {
77
id "dev.flutter.flutter-gradle-plugin"
88
}
99

10-
def localProperties = new Properties()
11-
def localPropertiesFile = rootProject.file('local.properties')
12-
if (localPropertiesFile.exists()) {
13-
localPropertiesFile.withReader('UTF-8') { reader ->
14-
localProperties.load(reader)
15-
}
16-
}
17-
18-
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
19-
if (flutterVersionCode == null) {
20-
flutterVersionCode = '1'
21-
}
22-
23-
def flutterVersionName = localProperties.getProperty('flutter.versionName')
24-
if (flutterVersionName == null) {
25-
flutterVersionName = '1.0'
26-
}
27-
2810
android {
2911
namespace "com.example.view"
3012
compileSdk flutter.compileSdkVersion
@@ -38,8 +20,8 @@ android {
3820
applicationId "io.flutter.examples.flutter_view"
3921
minSdkVersion flutter.minSdkVersion
4022
targetSdkVersion flutter.targetSdkVersion
41-
versionCode flutterVersionCode.toInteger()
42-
versionName flutterVersionName
23+
versionCode flutter.versionCode
24+
versionName flutter.versionName
4325
}
4426

4527
buildTypes {

examples/hello_world/android/app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ android {
2020
applicationId = "io.flutter.examples.hello_world"
2121
minSdk = flutter.minSdkVersion
2222
targetSdk = flutter.targetSdkVersion
23-
versionCode = flutter.versionCode()
24-
versionName = flutter.versionName()
23+
versionCode = flutter.versionCode
24+
versionName = flutter.versionName
2525
}
2626

2727
buildTypes {

examples/layers/android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ android {
2020
applicationId "io.flutter.examples.layers"
2121
minSdkVersion flutter.minSdkVersion
2222
targetSdkVersion flutter.targetSdkVersion
23-
versionCode flutter.versionCode()
24-
versionName flutter.versionName()
23+
versionCode flutter.versionCode
24+
versionName flutter.versionName
2525
}
2626

2727
buildTypes {

packages/flutter_tools/gradle/src/main/groovy/app_plugin_loader.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class FlutterAppPluginLoaderPlugin implements Plugin<Settings> {
1717
settings.ext.flutterSdkPath = properties.getProperty("flutter.sdk")
1818
assert settings.ext.flutterSdkPath != null, "flutter.sdk not set in local.properties"
1919
}
20-
20+
2121
// Load shared gradle functions
2222
settings.apply from: Paths.get(settings.ext.flutterSdkPath, "packages", "flutter_tools", "gradle", "src", "main", "groovy", "native_plugin_loader.groovy")
2323

packages/flutter_tools/gradle/src/main/groovy/flutter.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class FlutterExtension {
7878
public String flutterVersionName = null
7979

8080
/** Returns flutterVersionCode as an integer with error handling. */
81-
public Integer versionCode() {
81+
public Integer getVersionCode() {
8282
if (flutterVersionCode == null) {
8383
throw new GradleException("flutterVersionCode must not be null.")
8484
}
@@ -91,7 +91,7 @@ class FlutterExtension {
9191
}
9292

9393
/** Returns flutterVersionName with error handling. */
94-
public String versionName() {
94+
public String getVersionName() {
9595
if (flutterVersionName == null) {
9696
throw new GradleException("flutterVersionName must not be null.")
9797
}

0 commit comments

Comments
 (0)