Skip to content

Resolve resolve native Flutter dependencies in Android Studio #167332

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

Conversation

rekire
Copy link
Contributor

@rekire rekire commented Apr 17, 2025

With this fix you can edit Flutter and native code in one Android Studio instance. This fixes #19830

The only downside is that you need to copy the files settings.gradle, build.gradle and local.properteis from the android folder to the project root folder. The last one should be added to the .gitignore file.

The second step is that you need to correct the path in the settings.gradle at the end is:

include ':app'

That needs to be replaced with:

include ':app'
project(':app').projectDir = new File(rootDir, 'android/app/')

The cool thing is if you have two flutter projects or another gradle module you can include them there too and you get the autocompletion too.

include ':app', ':app2', ':native-lib'
project(':app').projectDir = new File(rootDir, 'android/app/')
project(':app2').projectDir = new File(rootDir, 'app2/android/app/')
project(':native-lib').projectDir = new File(rootDir, 'example/native-lib/')

My assumption is that there will be some change requests and some questions. Feel free to ask

Pre-launch Checklist

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

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

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.If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions bot added platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. labels Apr 17, 2025
@camsim99 camsim99 requested review from reidbaker and gmackall and removed request for reidbaker April 22, 2025 18:14
@reidbaker
Copy link
Contributor

It looks like this change caused test failures.

execution failed for task ':app:preReleaseBuild'.
            > The following Android dependencies are set to compileOnly which is not supported:
              -> io.flutter:arm64_v8a_debug:1.0.0-eee1cffceea3b53287c8097679a9c868c4831330
              -> io.flutter:armeabi_v7a_debug:1.0.0-eee1cffceea3b53287c8097679a9c868c4831330
              -> io.flutter:flutter_embedding_debug:1.0.0-eee1cffceea3b53287c8097679a9c868c4831330
              -> io.flutter:x86_64_debug:1.0.0-eee1cffceea3b53287c8097679a9c868c4831330
              -> io.flutter:x86_debug:1.0.0-eee1cffceea3b53287c8097679a9c868c4831330

@rekire
Copy link
Contributor Author

rekire commented Apr 28, 2025

I am not sure, how I can fix the test yet.

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.

Tests need to pass.
Blocking this so I can review it when it is ready.

@rekire rekire marked this pull request as draft April 28, 2025 14:34
@flutter-dashboard
Copy link

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

For more guidance, visit Writing a golden file test for package:flutter.

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

@rekire rekire marked this pull request as ready for review May 3, 2025 12:29
@rekire
Copy link
Contributor Author

rekire commented May 3, 2025

@reidbaker I am not sure why some tests are red it changes on each master merge. Are the tests currently flaky or is it somehow my fault?

@rekire
Copy link
Contributor Author

rekire commented May 4, 2025

JFYI: I'm also working on migrating the default template to put the files at the right place. This also includes some fixes. I am not sure if I should make multiple PRs for that since I guess that will fix most likely two other bugs: rekire#1

Like that the .cxx is not on the ignore list or that you get the nasty "Missing ExternalProject for :" error.

That diff will also give you an idea what is required to make use of my change.

@reidbaker
Copy link
Contributor

The tests I saw when I made #167332 (comment) looked like it was caused by your change. That said if a test fails then passes and your code unrelated then consider it flakey.

@rekire
Copy link
Contributor Author

rekire commented May 5, 2025

I merge the master one time more. That test you mentioned failed because of my change. I fixed my code so that test is green. Let's wait for the CI if I get all tests passed. (Actually I would prefer just to rerun the failed test to verify my flakiness assumption, but I don't have the permission)

What do you think should I change the project creation template within this PR?

What is the right way to make sure that the result of the current template won't break, when my changes become the default? My aimed "big" change is that the settings.gradle.kts and the local.properties file should move from the android to the project root directory.

}
}
}
} catch (e: TaskInstantiationException) {
// ignored
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this safe to ignore? We use lockfiles in our own ci and having the generation fail without creating lockfiles would break our process.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That just happens when the task is registered twice which, can just happen when you have two flutter modules in your project (like a plugin). I tried to check if that task is already registered, but that caused some strange class cast exceptions in gradle, so I choose (without knowing a better solution) to ignore that special exception.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK that seems safe to ignore. If I have time I can see if we can check if we ahve already applied the plugin which would catch the issue before the exception but you dont need to do that.

@@ -97,6 +98,13 @@ class FlutterPlugin : Plugin<Project> {
repositories.maven {
url = uri(repository!!)
}
if (plugins.hasPlugin("com.android.application") && hasProperty("android.injected.invoked.from.ide")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Where did you find "android.injected.invoked.from.ide"? I would like to read the source/documentation.

In general we dont do ide specific code in our plugin but from the string I cant tell if this is part of the api or something that is android studio specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found it on StackOverflow: https://stackoverflow.com/q/18824890 I just want to inject the dependencies for Android Studio in normal builds like the CLI or CI those dependencies are not relevant.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jwren Is there something equivalent for visual studio or something ide neutral you want this pr to include?
For now it is ok to leave this because I want @gmackall's opinion but I think we may ask that the check for android studio be removed to align with our philosophy of of shipping tools that are portable.

It also helps protect against bugs that only happen for users when they run from android studio. This is extra important because we do not have integration tests that require launch android studio and verifying the tooling works.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

If this change has been tested and seems to work then I am okay with it. Any other IDE neutral changes can be added as a follow on.

@rekire -- Thanks for this change. Did you check that this doesn't have any negative effects for Ultimate or Community?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not yet, I can try it tomorrow on the CE, but I've no license for the ultimate edition.

Copy link
Member

Choose a reason for hiding this comment

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

CE is sufficient

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested it with my new template and it worked as expected. I just had to click once on import gradle project or something similar which popped up on the right. I guess that is the default behavior. Visual Studio code seems not to break ether, however there I had no Kotlin support (most likely because I never installed those plugins)

@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

For more guidance, visit Writing a golden file test for package:flutter.

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

Changes reported for pull request #167332 at sha 645a016

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 5, 2025
sfshaza2 added a commit to flutter/website that referenced this pull request Jul 14, 2025
Related to [Resolve resolve native Flutter dependencies in Android
Studio](flutter/flutter#167332) and in
preparation of [Extend template to resolve Dart and
Kotlin](flutter/flutter#168490) to explain how
to use that fix to resolve [Can't resolve symbol io.flutter.plugin
dependency](flutter/flutter#19830)


## Presubmit checklist

- [ ] If this PR is not meant to land until a future stable release,
mark it as draft with an explanation.
- [x] This PR doesn't contain automatically generated corrections
(generated by 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
pronouns).
- [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: Shams Zakhour (ignore Sfshaza) <44418985+sfshaza2@users.noreply.github.com>
github-merge-queue bot pushed a commit that referenced this pull request Jul 23, 2025
… support (#172651)

I asked for this in this comment
#167332 (comment)
but the request may have been unclear, as the PR landed without the
change. Following up to structure based on my comment.

I want to avoid the configuration that is specific to this one use case
creeping out across the FGP and wider flutter tool if it doesn't need
to.

## 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].
- [x] 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

Co-authored-by: Gray Mackall <mackall@google.com>
azatech pushed a commit to azatech/flutter that referenced this pull request Jul 28, 2025
… support (flutter#172651)

I asked for this in this comment
flutter#167332 (comment)
but the request may have been unclear, as the PR landed without the
change. Following up to structure based on my comment.

I want to avoid the configuration that is specific to this one use case
creeping out across the FGP and wider flutter tool if it doesn't need
to.

## 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].
- [x] 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

Co-authored-by: Gray Mackall <mackall@google.com>
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2025
ksokolovskyi pushed a commit to ksokolovskyi/flutter that referenced this pull request Aug 19, 2025
… support (flutter#172651)

I asked for this in this comment
flutter#167332 (comment)
but the request may have been unclear, as the PR landed without the
change. Following up to structure based on my comment.

I want to avoid the configuration that is specific to this one use case
creeping out across the FGP and wider flutter tool if it doesn't need
to.

## 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].
- [x] 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

Co-authored-by: Gray Mackall <mackall@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. will affect goldens Changes to golden files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't resolve symbol io.flutter.plugin dependency
4 participants