-
Notifications
You must be signed in to change notification settings - Fork 28.7k
Support host android apps with kts
gradle files for add to app
#156502
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
Support host android apps with kts
gradle files for add to app
#156502
Conversation
kts
gradle fileskts
gradle files
This comment was marked as outdated.
This comment was marked as outdated.
kts
gradle fileskts
gradle files for add to app
cc @craiglabenz No action needed, just that this is the latest on attempting to support host apps using kotlin gradle files. If I can land this it should be pretty simple to get a host app working with kotlin gradle files, just a couple line change that we can go over |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very nice change!
LGTM
…only asset in test
converting to draft till I get the new test passing locally |
Should be ready for review! Ended up making a number of changes for the testing:
|
I also isolated the changes that needed to be made to the new host app (that uses Kotlin gradle files) in a single commit, so here this is the diff that users will need to make: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see anything wrong. LGTM
Really happy to see this change being made.
// Set of Material typography styles to start with | ||
val Typography = Typography( | ||
bodyLarge = TextStyle( | ||
fontFamily = FontFamily.Default, | ||
fontWeight = FontWeight.Normal, | ||
fontSize = 16.sp, | ||
lineHeight = 24.sp, | ||
letterSpacing = 0.5.sp | ||
) | ||
/* Other default text styles to override | ||
titleLarge = TextStyle( | ||
fontFamily = FontFamily.Default, | ||
fontWeight = FontWeight.Normal, | ||
fontSize = 22.sp, | ||
lineHeight = 28.sp, | ||
letterSpacing = 0.sp | ||
), | ||
labelSmall = TextStyle( | ||
fontFamily = FontFamily.Default, | ||
fontWeight = FontWeight.Medium, | ||
fontSize = 11.sp, | ||
lineHeight = 16.sp, | ||
letterSpacing = 0.5.sp | ||
) | ||
*/ | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was part of the output of the AS app templates, removed
def flutterProjectRoot = null | ||
if (!getBinding().getVariables().containsKey("gradle")) { | ||
gradle = this | ||
flutterProjectRoot = gradle.buildscript.getSourceFile().getParentFile().getParentFile().absolutePath | ||
} else { | ||
gradle = getBinding().getVariables().get("gradle") | ||
def scriptFile = getClass().protectionDomain.codeSource.location.toURI() | ||
flutterProjectRoot = new File(scriptFile).parentFile.parentFile.absolutePath | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a comment here would be nice, describing when each case happens.
basically this from OP:
setBinding isn't part of the Kotlin gradle DSL, and there isn't (that I can find) an easy Kotlin equivalent. If this binding isn't set, the reference to gradle in include_flutter.groovy is wrong, which breaks the script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, added!
Trying to figure out why the |
@@ -54,14 +54,14 @@ const String oneMajorVersionHigherJavaVersion = '23'; | |||
// | |||
// Supported here means supported by the tooling for | |||
// flutter analyze --suggestions and does not imply broader flutter support. | |||
const String maxKnownAndSupportedGradleVersion = '8.7'; | |||
const String maxKnownAndSupportedGradleVersion = '8.10'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are point releases significant here? I.e. will using 8.10.2
result in some warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops! That was on the wrong branch, should be on #157032. Thanks for pointing it out!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the answer to the question by the way is that yes they are significant based on the current implementation, and I'll want to figure out how we handle patch versions for that PR because I don't think the current implementation really expresses what we want it to.
I suspect that the correct way to handle them is to basically make the max known and supported 8.10.99
for example, because I don't think we will want to update that value for each patch version, and it's probably fine to just automatically assume new patch versions for a known minor version are supported.
But that is a question for that other PR!
This reverts commit 76baafd.
…tter#156502) Allows applying of `include_flutter.groovy` via the `apply from:` syntax, which allows using a host app that is using the Gradle Kotlin DSL (the default these days when creating an Android app in AS). Explanation: The `include_flutter.groovy` script is currently not able to be called by Kotlin gradle files, because it is [intended to be invoked with the following lines](https://docs.flutter.dev/add-to-app/android/project-setup#depend-on-the-modules-source-code): ``` setBinding(new Binding([gradle: this])) // new evaluate(new File( // new settingsDir.parentFile, // new 'flutter_module/.android/include_flutter.groovy' // new )) ``` `setBinding` isn't part of the Kotlin gradle DSL, and there isn't (that I can find) an easy Kotlin equivalent. If this binding isn't set, the reference to `gradle` in `include_flutter.groovy` is wrong, which breaks the script. This PR modifies `include_flutter.groovy` to also support being invoked through the standard way of invoking a script via the Gradle Groovy/Kotlin DSLs, which is `apply from:` (or it's slightly different Kotlin syntax). The start of the script identifies which of the two approaches is being used by checking if the binding is set, and then initializes some variables differently depending on the case. If we land this, I believe we should update the example Gradle files for both the `kts` and `groovy` cases to prefer the `apply from` syntax as I think this is the syntax most developers would be more familiar with already seeing in their Gradle files.
Failed to create CP due to merge conflicts. |
…tter#156502) Allows applying of `include_flutter.groovy` via the `apply from:` syntax, which allows using a host app that is using the Gradle Kotlin DSL (the default these days when creating an Android app in AS). Explanation: The `include_flutter.groovy` script is currently not able to be called by Kotlin gradle files, because it is [intended to be invoked with the following lines](https://docs.flutter.dev/add-to-app/android/project-setup#depend-on-the-modules-source-code): ``` setBinding(new Binding([gradle: this])) // new evaluate(new File( // new settingsDir.parentFile, // new 'flutter_module/.android/include_flutter.groovy' // new )) ``` `setBinding` isn't part of the Kotlin gradle DSL, and there isn't (that I can find) an easy Kotlin equivalent. If this binding isn't set, the reference to `gradle` in `include_flutter.groovy` is wrong, which breaks the script. This PR modifies `include_flutter.groovy` to also support being invoked through the standard way of invoking a script via the Gradle Groovy/Kotlin DSLs, which is `apply from:` (or it's slightly different Kotlin syntax). The start of the script identifies which of the two approaches is being used by checking if the binding is set, and then initializes some variables differently depending on the case. If we land this, I believe we should update the example Gradle files for both the `kts` and `groovy` cases to prefer the `apply from` syntax as I think this is the syntax most developers would be more familiar with already seeing in their Gradle files.
…tter#156502) Allows applying of `include_flutter.groovy` via the `apply from:` syntax, which allows using a host app that is using the Gradle Kotlin DSL (the default these days when creating an Android app in AS). Explanation: The `include_flutter.groovy` script is currently not able to be called by Kotlin gradle files, because it is [intended to be invoked with the following lines](https://docs.flutter.dev/add-to-app/android/project-setup#depend-on-the-modules-source-code): ``` setBinding(new Binding([gradle: this])) // new evaluate(new File( // new settingsDir.parentFile, // new 'flutter_module/.android/include_flutter.groovy' // new )) ``` `setBinding` isn't part of the Kotlin gradle DSL, and there isn't (that I can find) an easy Kotlin equivalent. If this binding isn't set, the reference to `gradle` in `include_flutter.groovy` is wrong, which breaks the script. This PR modifies `include_flutter.groovy` to also support being invoked through the standard way of invoking a script via the Gradle Groovy/Kotlin DSLs, which is `apply from:` (or it's slightly different Kotlin syntax). The start of the script identifies which of the two approaches is being used by checking if the binding is set, and then initializes some variables differently depending on the case. If we land this, I believe we should update the example Gradle files for both the `kts` and `groovy` cases to prefer the `apply from` syntax as I think this is the syntax most developers would be more familiar with already seeing in their Gradle files.
_Description of what this PR is changing or adding, and why:_ Improves and adds documentation for launching Flutter from Kotlin and Compose-flavored Android apps _Issues fixed by this PR (if any):_ _PRs or commits this PR depends on (if any):_ Depends on flutter/flutter#156502. Must either use the `master` channel or `stable` after that code reaches it. Changes can be previewed on the staging built at these URLs: * [`/add-to-app/android/project-setup`](https://flutter-docs-prod--pr11345-launch-flutter-from-compose-wlgslbu8.web.app/add-to-app/android/project-setup) * [`/add-to-app/android/add-flutter-screen`](https://flutter-docs-prod--pr11345-launch-flutter-from-compose-wlgslbu8.web.app/add-to-app/android/add-flutter-screen) ## Presubmit checklist - [x] This PR is marked as draft with an explanation if not meant to land until a future stable release. - [x] This PR doesn’t contain automatically generated corrections (Grammarly or similar). - [x] This PR follows the [Google Developer Documentation Style Guidelines](https://developers.google.com/style) — for example, it doesn’t use _i.e._ or _e.g._, and it avoids _I_ and _we_ (first person). - [x] This PR uses [semantic line breaks](https://github.com/dart-lang/site-shared/blob/main/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks) of 80 characters or fewer. --------- Co-authored-by: Khanh Nguyen <[email protected]>
Allows applying of
include_flutter.groovy
via theapply from:
syntax, which allows using a host app that is using the Gradle Kotlin DSL (the default these days when creating an Android app in AS).Explanation: The
include_flutter.groovy
script is currently not able to be called by Kotlin gradle files, because it is intended to be invoked with the following lines:setBinding
isn't part of the Kotlin gradle DSL, and there isn't (that I can find) an easy Kotlin equivalent. If this binding isn't set, the reference togradle
ininclude_flutter.groovy
is wrong, which breaks the script.This PR modifies
include_flutter.groovy
to also support being invoked through the standard way of invoking a script via the Gradle Groovy/Kotlin DSLs, which isapply from:
(or it's slightly different Kotlin syntax). The start of the script identifies which of the two approaches is being used by checking if the binding is set, and then initializes some variables differently depending on the case.If we land this, I believe we should update the example Gradle files for both the
kts
andgroovy
cases to prefer theapply from
syntax as I think this is the syntax most developers would be more familiar with already seeing in their Gradle files.Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.