[flutter_tools] Add support for versioned Android cmdline tools (#78253)
This commit is contained in:
committed by
GitHub
parent
389a3fa50f
commit
fed35b4d9c
@@ -261,23 +261,57 @@ class AndroidSdk {
|
||||
return null;
|
||||
}
|
||||
|
||||
String getAvdManagerPath() {
|
||||
final String binaryName = globals.platform.isWindows ? 'avdmanager.bat' : 'avdmanager';
|
||||
final File cmdlineToolsBinary = directory
|
||||
String getCmdlineToolsPath(String binaryName) {
|
||||
// First look for the latest version of the command-line tools
|
||||
final File cmdlineToolsLatestBinary = directory
|
||||
.childDirectory('cmdline-tools')
|
||||
.childDirectory('latest')
|
||||
.childDirectory('bin')
|
||||
.childFile(binaryName);
|
||||
if (cmdlineToolsBinary.existsSync()) {
|
||||
return cmdlineToolsBinary.path;
|
||||
if (cmdlineToolsLatestBinary.existsSync()) {
|
||||
return cmdlineToolsLatestBinary.path;
|
||||
}
|
||||
|
||||
// Next look for the highest version of the command-line tools
|
||||
final Directory cmdlineToolsDir = directory.childDirectory('cmdline-tools');
|
||||
if (cmdlineToolsDir.existsSync()) {
|
||||
final List<Version> cmdlineTools = cmdlineToolsDir
|
||||
.listSync()
|
||||
.whereType<Directory>()
|
||||
.map((Directory subDirectory) {
|
||||
try {
|
||||
return Version.parse(subDirectory.basename);
|
||||
} on Exception {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.where((Version version) => version != null)
|
||||
.toList();
|
||||
cmdlineTools.sort();
|
||||
|
||||
for (final Version cmdlineToolsVersion in cmdlineTools.reversed) {
|
||||
final File cmdlineToolsBinary = directory
|
||||
.childDirectory('cmdline-tools')
|
||||
.childDirectory(cmdlineToolsVersion.toString())
|
||||
.childDirectory('bin')
|
||||
.childFile(binaryName);
|
||||
if (cmdlineToolsBinary.existsSync()) {
|
||||
return cmdlineToolsBinary.path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Finally fallback to the old SDK tools
|
||||
final File toolsBinary = directory.childDirectory('tools').childDirectory('bin').childFile(binaryName);
|
||||
if (toolsBinary.existsSync()) {
|
||||
return toolsBinary.path;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
String getAvdManagerPath() => getCmdlineToolsPath(globals.platform.isWindows ? 'avdmanager.bat' : 'avdmanager');
|
||||
|
||||
/// Sets up various paths used internally.
|
||||
///
|
||||
/// This method should be called in a case where the tooling may have updated
|
||||
@@ -354,14 +388,11 @@ class AndroidSdk {
|
||||
final String executable = globals.platform.isWindows
|
||||
? 'sdkmanager.bat'
|
||||
: 'sdkmanager';
|
||||
final File cmdlineTool = directory
|
||||
.childDirectory('cmdline-tools')
|
||||
.childDirectory('latest')
|
||||
.childDirectory('bin')
|
||||
.childFile(executable);
|
||||
if (cmdlineTool.existsSync()) {
|
||||
return cmdlineTool.path;
|
||||
final String path = getCmdlineToolsPath(executable);
|
||||
if (path != null) {
|
||||
return path;
|
||||
}
|
||||
// If no binary was found, return the default location
|
||||
return directory
|
||||
.childDirectory('tools')
|
||||
.childDirectory('bin')
|
||||
|
||||
@@ -80,6 +80,26 @@ void main() {
|
||||
Config: () => config,
|
||||
});
|
||||
|
||||
testUsingContext('returns sdkmanager path under cmdline tools (highest version) on Linux/macOS', () {
|
||||
sdkDir = MockAndroidSdk.createSdkDirectory();
|
||||
config.setValue('android-sdk', sdkDir.path);
|
||||
|
||||
final AndroidSdk sdk = AndroidSdk.locateAndroidSdk();
|
||||
final List<String> versions = <String>['3.0', '2.1', '1.0'];
|
||||
for (final String version in versions) {
|
||||
fileSystem.file(
|
||||
fileSystem.path.join(sdk.directory.path, 'cmdline-tools', version, 'bin', 'sdkmanager')
|
||||
).createSync(recursive: true);
|
||||
}
|
||||
|
||||
expect(sdk.sdkManagerPath, fileSystem.path.join(sdk.directory.path, 'cmdline-tools', '3.0', 'bin', 'sdkmanager'));
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
Platform: () => FakePlatform(operatingSystem: 'linux'),
|
||||
Config: () => config,
|
||||
});
|
||||
|
||||
testUsingContext('Caches adb location after first access', () {
|
||||
sdkDir = MockAndroidSdk.createSdkDirectory();
|
||||
config.setValue('android-sdk', sdkDir.path);
|
||||
|
||||
Reference in New Issue
Block a user