Skip to content

Conversation

@ralph-bergmann
Copy link

Uses the version property from the pubspec.yaml file to set the corresponding fields in the app/build.gradle file respectively in the Info.plist file.

The --build-name and --build-number options have change. Now they modify the pubspec.yaml file.

The build command reads at built-time the version property from the pubspec.yaml file.

If the version property is not set the build command will not change the app/build.gradle / Info.plist file.

@mit-mit
Copy link
Member

mit-mit commented Apr 25, 2018

cc @mravn-google

@MisterJimson
Copy link

Great idea!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not rethrow? If their manifest is invalid and can't be parsed, it seems like we should surface that and halt the build.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tvolkert In my first version, I called completer.completeError('test error') with the result that Flutter crashed:

$ flutter build apk --build-name=1.0.3 --build-number=3
Update version in pubspec.yaml...                            0,1s
Set version in app/build.gradle...                           0,0s

Oops; flutter has exited unexpectedly: "test error".
Sending crash report to Google.
Crash report sent (report ID: da9511e51bac8867)
Crash report written to /Volumes/Archiv/hello/flutter_01.log;
please let us know at https://github.com/flutter/flutter/issues.

How can I break the build without crashing Flutter?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can complete with a ToolExit error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we want to cause the build to fail, but yes, without the "flutter has exited unexpectedly" flow 😃

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to use a Completer any more -- you're async now.

In review comments below, I suggest a new use for a completer, but even then, I think you should await the completer's future in the body of this method, but not return the completer's future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should '' be '.'? Can you add a test that exercises this path?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The onDone callback won't by awaited by default (its signature returns void). You'll need to create a Completer<void> to signal when it finishes, then await that completer's future below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes with onError (but it should probably complete with an error)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're async - no need for a completer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future<void>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future<void>

Copy link
Author

@ralph-bergmann ralph-bergmann Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tvolkert what is the difference between Future<Null> and Future<void>?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code herein looks very similar to that in gradle.dart -- seems like there's an opportunity to refactor so they share some common code?

@mravn-google
Copy link
Contributor

mravn-google commented Apr 25, 2018

I'm concerned about having Flutter tooling modify user-edited files of the platform-specific project folders, android/ and ios/.

These parts of a Flutter project are generally intended to be edited by the Flutter user, not Flutter tooling. It is already a problem that Flutter tooling is forced to make assumptions about the contents of these folders (as evidenced by the difficulty of adding Flutter to an existing app). Automatically updating user-edited files is not an easy business (as evidenced by the complexity of the code of this PR) and even when done correctly, it can easily confuse the user, e.g. in relation to the git status of files.

For plugin support, Flutter tooling generates files in the platform-specific folders and automatically overwrite those on pubspec.yaml changes. These files are not meant to be user-edited. Instead, we have defined the project templates such that the provided Gradle and Cocoapods scripts read from the generated files, rather than having Flutter tooling update the scripts. I suggest emulating that approach.

Copy link
Contributor

@mravn-google mravn-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid having Flutter tools modify user-edited build scripts. The build script templates in the flutter_tools package could instead be updated to make the scripts read information provided elsewhere.

@ralph-bergmann
Copy link
Author

For the Android part, I can add a version.properties file and use it's value in the app/build.gradle file to set version etc.

But I have no idea how to do that for iOS. On the other hand, for iOS I use the xcodebuild command line tool (provided by Apple) to change this value. Is it okay for you to use the xcodebuild tool or do you want a "don't modify project files" way for iOS too?

@mravn-google
Copy link
Contributor

On iOS, Flutter tooling already writes ios/Flutter/Generated.xcconfig and the properties of that file are then available to Xcode. We read them in the custom Xcode build script provided with Flutter tooling, as well as in the iOS project template, e.g. here.

@mravn-google
Copy link
Contributor

On Android, we communicate information via android/local.properties instead.

Copy link
Contributor

@tvolkert tvolkert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops - wrong PR 😃

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why will run ignore it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is deprecated when I'm done with refactoring suggested by mravn-google

@Hixie
Copy link
Contributor

Hixie commented Apr 28, 2018

You may be interested in this TODO as well:

// TODO(ianh): Get this from the embedder somehow.

@ralph-bergmann ralph-bergmann force-pushed the add_version_to_pubspec branch 2 times, most recently from f061775 to 3940cd0 Compare April 30, 2018 20:09
@ralph-bergmann
Copy link
Author

@mravn-google @tvolkert I refactored my PR, please have a look

@Hixie I didn't found an excellent way to solve https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/about.dart#L490. But maybe with #16934, we have a developer-friendly way to set the version?

@Hixie
Copy link
Contributor

Hixie commented May 1, 2018

Yeah I wasn't sure how to fix it either :-)

@ralph-bergmann
Copy link
Author

Some PRs ago (#15788) I added the --build-name and --build-number option to the flutter build ios/apk command.

I'm not so sure if it is now the right place because these options are now modifying the pubspec.yaml file independent from the build process.

I thought about to move them to the flutter config command, but this is to configure Flutter itself and not to configure a Flutter project?

What do you think?

@ralph-bergmann
Copy link
Author

@mravn-google @tvolkert friendly reminder :-)

@mravn-google
Copy link
Contributor

Some PRs ago (#15788) I added the --build-name and --build-number option to the flutter build ios/apk command.
I'm not so sure if it is now the right place because these options are now modifying the pubspec.yaml file independent from the build process.
I thought about to move them to the flutter config command, but this is to configure Flutter itself and not to configure a Flutter project?

I would prefer the source of truth, and flow of information from there, to be crystal clear. I see pubspec.yaml as a source of truth, to be modified only by the programmer, manually. So I'd support reverting #15788.

@ralph-bergmann
Copy link
Author

@mravn-google we use the --build-number flag for our CI builds to increase the build number automatically every time our CI builds a new version. I know there are other ways to do that for iOS with the help of Fastlane and I can modify the build.gradle file to do that for Android too.

But at the end, it looks like we have two separate apps and in my opinion, it is one app, a Flutter app. So for me, it looks strange to do it the old/native way instead of creating a new Flutter way.

@mravn-google
Copy link
Contributor

I agree that we should do it the Flutter way, considering it a single app.

A build number set by CI is most likely not something you'd want to check into source control, since CI is often itself triggered by a check in.

That would mean the build number cannot be part of pubspec.yaml. It could be given to flutter build as a CLI argument and relayed to Gradle and Xcode via the existing channels for transient information: Generated.xcconfig, local.properties, environment variables.

The build name is of a different nature, and should be defined by version in pubspec.yaml.

@MisterJimson
Copy link

MisterJimson commented May 18, 2018 via email

@ralph-bergmann
Copy link
Author

ralph-bergmann commented May 18, 2018

How about:

  • developer has to change version: 1.0.0+1 in pubspec.yaml file manualy
  • version: 1.0.0+1 modifies the Android / iOS project files via android/local.properties / ios/Flutter/Generated.xcconfig on build time
  • if --build-name option is provided, Flutter uses its value as build name instead of the one from version: 1.0.0+1
  • if --build-number option is provided, Flutter uses its value as build number instead of the one from version: 1.0.0+1

@ralph-bergmann ralph-bergmann force-pushed the add_version_to_pubspec branch from 3940cd0 to 08e9b57 Compare May 21, 2018 00:07
@ralph-bergmann
Copy link
Author

@mravn-google I updated my commit

Now the flutter build apk/ios command uses the version property from the pubspec.yaml file to set the corresponding fields in the local.properties file respectively in the Generated.xcconfig file.

The --build-name and --build-number options have change. Now they overtrump the version property from the pubspec.yaml file. The pubspec.yaml file will not be modified.

If the version property is not set and the --build-name and --build-number options are not provided, the build command will not change the local.properties / Generated.xcconfig file.

@ralph-bergmann ralph-bergmann force-pushed the add_version_to_pubspec branch from 08e9b57 to ac835b5 Compare May 21, 2018 08:44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: wrap comments at 80

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: wrap comments at 80

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manifest can't be null here, so need to use ?.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manifest can't be null here, so need to use ?.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can omit the example since the template value serves as an example

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename the flutter build command flag to be --build-version to match this?

Copy link
Contributor

@tvolkert tvolkert May 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""
Both the version and the builder number may be overridden in flutter build by
specifying --build-name and --build-number, respectively.
"""

@ralph-bergmann ralph-bergmann force-pushed the add_version_to_pubspec branch 3 times, most recently from 937ff73 to 9f5df56 Compare May 28, 2018 20:50
@ralph-bergmann
Copy link
Author

Thank you for spending your time to review this :-)

@mravn-google
Copy link
Contributor

@tvolkert Can we merge this?

Uses the `version` property from the `pubspec.yaml` file to set the corresponding fields in the `local.properties` file respectively in the `Generated.xcconfig` file.

The `--build-name` and `--build-number` options have change. Now they overtrump the `version` property from the `pubspec.yaml` file.

If the `version` property is not set and the  `--build-name` and `--build-number` options are not provided, the build command will not change the `local.properties` / `Generated.xcconfig` file.
@ralph-bergmann ralph-bergmann force-pushed the add_version_to_pubspec branch from 9f5df56 to c7fe79c Compare May 30, 2018 12:36
@tvolkert
Copy link
Contributor

Yep!

@tvolkert tvolkert merged commit c65e9d1 into flutter:master May 30, 2018
@ralph-bergmann ralph-bergmann deleted the add_version_to_pubspec branch May 30, 2018 15:05
}
}

testUsingContext('extract build name and number from pubspec.yaml', () async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like these tests aren't hermetic - they're accessing the real file system and spawning processes against the real OS. That makes them subject to significantly more flakiness.

@the4thfloor will you please send a follow-up to move these to be hermetic (using the mock process manager and memory file system, etc.). For example, the tests above use testUsingOsxContext(), which sets up all the hermetic bindings:

testUsingContext(description, testMethod, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Platform: () => macOS,
FileSystem: () => fs,
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #18093

@gmcdowell
Copy link

updating of versionCode via 'flutter build apk --debug --build-number=2' does not stick.

I have tested on all channels and when run i witness the change to the local.properties file is in fact undertaken, however a subsequent gradle build step appears to revert to the value to 1 (default).

I initially suspected line 15 & 16 in the android/build.gradle file, however when I altered this to a new value, it was not reflected.

I've also been checking the generated output.json file in build/app/outputs/apk/debug/ and this is never updated.

I am trying to setup CD via fastlane into the App/Play Stores both of which require incremental build version identifiers.

Advice appreciated

@ralph-bergmann
Copy link
Author

Hi @gmcdowell,

I wrote a Medium article about it, see paragraph How to update an old Flutter project?

Do not hesitate to ask if there are still problems/questions.

Ralph

@gmcdowell
Copy link

gmcdowell commented Nov 1, 2018 via email

@gmcdowell
Copy link

gmcdowell commented Nov 1, 2018 via email

@ralph-bergmann
Copy link
Author

ralph-bergmann commented Nov 1, 2018

there was a discussion about if the change can modify the pubspec.yaml file or not, see #16857 (comment)

I will look into the other issue #23811

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants