Skip to content

Expose versionCode and versionName from local.properties in FlutterExtension - #141417

Merged
auto-submit[bot] merged 3 commits into
flutter:masterfrom
bartekpacia:feature/flutter_extension_version_code_name
Jan 12, 2024
Merged

auto-submit[bot] merged 3 commits into
flutter:masterfrom
bartekpacia:feature/flutter_extension_version_code_name

Conversation

@bartekpacia

@bartekpacia bartekpacia commented Jan 11, 2024 •

Copy link
Copy Markdown
Member

This PR has no issue. I got this cool idea and decided to quickly try it out, and it works.

Summary

This will allow Flutter Developers to have less code in their Android Gradle buildscripts.

 plugins {
     id "com.android.application"
     id "dev.flutter.flutter-gradle-plugin"
     id "kotlin-android"
 }

-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"
-}
-
-def flutterVersionName = localProperties.getProperty("flutter.versionName")
-if (flutterVersionName == null) {
-    flutterVersionName = "1.0"
-}
-
-def keystorePropertiesFile = rootProject.file("keystore.properties")
-def keystoreProperties = new Properties()
-
 keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

 android {
         applicationId "pl.baftek.discoverrudy"
         minSdk 21
         targetSdk 34
-        versionCode flutterVersionCode.toInteger()
-        versionName flutterVersionName
+        versionCode flutter.versionCode()
+        versionName flutter.versionName()
     }

The boilerplate that loads 'local.properties' can live in Flutter Gradle Plugin.

Concerns

I was worried about lifecycle/ordering issues, so I tested it.

To Flutter Gradle Plugin, I added:

 class FlutterPlugin implements Plugin<Project> {
     //...

     @Override
     void apply(Project project) {
+        project.logger.quiet("Start applying FGP")
         // ...
     }
 }

and to my android/app/build.gradle I added:

 android {
+    logger.quiet("Start evaluating android block")
     namespace "pl.bartekpacia.awesomeapp"
     compileSdk 34
 
     defaultConfig {
         applicationId "pl.baftek.discoverrudy"
         minSdk 21
         targetSdk 34
         versionCode flutter.versionCode()
         versionName flutter.versionName()
     }

Gradle first applies the plugins (which sets versionCode and versionName on FlutterExtension), and then it executes the android {} extension block:

$ ./gradlew :app:assembleDebug

> Configure project :app
Start applying FGP
Start evaluating android block

BUILD SUCCESSFUL in 2s
383 actionable tasks: 10 executed, 373 up-to-date

So ordering is fine.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jan 11, 2024
@bartekpacia bartekpacia changed the title expose versionCode and versionName in FlutterExtension Expose versionCode and versionName from local.properties in FlutterExtension Jan 11, 2024
@bartekpacia

Copy link
Copy Markdown
Member Author

TODO (Once tests pass and we deem it okay): update new project template, update #135392

@bartekpacia
bartekpacia marked this pull request as ready for review January 12, 2024 17:25
@github-actions github-actions Bot added the d: examples Sample code and demos label Jan 12, 2024
@bartekpacia
bartekpacia requested a review from camsim99 January 12, 2024 18:00
@bartekpacia bartekpacia added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 12, 2024
@auto-submit
auto-submit Bot merged commit fd827e3 into flutter:master Jan 12, 2024
@bartekpacia
bartekpacia deleted the feature/flutter_extension_version_code_name branch January 12, 2024 18:22
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 13, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 13, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 14, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 14, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 14, 2024
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jan 14, 2024
flutter/flutter@7dc856a...1a2c315

2024-01-14 [email protected] BoxPainter should dispatch creation and disposal events. (flutter/flutter#141526)
2024-01-14 [email protected] Roll Flutter Engine from a0ac66ecaa2b to f20657354d8b (1 revision) (flutter/flutter#141518)
2024-01-13 [email protected] Roll Flutter Engine from b06478b70a2f to a0ac66ecaa2b (1 revision) (flutter/flutter#141498)
2024-01-13 [email protected] Roll Flutter Engine from 205ed6882a8f to b06478b70a2f (3 revisions) (flutter/flutter#141496)
2024-01-13 [email protected] Roll Flutter Engine from b8e5d4776908 to 205ed6882a8f (1 revision) (flutter/flutter#141492)
2024-01-12 [email protected] Roll Flutter Engine from 418c9e918a22 to b8e5d4776908 (7 revisions) (flutter/flutter#141489)
2024-01-12 [email protected] Added newline at end of `.gitignore` files (flutter/flutter#141270)
2024-01-12 49699333+dependabot[bot]@users.noreply.github.com Bump actions/upload-artifact from 4.0.0 to 4.1.0 (flutter/flutter#141480)
2024-01-12 [email protected] Fixed a lot of typos (flutter/flutter#141431)
2024-01-12 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Remove hack from PageView." (flutter/flutter#141479)
2024-01-12 [email protected] Roll Flutter Engine from 01e353544dd7 to 418c9e918a22 (2 revisions) (flutter/flutter#141474)
2024-01-12 [email protected] Roll Flutter Engine from 0ac8215c70ae to 01e353544dd7 (1 revision) (flutter/flutter#141470)
2024-01-12 [email protected] Roll Flutter Engine from ef2cf86c35a5 to 0ac8215c70ae (2 revisions) (flutter/flutter#141464)
2024-01-12 [email protected] unpin web_socket_channel and roll pub packages (flutter/flutter#141424)
2024-01-12 [email protected] FlutterExtension: make fields non-static (flutter/flutter#141463)
2024-01-12 [email protected] [deep link]  Update a gradle task to add flag check and intent filter check to the AppLinkSettings (flutter/flutter#141231)
2024-01-12 [email protected] Expose versionCode and versionName from local.properties in FlutterExtension (flutter/flutter#141417)
2024-01-12 [email protected] Roll Flutter Engine from a56f346dbbf9 to ef2cf86c35a5 (1 revision) (flutter/flutter#141456)
2024-01-12 [email protected] When Impeller is enabled for flutter tester choose correct shader target. (flutter/flutter#141391)
2024-01-12 [email protected] Remove hack from PageView. (flutter/flutter#141138)
2024-01-12 [email protected] Roll Flutter Engine from d0f9329c5ce4 to a56f346dbbf9 (6 revisions) (flutter/flutter#141451)
2024-01-12 [email protected] Adds support for StepStyle visual property bundle to the Step widget (flutter/flutter#140825)
2024-01-12 [email protected] Roll Flutter Engine from 44a0a6ee4d39 to d0f9329c5ce4 (1 revision) (flutter/flutter#141435)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
auto-submit Bot pushed a commit that referenced this pull request Jan 29, 2024
…142464)

This reverts commit f5ac225, i.e. #137115.

This is a continuation of #142266 that was redone based on feedback to make this easier to revert in the future. The exact steps I took to create this revert:

1. Revert commit noted above
2. Fix merge conflicts, that notably involved reverting some changes in #140744 ~and #141417 (fixed my merge to avoid the second PR from being affected)
3. Delete `packages/flutter_tools/test/integration.shard/android_plugin_skip_unsupported_test.dart` as this was added in the commit noted above

cc @Gustl22 since I couldn't tag as a reviewer
camsim99 added a commit to camsim99/flutter that referenced this pull request Jan 29, 2024
)" (flutter#142464)

This reverts commit f5ac225, i.e. flutter#137115.

This is a continuation of flutter#142266 that was redone based on feedback to make this easier to revert in the future. The exact steps I took to create this revert:

1. Revert commit noted above
2. Fix merge conflicts, that notably involved reverting some changes in flutter#140744 ~and flutter#141417 (fixed my merge to avoid the second PR from being affected)
3. Delete `packages/flutter_tools/test/integration.shard/android_plugin_skip_unsupported_test.dart` as this was added in the commit noted above

cc @Gustl22 since I couldn't tag as a reviewer
bartekpacia added a commit that referenced this pull request Apr 1, 2024
…nsion (#146044)

This PR is a follow-up of a previous PR of mine:
#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 #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 <[email protected]>
auto-submit Bot pushed a commit that referenced this pull request Apr 11, 2024
…ter.versionCode (#146604)

Follow up of #146044 and #141417

Minor change to make Gradle buildscripts shorter.
gilnobrega pushed a commit to gilnobrega/flutter that referenced this pull request Apr 22, 2024
…ter.versionCode (flutter#146604)

Follow up of flutter#146044 and flutter#141417

Minor change to make Gradle buildscripts shorter.
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
flutter/flutter@7dc856a...1a2c315

2024-01-14 [email protected] BoxPainter should dispatch creation and disposal events. (flutter/flutter#141526)
2024-01-14 [email protected] Roll Flutter Engine from a0ac66ecaa2b to f20657354d8b (1 revision) (flutter/flutter#141518)
2024-01-13 [email protected] Roll Flutter Engine from b06478b70a2f to a0ac66ecaa2b (1 revision) (flutter/flutter#141498)
2024-01-13 [email protected] Roll Flutter Engine from 205ed6882a8f to b06478b70a2f (3 revisions) (flutter/flutter#141496)
2024-01-13 [email protected] Roll Flutter Engine from b8e5d4776908 to 205ed6882a8f (1 revision) (flutter/flutter#141492)
2024-01-12 [email protected] Roll Flutter Engine from 418c9e918a22 to b8e5d4776908 (7 revisions) (flutter/flutter#141489)
2024-01-12 [email protected] Added newline at end of `.gitignore` files (flutter/flutter#141270)
2024-01-12 49699333+dependabot[bot]@users.noreply.github.com Bump actions/upload-artifact from 4.0.0 to 4.1.0 (flutter/flutter#141480)
2024-01-12 [email protected] Fixed a lot of typos (flutter/flutter#141431)
2024-01-12 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Remove hack from PageView." (flutter/flutter#141479)
2024-01-12 [email protected] Roll Flutter Engine from 01e353544dd7 to 418c9e918a22 (2 revisions) (flutter/flutter#141474)
2024-01-12 [email protected] Roll Flutter Engine from 0ac8215c70ae to 01e353544dd7 (1 revision) (flutter/flutter#141470)
2024-01-12 [email protected] Roll Flutter Engine from ef2cf86c35a5 to 0ac8215c70ae (2 revisions) (flutter/flutter#141464)
2024-01-12 [email protected] unpin web_socket_channel and roll pub packages (flutter/flutter#141424)
2024-01-12 [email protected] FlutterExtension: make fields non-static (flutter/flutter#141463)
2024-01-12 [email protected] [deep link]  Update a gradle task to add flag check and intent filter check to the AppLinkSettings (flutter/flutter#141231)
2024-01-12 [email protected] Expose versionCode and versionName from local.properties in FlutterExtension (flutter/flutter#141417)
2024-01-12 [email protected] Roll Flutter Engine from a56f346dbbf9 to ef2cf86c35a5 (1 revision) (flutter/flutter#141456)
2024-01-12 [email protected] When Impeller is enabled for flutter tester choose correct shader target. (flutter/flutter#141391)
2024-01-12 [email protected] Remove hack from PageView. (flutter/flutter#141138)
2024-01-12 [email protected] Roll Flutter Engine from d0f9329c5ce4 to a56f346dbbf9 (6 revisions) (flutter/flutter#141451)
2024-01-12 [email protected] Adds support for StepStyle visual property bundle to the Step widget (flutter/flutter#140825)
2024-01-12 [email protected] Roll Flutter Engine from 44a0a6ee4d39 to d0f9329c5ce4 (1 revision) (flutter/flutter#141435)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
bisor0627 pushed a commit to bisor0627/packages that referenced this pull request Jun 19, 2026
flutter/flutter@7dc856a...1a2c315

2024-01-14 [email protected] BoxPainter should dispatch creation and disposal events. (flutter/flutter#141526)
2024-01-14 [email protected] Roll Flutter Engine from a0ac66ecaa2b to f20657354d8b (1 revision) (flutter/flutter#141518)
2024-01-13 [email protected] Roll Flutter Engine from b06478b70a2f to a0ac66ecaa2b (1 revision) (flutter/flutter#141498)
2024-01-13 [email protected] Roll Flutter Engine from 205ed6882a8f to b06478b70a2f (3 revisions) (flutter/flutter#141496)
2024-01-13 [email protected] Roll Flutter Engine from b8e5d4776908 to 205ed6882a8f (1 revision) (flutter/flutter#141492)
2024-01-12 [email protected] Roll Flutter Engine from 418c9e918a22 to b8e5d4776908 (7 revisions) (flutter/flutter#141489)
2024-01-12 [email protected] Added newline at end of `.gitignore` files (flutter/flutter#141270)
2024-01-12 49699333+dependabot[bot]@users.noreply.github.com Bump actions/upload-artifact from 4.0.0 to 4.1.0 (flutter/flutter#141480)
2024-01-12 [email protected] Fixed a lot of typos (flutter/flutter#141431)
2024-01-12 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Remove hack from PageView." (flutter/flutter#141479)
2024-01-12 [email protected] Roll Flutter Engine from 01e353544dd7 to 418c9e918a22 (2 revisions) (flutter/flutter#141474)
2024-01-12 [email protected] Roll Flutter Engine from 0ac8215c70ae to 01e353544dd7 (1 revision) (flutter/flutter#141470)
2024-01-12 [email protected] Roll Flutter Engine from ef2cf86c35a5 to 0ac8215c70ae (2 revisions) (flutter/flutter#141464)
2024-01-12 [email protected] unpin web_socket_channel and roll pub packages (flutter/flutter#141424)
2024-01-12 [email protected] FlutterExtension: make fields non-static (flutter/flutter#141463)
2024-01-12 [email protected] [deep link]  Update a gradle task to add flag check and intent filter check to the AppLinkSettings (flutter/flutter#141231)
2024-01-12 [email protected] Expose versionCode and versionName from local.properties in FlutterExtension (flutter/flutter#141417)
2024-01-12 [email protected] Roll Flutter Engine from a56f346dbbf9 to ef2cf86c35a5 (1 revision) (flutter/flutter#141456)
2024-01-12 [email protected] When Impeller is enabled for flutter tester choose correct shader target. (flutter/flutter#141391)
2024-01-12 [email protected] Remove hack from PageView. (flutter/flutter#141138)
2024-01-12 [email protected] Roll Flutter Engine from d0f9329c5ce4 to a56f346dbbf9 (6 revisions) (flutter/flutter#141451)
2024-01-12 [email protected] Adds support for StepStyle visual property bundle to the Step widget (flutter/flutter#140825)
2024-01-12 [email protected] Roll Flutter Engine from 44a0a6ee4d39 to d0f9329c5ce4 (1 revision) (flutter/flutter#141435)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App d: examples Sample code and demos tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants