Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add migrator to upgrade gradle version when conflict with Android Studio bundled Java version is detected #124085

Merged
merged 42 commits into from Apr 27, 2023

Conversation

gmackall
Copy link
Member

@gmackall gmackall commented Apr 4, 2023

This PR adds an android project migrator that checks the version of android studio and the version of gradle for conflicts, and upgrades to 7.4 if a conflict is detected. For more detail about the particular conflict, see #122376.

The PR also upgrades older gradle versions being used in integration testing to 7.4.

Fixes/related to: #122376 and #123636

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.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. f: integration_test The flutter/packages/integration_test plugin team Infra upgrades, team productivity, code health, technical debt. See also team: labels. tool Affects the "flutter" command-line tool. See also t: labels. labels Apr 4, 2023
@gmackall
Copy link
Member Author

gmackall commented Apr 4, 2023

Also cc'ing @jmagman as you reviewed/authored the migrator PRs I based this on, feel free to ignore if you don't think you are the right person to review the migrator portion of this PR.

///
/// For more info see the Gradle-Java compatibility matrix:
/// https://docs.gradle.org/current/userguide/compatibility.html
class GradleVersionConflictMigration extends ProjectMigrator {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: maybe GradleJavaVersionConflictMigration?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a better name, will change.

logger.printTrace('Android Studio version could not be detected, '
'skipping gradle version compatibility check.');
return;
} else if (_androidStudio!.version.compareTo(_androidStudioFlamingo) < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know we're short on time, but do we want to make this more general like comparing to a _currentAndroidStudioVersion or something we can easily change in the future? Not sure how this sort of migrator is typically handled.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am open to making it more general, the key pieces of information required are a table of "for each Android Studio version, what is the bundled jdk version" and "for each java version, what is the minimum gradle version required."

The second piece is covered in this table, but I could not easily find the first piece of information.

If we think it should be more general I can try to find that info, but would also understand if the answer is "we want this migrator to do less replacing, not more."

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. Just thought I'd mention it as a possibility!

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

Your test failure is #124128, try rebasing on #124139.

logger.printTrace('Android Studio version could not be detected, '
'skipping gradle version compatibility check.');
return;
} else if (_androidStudio!.version.compareTo(_androidStudioFlamingo) < 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Version handles comparison operators

Suggested change
} else if (_androidStudio!.version.compareTo(_androidStudioFlamingo) < 0) {
} else if (_androidStudio!.version < _androidStudioFlamingo) {

'skipping gradle version compatibility check.');
return;
} else if (_androidStudio!.version.compareTo(_androidStudioFlamingo) < 0) {
//Version of Android Studio is less than impacted version, no migration necessary.
Copy link
Member

Choose a reason for hiding this comment

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

I think you should trace this, also makes it easier to test.

}
final String existingVersionString = match[1]!;
final Version existingVersion = Version.parse(existingVersionString)!;
if (existingVersion.compareTo(_lowestSupportedGradleVersion) < 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (existingVersion.compareTo(_lowestSupportedGradleVersion) < 0) {
if (existingVersion < _lowestSupportedGradleVersion) {

final String existingVersionString = match[1]!;
final Version existingVersion = Version.parse(existingVersionString)!;
if (existingVersion.compareTo(_lowestSupportedGradleVersion) < 0) {
logger.printTrace('Conflict detected between versions of Android Studio '
Copy link
Member

Choose a reason for hiding this comment

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

I think the user should see this message in non-verbose mode so they have some hint about why it's happening?

Suggested change
logger.printTrace('Conflict detected between versions of Android Studio '
logger.printStatus('Conflict detected between versions of Android Studio '

if (existingVersion.compareTo(_lowestSupportedGradleVersion) < 0) {
logger.printTrace('Conflict detected between versions of Android Studio '
'and gradle, upgrading gradle version from $existingVersion to 7.4');
return _newVersionFullDependency;
Copy link
Member

Choose a reason for hiding this comment

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

I'm not familiar with the gradle properties files, is it possible there was leading whitespace (that mattered) before?

Copy link
Member Author

@gmackall gmackall Apr 4, 2023

Choose a reason for hiding this comment

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

I've changed the match so that we check for arbitrary whitespace at the start, and then so that we just replace the version number in the existing line. This will also stop us from overwriting the choice of either "bin" or "zip" at the end.

Comment on lines 68 to 71
} else {
//Version of gradle is already high enough, no migration necessary.
return line;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
} else {
//Version of gradle is already high enough, no migration necessary.
return line;
}
}
// Version of gradle is already high enough, no migration necessary.
return line;

@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
Copy link
Member

Choose a reason for hiding this comment

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

To confirm, you update these integration tests by letting the migrator actually run on them, not by editing it manually?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not - I made these changes before writing the migrator to see if it would cause any errors. I tested on some local projects, but it would be a good sanity check to let the migrator make these changes. I'll revert them locally and let the migrator handle and update with results.

Copy link
Member

Choose a reason for hiding this comment

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

It won't get everything, but a bunch of them will be covered/migrated by running the build tests shard locally:

$ SHARD=build_tests dart dev/bots/test.dart

To save time first comment out all the _flutterBuild* lines in _runExampleProjectBuildTests except one of the _flutterBuildApk lines:

await _flutterBuildApk(examplePath, release: false, additionalArgs: additionalArgs, verifyCaching: verifyCaching);

That way it doesn't build all the iOS, Linux, etc projects when you only need the Android ones.

Copy link
Member Author

@gmackall gmackall Apr 5, 2023

Choose a reason for hiding this comment

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

Thanks, I was trying to run them 1 by 1. I downgraded the integration test gradle versions back to their original state (6.7) and ran the tests using that command, and all of the tests that ran then returned to 7.4 as expected. I also tested it out with a couple of differently formatted versions (i.e. major, minor, patch -> major, minor, etc) because these cases were all exactly 6.7 to 7.4.

I'm still working on running the ones that weren't hit by this command

Copy link
Member Author

Choose a reason for hiding this comment

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

I can now confirm they all upgrade to what was already committed.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
gmackall pushed a commit to gmackall/flutter that referenced this pull request May 1, 2023
…roid Studio bundled Java version is detected (flutter#124085)"

This reverts commit eba2a52.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
auto-submit bot pushed a commit that referenced this pull request May 1, 2023
#125813)

�roid Studio bundled Java version is detected (#124085)"

This reverts commit eba2a52.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2023
auto-submit bot pushed a commit that referenced this pull request May 3, 2023
…droid Studio bundled Java version is detected (#125836)

This is an attempt to reland #124085.

Differences from this attempt and the last: 
1. Adds a check for null android studio versions and a test for this case.
2. Wraps the migrate code in a try-catch [per the suggestion here](https://github.com/flutter/flutter/pull/125728/files#r1181747899).

Old PR description:
This PR adds an android project migrator that checks the version of android studio and the version of gradle for conflicts, and upgrades to 7.4 if a conflict is detected. For more detail about the particular conflict, see #122376.

The PR also upgrades older gradle versions being used in integration testing to 7.4.

Fixes/related to: #122376 and #123636
gmackall added a commit to gmackall/flutter that referenced this pull request May 4, 2023
…droid Studio bundled Java version is detected (flutter#125836)

This is an attempt to reland flutter#124085.

Differences from this attempt and the last:
1. Adds a check for null android studio versions and a test for this case.
2. Wraps the migrate code in a try-catch [per the suggestion here](https://github.com/flutter/flutter/pull/125728/files#r1181747899).

Old PR description:
This PR adds an android project migrator that checks the version of android studio and the version of gradle for conflicts, and upgrades to 7.4 if a conflict is detected. For more detail about the particular conflict, see flutter#122376.

The PR also upgrades older gradle versions being used in integration testing to 7.4.

Fixes/related to: flutter#122376 and flutter#123636
gmackall added a commit to gmackall/flutter that referenced this pull request May 5, 2023
…droid Studio bundled Java version is detected (flutter#125836)

This is an attempt to reland flutter#124085.

Differences from this attempt and the last:
1. Adds a check for null android studio versions and a test for this case.
2. Wraps the migrate code in a try-catch [per the suggestion here](https://github.com/flutter/flutter/pull/125728/files#r1181747899).

Old PR description:
This PR adds an android project migrator that checks the version of android studio and the version of gradle for conflicts, and upgrades to 7.4 if a conflict is detected. For more detail about the particular conflict, see flutter#122376.

The PR also upgrades older gradle versions being used in integration testing to 7.4.

Fixes/related to: flutter#122376 and flutter#123636
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) a: text input Entering text in a text field or keyboard related problems autosubmit Merge PR when tree becomes green via auto submit App f: integration_test The flutter/packages/integration_test plugin framework flutter/packages/flutter repository. See also f: labels. team Infra upgrades, team productivity, code health, technical debt. See also team: labels. tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants