Skip to content
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

[flutter_tools] Add namespace getter in Android project; use namespace as fallback #121416

Merged

Conversation

navaronbracke
Copy link
Contributor

@navaronbracke navaronbracke commented Feb 24, 2023

For newer Android projects the package attribute in the Manifest has been replaced with a namespace attribute under the android section of the build.gradle file.

List which issues are fixed by this PR. You must list at least one issue.
Fixes: #121404

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.
N/A

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • 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.
  • All existing and new tests are passing.

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

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Feb 24, 2023
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

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.

@navaronbracke
Copy link
Contributor Author

navaronbracke commented Feb 24, 2023

@christopherfujino Could you give me a hint for a test? I'd want to have a stub build.gradle with the namespace tag in it and a manifest without a package attribute. Then I'd try to build an apk and assert on the package identifier?

I just don't know how to do that exactly. Edit: I think I got it, except for a remaining expect()


expect(processManager, hasNoRemainingExpectations);

// TODO: verify the packageId of the built APK equals the namespace value
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this test verifies that building an APK using the namespace works, but I'd like to assert that the namespace value is also correct. Any tips on how to do that? Or is that not required (as the test already validates that the APK is built without errors)

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this test validates your change--I reverted your lib/src changes and this test still passes.

Can you test AndroidApk.fromAndroidProject()?

@@ -486,9 +487,15 @@ class AndroidProject extends FlutterProjectPlatform {
}

File get appManifestFile {
return isUsingGradle
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@christopherfujino I had mismatching results when originally running this test.
The fileSystem created in the test would report that the appManifestFile exists, but the globals.fs file system in this getter reported that it did not exist.

According to a doc comment I can override globals.fs in tests. I don't see the setUp((){}) doing something like that. What would be the right thing to do here?

A) Override globals.fs in the test
B) Fix the getter to use hostAppGradleRoot, which does use the fileSystem that was set up in the specific test (which is what I did here)

Copy link
Member

Choose a reason for hiding this comment

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

Good find. Looks like whatever test you copy-pasted this from was also leaking the real file system. The whole purpose of the testUsingContext() function you're calling is that it allows you to provide overrides to the Zone/context getters (globals.fs is essentially calling `context.get();).

Here is an example of constructing a FileSystem in setUp and then providing it as a context override for a testUsingContext invocation: https://github.com/flutter/flutter/blob/master/packages/flutter_tools/test/commands.shard/hermetic/build_test.dart#L60

Copy link
Member

Choose a reason for hiding this comment

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

although if it makes sense, what you did here is probably better (it looks cleaner)

Copy link
Contributor Author

@navaronbracke navaronbracke Mar 8, 2023

Choose a reason for hiding this comment

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

Thanks for the tip, I'll update the test with an override for the file system. I'll keep that in mind for the next time I need to write tests like this.

@navaronbracke
Copy link
Contributor Author

navaronbracke commented Mar 9, 2023

@christopherfujino fixed the test (forgot the activity tag, woops) and now it no longer hangs when running the tests.
I wonder why it hung in the first place, perhaps the huge amount of tests in flutter_tools has something to do with it?

Copy link
Member

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for sticking through, I know this was tricky to test.

Copy link
Contributor

@eliasyishak eliasyishak left a comment

Choose a reason for hiding this comment

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

👍

@eliasyishak eliasyishak added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 9, 2023
@auto-submit auto-submit bot merged commit 57171a3 into flutter:master Mar 9, 2023
@navaronbracke navaronbracke deleted the android_gradle_namespace_fix branch March 10, 2023 06:55
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 10, 2023
hangyujin pushed a commit to hangyujin/flutter that referenced this pull request Mar 11, 2023
…e as fallback (flutter#121416)

[flutter_tools] Add namespace getter in Android project; use namespace as fallback
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 11, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 12, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
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 tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flutter_tools] Support namespace attribute introduced in AGP 7.3
3 participants