@@ -69,6 +69,34 @@ class FlutterExtension {
6969
7070 /* * Allows to override the target file. Otherwise, the target is lib/main.dart. */
7171 String target
72+
73+ /* * The versionCode that was read from app's local.properties. */
74+ String flutterVersionCode = null
75+
76+ /* * The versionName that was read from app's local.properties. */
77+ String flutterVersionName = null
78+
79+ /* * Returns flutterVersionCode as an integer with error handling. */
80+ Integer versionCode () {
81+ if (flutterVersionCode == null ) {
82+ throw new GradleException (" flutterVersionCode must not be null." )
83+ }
84+
85+ if (! flutterVersionCode. isNumber()) {
86+ throw new GradleException (" flutterVersionCode must be an integer." )
87+ }
88+
89+ return flutterVersionCode. toInteger()
90+ }
91+
92+ /* * Returns flutterVersionName with error handling. */
93+ String versionName () {
94+ if (flutterVersionName == null ) {
95+ throw new GradleException (" flutterVersionName must not be null." )
96+ }
97+
98+ return flutterVersionName
99+ }
72100}
73101
74102// This buildscript block supplies dependencies for this file's own import
@@ -226,7 +254,28 @@ class FlutterPlugin implements Plugin<Project> {
226254 // Load shared gradle functions
227255 project. apply from : Paths . get(flutterRoot. absolutePath, " packages" , " flutter_tools" , " gradle" , " src" , " main" , " groovy" , " native_plugin_loader.groovy" )
228256
229- project. extensions. create(" flutter" , FlutterExtension )
257+ def extension = project. extensions. create(" flutter" , FlutterExtension )
258+ def localProperties = new Properties ()
259+ def localPropertiesFile = rootProject. file(" local.properties" )
260+ if (localPropertiesFile. exists()) {
261+ localPropertiesFile. withReader(" UTF-8" ) { reader ->
262+ localProperties. load(reader)
263+ }
264+ }
265+
266+ def flutterVersionCode = localProperties. getProperty(" flutter.versionCode" )
267+ if (flutterVersionCode == null ) {
268+ flutterVersionCode = " 1"
269+ }
270+ extension. flutterVersionCode = flutterVersionCode
271+
272+
273+ def flutterVersionName = localProperties. getProperty(" flutter.versionName" )
274+ if (flutterVersionName == null ) {
275+ flutterVersionName = " 1.0"
276+ }
277+ extension. flutterVersionName = flutterVersionName
278+
230279 this . addFlutterTasks(project)
231280
232281 // By default, assembling APKs generates fat APKs if multiple platforms are passed.
0 commit comments