Skip to content

Fix: fix android studio 4.1 plugin path for macOS#69364

Merged
jonahwilliams merged 7 commits intoflutter:masterfrom
Mokusesei:fix-android-studio-4.1-plugin-path-for-mac
Nov 5, 2020
Merged

Fix: fix android studio 4.1 plugin path for macOS#69364
jonahwilliams merged 7 commits intoflutter:masterfrom
Mokusesei:fix-android-studio-4.1-plugin-path-for-mac

Conversation

@Mokusesei
Copy link
Contributor

@Mokusesei Mokusesei commented Oct 30, 2020

Description

Plugin path of android studio4.1 in MacOS has been changed(now is at HOME_DIR_PATH/Library/Application Support/Google/AndroidStudiox.x), which makes cmd 'flutter doctor' print wrong logs!

Related Issues

None yet!

Checklist

Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.

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

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

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Oct 30, 2020
@google-cla google-cla bot added the cla: yes label Oct 30, 2020
Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

This will need a test before we can submit it. The existing test file is https://github.com/flutter/flutter/blob/master/packages/flutter_tools/test/general.shard/android/android_studio_validator_test.dart. Though unfortunately we don't have any coverage of this code path yet :(

Ideally there would be two tests, one that looks up the < 4.1 path and one that looks up the > 4.1 path. This could be done by setting the platform the macOS using a FakePlatform(operatingSystem: 'macos') and then checking that the plugin path is correct for a given major/minor version

@Mokusesei
Copy link
Contributor Author

This will need a test before we can submit it. The existing test file is https://github.com/flutter/flutter/blob/master/packages/flutter_tools/test/general.shard/android/android_studio_validator_test.dart. Though unfortunately we don't have any coverage of this code path yet :(

Ideally there would be two tests, one that looks up the < 4.1 path and one that looks up the > 4.1 path. This could be done by setting the platform the macOS using a FakePlatform(operatingSystem: 'macos') and then checking that the plugin path is correct for a given major/minor version

Hi @jonahwilliams, thanks for your kind reply.
I have added two tests for my modified code in my latest commit. Actually, I just learn Flutter&&Dart for less than two months. it is my first time to write a dart test, and i'm not sure if it meets your requirements.please check carefully for me, thanks for your time.🙂

I also test my code in my own dev env(macOS):
on the stable channel, the flutter doctor shows:
image

on my modified channel, the flutter doctor works well again:
image

@Mokusesei Mokusesei force-pushed the fix-android-studio-4.1-plugin-path-for-mac branch from 0b2b39a to 0d6bf4d Compare November 2, 2020 08:51
'AndroidStudio$major.$minor',
);
/// plugin path of Android Studio has been changed after version 4.1.
if(double.parse('$major.$minor') >= 4.1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of concatenation these numbers parsing the string, check for the major and minor version separately:

(if major >= 4 && minor >= 1) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it!

'Application Support',
pathsSelectorValue,
);
: double.parse('$major.$minor') >= 4.1
Copy link
Contributor

Choose a reason for hiding this comment

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

The nested ternary expression is a big hard to read. I would break this up into an if (and use the separate major/minor checks like below):

String presetPluginsPath;
if (pathsSelectorValue != null) {
if (major >= 4 && minor >= 1) {
...
} else {
...
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it!

@jonahwilliams
Copy link
Contributor

This is looking great, just a few small comments!

);
});

testUsingContext('Can discover Android Studio >=4.1 location on Mac', () {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is kind of a nit, but the spacing in these tests makes them a bit hard to read. I would generally split up tests into 3 sections:

  1. creating objects/mocks and setting up state
  2. performing the action to be tested
  3. making expectations about the results

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is kind of a nit, but the spacing in these tests makes them a bit hard to read. I would generally split up tests into 3 sections:

  1. creating objects/mocks and setting up state
  2. performing the action to be tested
  3. making expectations about the results

Hi @jonahwilliams ,

The devil is in the detail. I really sorry for having overlooked the code style.
Thank you very much for your suggestion.It's this kind of suggestion that I strive for to help me keep improving.

Best wishes!😁

@jonahwilliams
Copy link
Contributor

You have a few minor analysis warnings that need to be cleaned up, otherwise it LGTM!

/b/s/w/ir/k/flutter/packages/flutter_tools/test/general.shard/android/android_studio_test.dart:120: trailing U+0020 space character
/b/s/w/ir/k/flutter/packages/flutter_tools/test/general.shard/android/android_studio_test.dart:126: trailing U+0020 space character
/b/s/w/ir/k/flutter/packages/flutter_tools/test/general.shard/android/android_studio_test.dart:144: trailing U+0020 space character
/b/s/w/ir/k/flutter/packages/flutter_tools/test/general.shard/android/android_studio_test.dart:159: trailing U+0020 space character

FileSystem: () => fileSystem,
FileSystemUtils: () => fsUtils,
ProcessManager: () => FakeProcessManager.any(),
// Custom home paths are not supported on macOS nor Windows yet,
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment actually seems wrong - this is testing mac right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comment actually seems wrong - this is testing mac right?

in fact, I don't have a wins pc to run this test. so i just copy this comment from other test case that in the same 'group' func (line 202).

@Mokusesei
Copy link
Contributor Author

You have a few minor analysis warnings that need to be cleaned up, otherwise it LGTM!

/b/s/w/ir/k/flutter/packages/flutter_tools/test/general.shard/android/android_studio_test.dart:120: trailing U+0020 space character
/b/s/w/ir/k/flutter/packages/flutter_tools/test/general.shard/android/android_studio_test.dart:126: trailing U+0020 space character
/b/s/w/ir/k/flutter/packages/flutter_tools/test/general.shard/android/android_studio_test.dart:144: trailing U+0020 space character
/b/s/w/ir/k/flutter/packages/flutter_tools/test/general.shard/android/android_studio_test.dart:159: trailing U+0020 space character

solved.

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM

@jonahwilliams
Copy link
Contributor

Thank you for the bug fix @Mokusesei , its much appreciated!

mraleph added a commit that referenced this pull request Nov 5, 2020
@mraleph
Copy link
Member

mraleph commented Nov 5, 2020

I am reverting due to crashes it causes: #69863

@mit-mit
Copy link
Member

mit-mit commented Nov 5, 2020

cc @Mokusesei

@Mokusesei
Copy link
Contributor Author

cc @Mokusesei

#69954 fixed

i'm so sorry for that.☕️

@mit-mit
Copy link
Member

mit-mit commented Nov 6, 2020

No problem @Mokusesei. Null errors are tricky to spot. This is a great real-world example of why we're adding null safety to Dart!

@Mokusesei
Copy link
Contributor Author

No problem @Mokusesei. Null errors are tricky to spot. This is a great real-world example of why we're adding null safety to Dart!

Yeah, I think I will get a huge buzz from that feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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