这是indexloc提供的服务,不要输入任何密码
Skip to content

Use Gradle KTS in new Android app projects by default (2nd try) #157195

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

Merged
merged 7 commits into from
Oct 22, 2024
Merged

Use Gradle KTS in new Android app projects by default (2nd try) #157195

merged 7 commits into from
Oct 22, 2024

Conversation

bartekpacia
Copy link
Member

This PR resolves #151166

This PR relands #154061

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].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@github-actions github-actions bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Oct 18, 2024
@bartekpacia bartekpacia requested review from gmackall and reidbaker and removed request for gmackall October 18, 2024 22:47
@bartekpacia bartekpacia marked this pull request as ready for review October 18, 2024 22:47
@bartekpacia
Copy link
Member Author

bartekpacia commented Oct 18, 2024

probably a good idea to rebase with master after #157196 lands

i.e. this PR depends on #157196 being on master

@@ -467,7 +467,19 @@ class AndroidProject extends FlutterProjectPlatform {
static final RegExp _androidNamespacePattern = RegExp('android {[\\S\\s]+namespace\\s*=?\\s*[\'"](.+)[\'"]');
static final RegExp _applicationIdPattern = RegExp('^\\s*applicationId\\s*=?\\s*[\'"](.*)[\'"]\\s*\$');
static final RegExp _imperativeKotlinPluginPattern = RegExp('^\\s*apply plugin\\:\\s+[\'"]kotlin-android[\'"]\\s*\$');
static final RegExp _declarativeKotlinPluginPattern = RegExp('^\\s*id\\s+[\'"]kotlin-android[\'"]\\s*\$');

/// Examples of strings that this regex matches:
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you, I really appreciate when we give examples next to regex expressions.

@gmackall
Copy link
Member

Updated branch to include #157196, LGTM if tests pass.

I checked post submits for the last merge, and it was just android_java11_dependency_smoke_tests/android_java17_dependency_smoke_tests and some tool integration tests failing. The tool integration tests are also getting run in presubmit and seem to be passing.

@gmackall gmackall added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 21, 2024
@bartekpacia
Copy link
Member Author

thanks @gmackall :)

I'll take a look at the failing tests in a minute.

Copy link
Contributor

auto-submit bot commented Oct 21, 2024

auto label is removed for flutter/flutter/157195, due to - The status or check suite Linux android_java17_dependency_smoke_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 21, 2024
Copy link
Contributor

@reidbaker reidbaker left a comment

Choose a reason for hiding this comment

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

Failures appear related to this pr.

To keep the default AGP version AGP version 8.1.0, download a compatible Java version
[2024-10-21 12:01:05.009001] [STDOUT] stderr: (Java 17 <= (Java 17 <= compatible Java version < Java 21) Java version < Java 21). Configure this Java version

@gmackall we dont have a java 21 version of these suite of tests yet, it looks like we will need to make one.

@gmackall
Copy link
Member

Yes, the latest android studio version vends Java 21 I believe, so it would be good to use that in CI

@bartekpacia
Copy link
Member Author

bartekpacia commented Oct 21, 2024

@reidbaker @gmackall Should I create a new PR that adds CI for java 21, then get it merged to master, and then come back to this PR?

@gmackall
Copy link
Member

gmackall commented Oct 21, 2024

Sorry for the confusion, my comment was independent of this PR - setting up java 21 tests in CI will probably require CIPD access anyways, which I believe is only available to Googlers, so we will take care of that (and I don't think it should block this PR).

That log indicates a problem that I believe I missed though:
the logs for this failing test
https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8733442600577716257/+/u/run_android_java11_dependency_smoke_tests/stdout

══╡ ••• Create new app with dependency versions: (AGP version: 7.0.1, Gradle version: 7.0.2, Kotlin version: 1.7.10, compileSdk version: 34) ••• ╞══
[2024-10-21 12:00:51.161782] [STDOUT] 
[2024-10-21 12:00:51.164051] [STDOUT] Found FLUTTER_LOGS_DIR dump directory /b/s/w/ir/x/w/rc/flutter_logs_dir
[2024-10-21 12:00:51.164346] [STDOUT] Executing "/b/s/w/ir/x/w/rc/tmpoelc13pa/flutter sdk/bin/flutter create dependency_checker_app --platforms=android --ci --debug-logs-dir=/b/s/w/ir/x/w/rc/flutter_logs_dir" in "/b/s/w/ir/x/t/flutter_android_dependency_version_testsAWDEOQ/7.0.2QDQNNN" with environment {BOT: true, LANG: en_US.UTF-8}
[2024-10-21 12:00:51.383044] [STDOUT] stdout: Creating project dependency_checker_app...
[2024-10-21 12:00:51.755288] [STDOUT] stdout: Resolving dependencies in `dependency_checker_app`...
[2024-10-21 12:00:52.373480] [STDOUT] stdout: Downloading packages...
[2024-10-21 12:00:52.389024] [STDOUT] stdout: Got dependencies in `dependency_checker_app`.
[2024-10-21 12:00:52.568869] [STDOUT] stdout: Wrote 35 files.
[2024-10-21 12:00:52.568977] [STDOUT] stdout: 
[2024-10-21 12:00:52.569010] [STDOUT] stdout: All done!
[2024-10-21 12:00:52.570876] [STDOUT] stdout: You can find general documentation for Flutter at: https://docs.flutter.dev//
[2024-10-21 12:00:52.570973] [STDOUT] stdout: Detailed API documentation is available at: https://api.flutter.dev//
[2024-10-21 12:00:52.571001] [STDOUT] stdout: If you prefer video documentation, consider: https://www.youtube.com/c/flutterdev
[2024-10-21 12:00:52.571033] [STDOUT] stdout: 
[2024-10-21 12:00:52.571135] [STDOUT] stdout: In order to run your application, type:
[2024-10-21 12:00:52.571177] [STDOUT] stdout: 
[2024-10-21 12:00:52.571206] [STDOUT] stdout:   $ cd dependency_checker_app
[2024-10-21 12:00:52.571231] [STDOUT] stdout:   $ flutter run
[2024-10-21 12:00:52.571263] [STDOUT] stdout: 
[2024-10-21 12:00:52.571294] [STDOUT] stdout: Your application code is in dependency_checker_app/lib/main.dart.
[2024-10-21 12:00:52.571322] [STDOUT] stdout: 
[2024-10-21 12:00:52.672703] [STDOUT] stderr: The configured version of Java detected may conflict with the Android Gradle Plugin (AGP) version in your new Flutter app.
[2024-10-21 12:00:52.672884] [STDOUT] stderr: 
[2024-10-21 12:00:52.672942] [STDOUT] stderr: To keep the default AGP version AGP version 8.1.0, download a compatible Java version
[2024-10-21 12:00:52.672979] [STDOUT] stderr: (Java 17 <= (Java 17 <= compatible Java version < Java 21) Java version < Java 21). Configure this Java version
[2024-10-21 12:00:52.673015] [STDOUT] stderr: globally for Flutter by running:
[2024-10-21 12:00:52.673046] [STDOUT] stderr: 
[2024-10-21 12:00:52.673184] [STDOUT] stderr:   flutter config --jdk-dir=<JDK_DIRECTORY>
[2024-10-21 12:00:52.673227] [STDOUT] stderr: 
[2024-10-21 12:00:52.673257] [STDOUT] stderr: 
[2024-10-21 12:00:52.673296] [STDOUT] stderr: Alternatively, to continue using your current Java version, update the AGP
[2024-10-21 12:00:52.673324] [STDOUT] stderr: version in the following file(s) to a compatible version (minimum compatible AGP version: 7.0):
[2024-10-21 12:00:52.673364] [STDOUT] stderr:     /b/s/w/ir/x/t/flutter_android_dependency_version_testsAWDEOQ/7.0.2QDQNNN/dependency_checker_app/android/build.gradle
[2024-10-21 12:00:52.673394] [STDOUT] stderr: 
[2024-10-21 12:00:52.673426] [STDOUT] stderr: For details on compatible Java and AGP versions, see
[2024-10-21 12:00:52.673457] [STDOUT] stderr: https://developer.android.com/build/releases/gradle-plugin

indicate that we aren't successfully setting the AGP version to 7.0.1 as the test intends. Let me take another look to see why this is

@gmackall
Copy link
Member

gmackall commented Oct 21, 2024

Ah, I see - that is just the warning from flutter create. Ignore the previous comment, I think that can be safely ignored because we are planning on overwriting the Gradle files anyways.

So in summary, I think you just need to fix the failures in the following log section, namely the part starting

[2024-10-21 12:00:49.029432] [STDOUT] stderr: FAILURE: Build failed with an exception.
[2024-10-21 12:00:49.029461] [STDOUT] stderr: 
[2024-10-21 12:00:49.029507] [STDOUT] stderr: * Where:
[2024-10-21 12:00:49.029544] [STDOUT] stderr: Settings file '/b/s/w/ir/x/t/flutter_android_dependency_version_testsZOXTQI/7.0.2GANUFY/dependency_checker_app/android/settings.gradle.kts' line: 2
[2024-10-21 12:00:49.029585] [STDOUT] stderr: 
[2024-10-21 12:00:49.029623] [STDOUT] stderr: * What went wrong:
[2024-10-21 12:00:49.029652] [STDOUT] stderr: Script compilation errors:
[2024-10-21 12:00:49.029684] [STDOUT] stderr: 
[2024-10-21 12:00:49.029712] [STDOUT] stderr:   Line 02:     def flutterSdkPath = {
[2024-10-21 12:00:49.029742] [STDOUT] stderr:                                   ^ Expecting an element
[2024-10-21 12:00:49.029775] [STDOUT] stderr: 
[2024-10-21 12:00:49.029803] [STDOUT] stderr:   Line 03:         def properties = new Properties()
[2024-10-21 12:00:49.029833] [STDOUT] stderr:                                   ^ Expecting an element
[2024-10-21 12:00:49.029864] [STDOUT] stderr: 
[2024-10-21 12:00:49.029892] [STDOUT] stderr:   Line 05:         def flutterSdkPath = properties.getProperty("flutter.sdk")
[2024-10-21 12:00:49.029920] [STDOUT] stderr:                                       ^ Expecting an element
[2024-10-21 12:00:49.029953] [STDOUT] stderr: 
[2024-10-21 12:00:49.029982] [STDOUT] stderr:   Line 05:         def flutterSdkPath = properties.getProperty("flutter.sdk")
[2024-10-21 12:00:49.037188] [STDOUT] stderr:                                                   ^ Expecting an element
[2024-10-21 12:00:49.037724] [STDOUT] stderr: 
[2024-10-21 12:00:49.039026] [STDOUT] stderr:   Line 06:         assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
[2024-10-21 12:00:49.039920] [STDOUT] stderr:                                          ^ Expecting an element
[2024-10-21 12:00:49.040246] [STDOUT] stderr: 
[2024-10-21 12:00:49.041363] [STDOUT] stderr:   Line 06:         assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
[2024-10-21 12:00:49.041575] [STDOUT] stderr:                                            ^ Unexpected tokens (use ';' to separate expressions on the same line)
[2024-10-21 12:00:49.042884] [STDOUT] stderr: 
[2024-10-21 12:00:49.042944] [STDOUT] stderr:   Line 06:         assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
[2024-10-21 12:00:49.043209] [STDOUT] stderr:                                                 ^ Unexpected tokens (use ';' to separate expressions on the same line)
[2024-10-21 12:00:49.043424] [STDOUT] stderr: 
[2024-10-21 12:00:49.044644] [STDOUT] stderr:   Line 20:     id "dev.flutter.flutter-plugin-loader" version "1.0.0"
[2024-10-21 12:00:49.045201] [STDOUT] stderr:                   ^ Unexpected tokens (use ';' to separate expressions on the same line)
[2024-10-21 12:00:49.045265] [STDOUT] stderr: 
[2024-10-21 12:00:49.046550] [STDOUT] stderr:   Line 21:     id "com.android.application" version "7.0.1" apply false
[2024-10-21 12:00:49.047067] [STDOUT] stderr:                   ^ Unexpected tokens (use ';' to separate expressions on the same line)
[2024-10-21 12:00:49.047336] [STDOUT] stderr: 
[2024-10-21 12:00:49.047971] [STDOUT] stderr:   Line 22:     id "org.jetbrains.kotlin.android" version "1.7.10" apply false
[2024-10-21 12:00:49.049283] [STDOUT] stderr:                   ^ Unexpected tokens (use ';' to separate expressions on the same line)

FYI you should be able to run these tests locally with

../../bin/cache/dart-sdk/bin/dart bin/test_runner.dart test -t android_java11_dependency_smoke_tests

run from

<flutter_root>/dev/devicelab

(and you'll probably want to comment all but one of them out from

List<VersionTuple> versionTuples = <VersionTuple>[
, as they can take a bit and you'll probably have fixed all of them once you fix one of them).

@bartekpacia
Copy link
Member Author

we are so back

@bartekpacia bartekpacia added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 22, 2024
@auto-submit auto-submit bot merged commit eb5ef69 into flutter:master Oct 22, 2024
136 checks passed
@bartekpacia bartekpacia deleted the bartekpacia/gradle_kotlin_by_default_2 branch October 22, 2024 19:48
M97Chahboun pushed a commit to M97Chahboun/flutter that referenced this pull request Oct 30, 2024
github-merge-queue bot pushed a commit that referenced this pull request Dec 6, 2024
…radle.kts usage (#159299)

update comments inside `flutter_build_preview_sdk_test.dart` to match
the usage of `build.gradle.kts` instead of `build.gradle`
those must've slipped from #157195
## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [x] 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].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

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

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 12, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change language of Gradle scripts in templates from Groovy to Kotlin
3 participants