Skip to content

Conversation

@camsim99
Copy link
Contributor

@camsim99 camsim99 commented Oct 25, 2021

Logs a warning when Flutter project's Android SDK version is below that of a plugin the project has as a dependency. This will be needed as plugin compileSdkVersions are bumped to support Android S+.

Fixes #91771

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Oct 25, 2021
@google-cla google-cla bot added the cla: yes label Oct 25, 2021
@camsim99 camsim99 changed the title [WIP] Add warning for bumping Android SDK version to match plugins Add warning for bumping Android SDK version to match plugins Oct 25, 2021
@camsim99 camsim99 marked this pull request as ready for review October 25, 2021 23:52
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@camsim99 camsim99 requested a review from blasten October 25, 2021 23:57
Copy link

Choose a reason for hiding this comment

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

I think we would need to get the max compileSdkVersion for each plugin, then check if it's grater than the project's compileSdkVersion.

Copy link
Contributor Author

@camsim99 camsim99 Oct 26, 2021

Choose a reason for hiding this comment

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

I assume you mean versus warning for each plugin whose compileSdkVersion is larger?

Copy link

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

nit: if plugin A requires 31 and plugin B requires 32, the app should bump to 32. what do you think about printing a single message at the end?

Copy link

Choose a reason for hiding this comment

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

note that since the message is generated from Gradle, the error message that we would (otherwise) add to this dart file isn't necessary

Comment on lines 423 to 432
Copy link

Choose a reason for hiding this comment

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

This is what I was thinking:

int maxPluginCompileSdkVersion = project.android.compileSdkVersion // TODO parse as int.
int processedPlugins = getPluginList().size()
getPluginList().each { plugin ->
    Project pluginProject = project.rootProject.findProject(plugin.key)
    pluginProject.afterEvaluate {
       int pluginCompileSdkVersion = pluginProject.android.compileSdkVersion // TODO parse as int.
       maxPluginCompileSdkVersion = max(maxPluginCompileSdkVersion, pluginCompileSdkVersion)

       processedPlugins--
       if (processedPlugins == 0) {
          if (maxPluginCompileSdkVersion > project.android.compileSdkVersion) {
             // Print error message.
          }
       }
    }
}

android {
compileSdkVersion 30
compileSdkVersion 31
Copy link

Choose a reason for hiding this comment

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

was there an issue with the current compileSdkVersion?

Copy link
Contributor Author

@camsim99 camsim99 Nov 5, 2021

Choose a reason for hiding this comment

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

Yeah, this test is looking for a specific failure, and without bumping this version, my error was given before giving the failure expected

Copy link

Choose a reason for hiding this comment

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

cool, but the test was still passing, right? Your PR is mostly adding more errors to the stderr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, the test was failing. @GaryQian can you provide some more context here?

], workingDirectory: projectAppDir.path);

// Check error message is thrown
final RegExp charactersToIgnore = RegExp(r'\|/|[\n]');
Copy link

Choose a reason for hiding this comment

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

nit: these characaters are also valid in the test. It could use Dart multiline strings if that is easier. e.g.

contains('''One or more plugins require a higher Android SDK version.

Fix this issue by adding the following to ${projectGradleFile.path}:

android {
   compileSdkVersion 31
}
''')

@blasten blasten requested a review from GaryQian November 5, 2021 19:29
Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

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

LGTM % nit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.

Enforce compileSdkVersion set in a plugin

4 participants