Unverified Commit 2e17a8e6 authored by Gurjinder Partola's avatar Gurjinder Partola Committed by GitHub

Fix avdmanager path detection (#78166)

parent 71fb9162
......@@ -263,9 +263,17 @@ class AndroidSdk {
String getAvdManagerPath() {
final String binaryName = globals.platform.isWindows ? 'avdmanager.bat' : 'avdmanager';
final File file = directory.childDirectory('tools').childDirectory('bin').childFile(binaryName);
if (file.existsSync()) {
return file.path;
final File cmdlineToolsBinary = directory
.childDirectory('cmdline-tools')
.childDirectory('latest')
.childDirectory('bin')
.childFile(binaryName);
if (cmdlineToolsBinary.existsSync()) {
return cmdlineToolsBinary.path;
}
final File toolsBinary = directory.childDirectory('tools').childDirectory('bin').childFile(binaryName);
if (toolsBinary.existsSync()) {
return toolsBinary.path;
}
return null;
}
......
......@@ -230,6 +230,74 @@ void main() {
Config: () => config,
Platform: () => FakePlatform(operatingSystem: 'linux'),
});
testUsingContext('returns avdmanager path under cmdline tools', () {
sdkDir = MockAndroidSdk.createSdkDirectory();
config.setValue('android-sdk', sdkDir.path);
final AndroidSdk sdk = AndroidSdk.locateAndroidSdk();
fileSystem.file(
fileSystem.path.join(sdk.directory.path, 'cmdline-tools', 'latest', 'bin', 'avdmanager')
).createSync(recursive: true);
expect(sdk.avdManagerPath, fileSystem.path.join(sdk.directory.path, 'cmdline-tools', 'latest', 'bin', 'avdmanager'));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(operatingSystem: 'linux'),
Config: () => config,
});
testUsingContext('returns avdmanager path under cmdline tools on windows', () {
sdkDir = MockAndroidSdk.createSdkDirectory();
config.setValue('android-sdk', sdkDir.path);
final AndroidSdk sdk = AndroidSdk.locateAndroidSdk();
fileSystem.file(
fileSystem.path.join(sdk.directory.path, 'cmdline-tools', 'latest', 'bin', 'avdmanager.bat')
).createSync(recursive: true);
expect(sdk.avdManagerPath, fileSystem.path.join(sdk.directory.path, 'cmdline-tools', 'latest', 'bin', 'avdmanager.bat'));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(operatingSystem: 'windows'),
Config: () => config,
});
testUsingContext("returns avdmanager path under tools if cmdline doesn't exist", () {
sdkDir = MockAndroidSdk.createSdkDirectory();
config.setValue('android-sdk', sdkDir.path);
final AndroidSdk sdk = AndroidSdk.locateAndroidSdk();
fileSystem.file(
fileSystem.path.join(sdk.directory.path, 'tools', 'bin', 'avdmanager')
).createSync(recursive: true);
expect(sdk.avdManagerPath, fileSystem.path.join(sdk.directory.path, 'tools', 'bin', 'avdmanager'));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(operatingSystem: 'linux'),
Config: () => config,
});
testUsingContext("returns avdmanager path under tools if cmdline doesn't exist on windows", () {
sdkDir = MockAndroidSdk.createSdkDirectory();
config.setValue('android-sdk', sdkDir.path);
final AndroidSdk sdk = AndroidSdk.locateAndroidSdk();
fileSystem.file(
fileSystem.path.join(sdk.directory.path, 'tools', 'bin', 'avdmanager.bat')
).createSync(recursive: true);
expect(sdk.avdManagerPath, fileSystem.path.join(sdk.directory.path, 'tools', 'bin', 'avdmanager.bat'));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(operatingSystem: 'windows'),
Config: () => config,
});
});
}
......
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