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.
```diff
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:
```diff
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:
```diff
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.
Flutter Examples
This directory contains several examples of using Flutter. To run an example,
use flutter run inside that example's directory. See the getting started
guide to install the flutter tool.
For additional samples, see the
flutter/samples repo.
Available examples include:
-
Hello, world The hello world app is a minimal Flutter app that shows the text "Hello, world!"
-
Flutter gallery The flutter gallery app no longer lives in this repo. Please see the gallery repo.
-
Layers The layers vignettes show how to use the various layers in the Flutter framework. For details, see the layers README.
-
Platform Channel The platform channel app demonstrates how to connect a Flutter app to platform-specific APIs. For documentation, see https://flutter.dev/platform-channels/.
-
Platform Channel Swift The platform channel swift app is the same as platform channel but the iOS version is in Swift and there is no Android version.
Notes
Note on Gradle wrapper files in .gitignore:
Gradle wrapper files should normally be checked into source control. The example projects don't do that to avoid having several copies of the wrapper binary in the Flutter repo. Instead, the Gradle wrapper is injected by Flutter tooling, and the wrapper files are .gitignore'd to avoid making the Flutter repository dirty as a side effect of running the examples.