Skip to content

Commit c2dc92c

Browse files
authored
Default to the newer version path when checking Android Studio Java path (flutter#101862)
1 parent 41b7389 commit c2dc92c

File tree

2 files changed

+86
-5
lines changed

2 files changed

+86
-5
lines changed

packages/flutter_tools/lib/src/android/android_studio.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,9 @@ class AndroidStudio implements Comparable<AndroidStudio> {
445445
}
446446

447447
final String javaPath = globals.platform.isMacOS ?
448-
version != null && version.major >= 2020 ?
449-
globals.fs.path.join(directory, 'jre', 'Contents', 'Home') :
448+
version != null && version.major < 2020 ?
450449
globals.fs.path.join(directory, 'jre', 'jdk', 'Contents', 'Home') :
450+
globals.fs.path.join(directory, 'jre', 'Contents', 'Home') :
451451
globals.fs.path.join(directory, 'jre');
452452
final String javaExecutable = globals.fs.path.join(javaPath, 'bin', 'java');
453453
if (!globals.processManager.canRun(javaExecutable)) {

packages/flutter_tools/test/general.shard/android/android_studio_test.dart

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ const Map<String, dynamic> macStudioInfoPlist2020_3 = <String, dynamic>{
5858
},
5959
};
6060

61+
const Map<String, dynamic> macStudioInfoPlistEAP = <String, dynamic>{
62+
'CFBundleGetInfoString': 'Android Studio EAP AI-212.5712.43.2112.8233820, build AI-212.5712.43.2112.8233820. Copyright JetBrains s.r.o., (c) 2000-2022',
63+
'CFBundleShortVersionString': 'EAP AI-212.5712.43.2112.8233820',
64+
'CFBundleVersion': 'AI-212.5712.43.2112.8233820',
65+
'JVMOptions': <String, dynamic>{
66+
'Properties': <String, dynamic>{
67+
'idea.vendor.name' : 'Google',
68+
'idea.paths.selector': 'AndroidStudio2021.2',
69+
'idea.platform.prefix': 'AndroidStudio',
70+
},
71+
},
72+
};
73+
6174
final Platform linuxPlatform = FakePlatform(
6275
environment: <String, String>{'HOME': homeLinux},
6376
);
@@ -135,6 +148,14 @@ void main() {
135148

136149
final String plistFilePath = globals.fs.path.join(studioInApplicationPlistFolder, 'Info.plist');
137150
plistUtils.fileContents[plistFilePath] = macStudioInfoPlist4_1;
151+
processManager.addCommand(FakeCommand(
152+
command: <String>[
153+
globals.fs.path.join(studioInApplicationPlistFolder, 'jre', 'jdk', 'Contents', 'Home', 'bin', 'java'),
154+
'-version',
155+
],
156+
stderr: '123',
157+
)
158+
);
138159
final AndroidStudio studio = AndroidStudio.fromMacOSBundle(
139160
globals.fs.directory(studioInApplicationPlistFolder)?.parent?.path,
140161
);
@@ -147,10 +168,11 @@ void main() {
147168
'Google',
148169
'AndroidStudio4.1',
149170
)));
171+
expect(studio.validationMessages, <String>['Java version 123']);
150172
}, overrides: <Type, Generator>{
151173
FileSystem: () => fileSystem,
152174
FileSystemUtils: () => fsUtils,
153-
ProcessManager: () => FakeProcessManager.any(),
175+
ProcessManager: () => processManager,
154176
// Custom home paths are not supported on macOS nor Windows yet,
155177
// so we force the platform to fake Linux here.
156178
Platform: () => platform,
@@ -168,6 +190,14 @@ void main() {
168190

169191
final String plistFilePath = globals.fs.path.join(studioInApplicationPlistFolder, 'Info.plist');
170192
plistUtils.fileContents[plistFilePath] = macStudioInfoPlist2020_3;
193+
processManager.addCommand(FakeCommand(
194+
command: <String>[
195+
globals.fs.path.join(studioInApplicationPlistFolder, 'jre', 'Contents', 'Home', 'bin', 'java'),
196+
'-version',
197+
],
198+
stderr: '123',
199+
)
200+
);
171201
final AndroidStudio studio = AndroidStudio.fromMacOSBundle(
172202
globals.fs.directory(studioInApplicationPlistFolder)?.parent?.path,
173203
);
@@ -180,10 +210,11 @@ void main() {
180210
'Google',
181211
'AndroidStudio2020.3',
182212
)));
213+
expect(studio.validationMessages, <String>['Java version 123']);
183214
}, overrides: <Type, Generator>{
184215
FileSystem: () => fileSystem,
185216
FileSystemUtils: () => fsUtils,
186-
ProcessManager: () => FakeProcessManager.any(),
217+
ProcessManager: () => processManager,
187218
// Custom home paths are not supported on macOS nor Windows yet,
188219
// so we force the platform to fake Linux here.
189220
Platform: () => platform,
@@ -201,6 +232,14 @@ void main() {
201232

202233
final String plistFilePath = globals.fs.path.join(studioInApplicationPlistFolder, 'Info.plist');
203234
plistUtils.fileContents[plistFilePath] = macStudioInfoPlist;
235+
processManager.addCommand(FakeCommand(
236+
command: <String>[
237+
globals.fs.path.join(studioInApplicationPlistFolder, 'jre', 'jdk', 'Contents', 'Home', 'bin', 'java'),
238+
'-version',
239+
],
240+
stderr: '123',
241+
)
242+
);
204243
final AndroidStudio studio = AndroidStudio.fromMacOSBundle(
205244
globals.fs.directory(studioInApplicationPlistFolder)?.parent?.path,
206245
);
@@ -212,10 +251,52 @@ void main() {
212251
'Application Support',
213252
'AndroidStudio3.3',
214253
)));
254+
expect(studio.validationMessages, <String>['Java version 123']);
215255
}, overrides: <Type, Generator>{
216256
FileSystem: () => fileSystem,
217257
FileSystemUtils: () => fsUtils,
218-
ProcessManager: () => FakeProcessManager.any(),
258+
ProcessManager: () => processManager,
259+
// Custom home paths are not supported on macOS nor Windows yet,
260+
// so we force the platform to fake Linux here.
261+
Platform: () => platform,
262+
PlistParser: () => plistUtils,
263+
});
264+
265+
testUsingContext('Can discover Android Studio EAP location on Mac', () {
266+
final String studioInApplicationPlistFolder = globals.fs.path.join(
267+
'/',
268+
'Application',
269+
'Android Studio with suffix.app',
270+
'Contents',
271+
);
272+
globals.fs.directory(studioInApplicationPlistFolder).createSync(recursive: true);
273+
274+
final String plistFilePath = globals.fs.path.join(studioInApplicationPlistFolder, 'Info.plist');
275+
plistUtils.fileContents[plistFilePath] = macStudioInfoPlistEAP;
276+
processManager.addCommand(FakeCommand(
277+
command: <String>[
278+
globals.fs.path.join(studioInApplicationPlistFolder, 'jre', 'Contents', 'Home', 'bin', 'java'),
279+
'-version',
280+
],
281+
stderr: '123',
282+
)
283+
);
284+
final AndroidStudio studio = AndroidStudio.fromMacOSBundle(
285+
globals.fs.directory(studioInApplicationPlistFolder)?.parent?.path,
286+
);
287+
288+
expect(studio, isNotNull);
289+
expect(studio.pluginsPath, equals(globals.fs.path.join(
290+
homeMac,
291+
'Library',
292+
'Application Support',
293+
'AndroidStudio2021.2',
294+
)));
295+
expect(studio.validationMessages, <String>['Java version 123']);
296+
}, overrides: <Type, Generator>{
297+
FileSystem: () => fileSystem,
298+
FileSystemUtils: () => fsUtils,
299+
ProcessManager: () => processManager,
219300
// Custom home paths are not supported on macOS nor Windows yet,
220301
// so we force the platform to fake Linux here.
221302
Platform: () => platform,

0 commit comments

Comments
 (0)