-
Notifications
You must be signed in to change notification settings - Fork 28.6k
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
base: master
Are you sure you want to change the base?
Resolve resolve native Flutter dependencies in Android Studio #167332
Conversation
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. |
It looks like this change caused test failures.
|
I am not sure, how I can fix the test yet. |
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.
Tests need to pass.
Blocking this so I can review it when it is ready.
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 Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
@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? |
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 That diff will also give you an idea what is required to make use of my change. |
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. |
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 |
} | ||
} | ||
} | ||
} catch (e: TaskInstantiationException) { | ||
// ignored |
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.
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.
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 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.
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.
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")) { |
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.
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.
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 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.
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.
@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.
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.
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.
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?
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.
Not yet, I can try it tomorrow on the CE, but I've no license for the ultimate edition.
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.
CE is sufficient
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 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)
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 Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
These changes appear to be failures to render anything. Not sure how this pr caused them (or if it did) |
Okay, I was already shocked how I broke that test :-D |
Ignoring the golden part of the test and just verifying if the app can run with your changes from I see
I think this is a real failure that is unrelated to your pr. |
I want to change the default template (from |
@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")) { |
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 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.
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.
@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?
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.
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)
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.
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.
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
andlocal.properteis
from theandroid
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:
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.
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.