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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

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
@reidbaker
Copy link
Contributor

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

These changes appear to be failures to render anything. Not sure how this pr caused them (or if it did)

@rekire
Copy link
Contributor Author

rekire commented May 5, 2025

Okay, I was already shocked how I broke that test :-D

@reidbaker
Copy link
Contributor

Ignoring the golden part of the test and just verifying if the app can run with your changes

from dev/integration_tests/android_engine_test run flutter run lib/external_texture/surface_producer_smiley_face_main.dart

I see

../../../packages/flutter/lib/src/semantics/semantics.dart:117:80: Error: The type 'SemanticsRole' is not exhaustively matched by the switch cases since it doesn't match 'SemanticsRole.searchBox'.
 - 'SemanticsRole' is from 'dart:ui'.
Try adding a wildcard pattern or cases that match 'SemanticsRole.searchBox'.
  static FlutterError? _checkSemanticsData(SemanticsNode node) => switch (node.role) {

I think this is a real failure that is unrelated to your pr.

@rekire
Copy link
Contributor Author

rekire commented May 7, 2025

I want to change the default template (from flutter create) to have the advantages also in fresh new projects. I am right now not sure if this should be part of the PR or if you prefer this as a second PR. My draft as diff to this PR is here: rekire#1, should I merge it into this PR? (of cause I need to make the tests pass before, this can be merged)

@reidbaker
Copy link
Contributor

@gmackall to review today.

@@ -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
Member

@gmackall gmackall May 19, 2025

Choose a reason for hiding this comment

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

Can you move this configuration to its own method (configureForTopLevelAndroidStudioSupport, or something similar), with docs explaining clearly the case that this configuration is done for?

The configuration is currently small anyways, but I want to make sure that if we add more in the future it doesn't end up leaking out across the FGP in a way that makes it hard to tell what is AS configuration only, and what is core logic of the FGP.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gmackall Where should I move it exactly? Just to the same level as the methods addFlutterDependencies() and addTaskForLockfileGeneration() with a couple of lines which explains the propose of adding those dependencies?

Copy link
Member

@gmackall gmackall May 19, 2025

Choose a reason for hiding this comment

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

Yes, just into its own class-level method, with a descriptive kdoc (and then you can leave the call site the same here. I just want the configuration encapsulated)

Copy link
Member

@gmackall gmackall left a comment

Choose a reason for hiding this comment

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

LGTM outside of the request to move to its own method.

I think we should hold off on adding the additional necessary build.gradle files to the templates until the feature gets some use - template changes are risky, so I'd like to only make that change that we have high confidence it is safe.

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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy