Skip to content

Conversation

@flutteractionsbot
Copy link

@flutteractionsbot flutteractionsbot commented Oct 30, 2024

This pull request is created by automatic cherry pick workflow
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.

Issue Link:

What is the link to the issue this cherry-pick is addressing?

This allows host Android apps using Kotlin Gradle files to depend on a Flutter module as source, see
https://docs.flutter.dev/add-to-app/android/project-setup#add-the-flutter-module-as-a-dependency.

Previously they wouldn't be able to, because we expected the host app to use setBinding in it's Gradle files, which is Groovy syntax that doesn't have a parallel in the Kotlin Gradle DSL. They could still depend on a flutter module if built as an aar.

Changelog Description:

Explain this cherry pick in one line that is accessible to most Flutter developers. See best practices for examples

Allows host Android apps using Kotlin Gradle files to include a Flutter module.

Impact Description:

What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)? Does it impact development (ex. flutter doctor crashes when Android Studio is installed), or the shipping production app (the app crashes on launch)

Without this change, Android apps using Kotlin Gradle files are unable to depend on a Flutter module as source (they would still be able to as an aar).

Workaround:

Is there a workaround for this issue?

Build the flutter module as an aar.

Risk:

What is the risk level of this cherry-pick?

  • Low
  • Medium
  • High

Test Coverage:

Are you confident that your fix is well-tested by automated tests?

  • Yes
  • No

Validation Steps:

What are the steps to validate that this fix works?

Create a new Android app (probably in Android studio).
Create a Flutter module (flutter create foobar --template=module).
Apply this diff, matching names to your specific case, to the Android app.

…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.
@flutteractionsbot flutteractionsbot added the cp: review Cherry-picks in the review queue label Oct 30, 2024
@flutteractionsbot

This comment was marked as resolved.

@github-actions github-actions bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Oct 30, 2024
@gmackall
Copy link
Member

cc @craiglabenz

@gmackall gmackall requested a review from a team October 30, 2024 20:55
@itsjustkevin itsjustkevin added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 5, 2024
@auto-submit auto-submit bot merged commit 31c0ff4 into flutter:flutter-3.27-candidate.0 Nov 5, 2024
127 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 12, 2024
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 cp: review Cherry-picks in the review queue tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants