Unverified Commit 1c976933 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] support Android Studio 4.1 on Windows (#67992)

Android Studio 4.1 moved the location of the .home file on Windows which is used to located the install directory. This functionality is important because it is how we locate and discover the Android SDK functionality, as well as the appropriate JRE.

fixes #67986
parent 1aaa455f
......@@ -260,6 +260,29 @@ class AndroidStudio implements Comparable<AndroidStudio> {
}
}
}
// 4.1 has a different location for AndroidStudio installs on Windows.
if (globals.platform.isWindows) {
final File homeDot = globals.fs.file(globals.fs.path.join(
globals.platform.environment['LOCALAPPDATA'],
'Google',
'AndroidStudio4.1',
'.home',
));
if (homeDot.existsSync()) {
final String installPath = homeDot.readAsStringSync();
if (globals.fs.isDirectorySync(installPath)) {
final AndroidStudio studio = AndroidStudio(
installPath,
version: Version(4, 1, 0),
studioAppName: 'Android Studio 4.1',
);
if (studio != null && !_hasStudioAt(studio.directory, newerThan: studio.version)) {
studios.removeWhere((AndroidStudio other) => other.directory == studio.directory);
studios.add(studio);
}
}
}
}
final String configuredStudioDir = globals.config.getValue('android-studio-dir') as String;
if (configuredStudioDir != null && !_hasStudioAt(configuredStudioDir)) {
......
......@@ -6,6 +6,7 @@ import 'package:file/memory.dart';
import 'package:flutter_tools/src/android/android_studio.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/version.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/ios/plist_parser.dart';
import 'package:mockito/mockito.dart';
......@@ -33,6 +34,13 @@ final Platform linuxPlatform = FakePlatform(
environment: <String, String>{'HOME': homeLinux},
);
final Platform windowsPlatform = FakePlatform(
operatingSystem: 'windows',
environment: <String, String>{
'LOCALAPPDATA': 'C:\\Users\\Dash\\AppData\\Local',
}
);
class MockPlistUtils extends Mock implements PlistParser {}
Platform macPlatform() {
......@@ -177,4 +185,28 @@ void main() {
PlistParser: () => plistUtils,
});
});
FileSystem windowsFileSystem;
setUp(() {
windowsFileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows);
});
testUsingContext('Can discover Android Studio 4.1 location on Windows', () {
windowsFileSystem.file('C:\\Users\\Dash\\AppData\\Local\\Google\\AndroidStudio4.1\\.home')
..createSync(recursive: true)
..writeAsStringSync('C:\\Program Files\\AndroidStudio');
windowsFileSystem
.directory('C:\\Program Files\\AndroidStudio')
.createSync(recursive: true);
final AndroidStudio studio = AndroidStudio.allInstalled().single;
expect(studio.version, Version(4, 1, 0));
expect(studio.studioAppName, 'Android Studio 4.1');
}, overrides: <Type, Generator>{
Platform: () => windowsPlatform,
FileSystem: () => windowsFileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment