Unverified Commit ad16823e authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] support new SDK structure for sdkmanager (#51980)

parent c411f588
......@@ -282,13 +282,15 @@ class AndroidSdk {
List<AndroidSdkVersion> _sdkVersions;
AndroidSdkVersion _latestVersion;
/// Whether the `platform-tools` directory exists in the Android SDK.
/// Whether the `platform-tools` or `cmdline-tools` directory exists in the Android SDK.
///
/// It is possible to have an Android SDK folder that is missing this with
/// the expectation that it will be downloaded later, e.g. by gradle or the
/// sdkmanager. The [licensesAvailable] property should be used to determine
/// whether the licenses are at least possibly accepted.
bool get platformToolsAvailable => globals.fs.directory(globals.fs.path.join(directory, 'platform-tools')).existsSync();
bool get platformToolsAvailable =>
globals.fs.directory(globals.fs.path.join(directory, 'cmdline-tools')).existsSync() ||
globals.fs.directory(globals.fs.path.join(directory, 'platform-tools')).existsSync();
/// Whether the `licenses` directory exists in the Android SDK.
///
......@@ -545,8 +547,17 @@ class AndroidSdk {
_latestVersion = _sdkVersions.isEmpty ? null : _sdkVersions.last;
}
/// Returns the filesystem path of the Android SDK manager tool or null if not found.
/// Returns the filesystem path of the Android SDK manager tool.
///
/// The sdkmanager was previously in the tools directory but this component
/// was marked as obsolete in 3.6.
String get sdkManagerPath {
final File cmdlineTool = globals.fs.file(
globals.fs.path.join(directory, 'cmdline-tools', 'latest', 'bin', 'sdkmanager')
);
if (cmdlineTool.existsSync()) {
return cmdlineTool.path;
}
return globals.fs.path.join(directory, 'tools', 'bin', 'sdkmanager');
}
......
......@@ -359,12 +359,6 @@ class AndroidLicenseValidator extends DoctorValidator {
throwToolExit(userMessages.androidMissingSdkManager(androidSdk.sdkManagerPath));
}
final Version sdkManagerVersion = Version.parse(androidSdk.sdkManagerVersion);
if (sdkManagerVersion == null || sdkManagerVersion.major < 26) {
// SDK manager is found, but needs to be updated.
throwToolExit(userMessages.androidSdkManagerOutdated(androidSdk.sdkManagerPath));
}
try {
final Process process = await processUtils.start(
<String>[androidSdk.sdkManagerPath, '--licenses'],
......
......@@ -60,11 +60,27 @@ void main() {
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('returns sdkmanager path', () {
testUsingContext('returns sdkmanager path under cmdline tools', () {
sdkDir = MockAndroidSdk.createSdkDirectory();
globals.config.setValue('android-sdk', sdkDir.path);
final AndroidSdk sdk = AndroidSdk.locateAndroidSdk();
globals.fs.file(
globals.fs.path.join(sdk.directory, 'cmdline-tools', 'latest', 'bin', 'sdkmanager')
).createSync(recursive: true);
expect(sdk.sdkManagerPath, globals.fs.path.join(sdk.directory, 'cmdline-tools', 'latest', 'bin', 'sdkmanager'));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('returns sdkmanager path under tools if cmdline doesnt exist', () {
sdkDir = MockAndroidSdk.createSdkDirectory();
globals.config.setValue('android-sdk', sdkDir.path);
final AndroidSdk sdk = AndroidSdk.locateAndroidSdk();
expect(sdk.sdkManagerPath, globals.fs.path.join(sdk.directory, 'tools', 'bin', 'sdkmanager'));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
......
......@@ -169,32 +169,6 @@ void main() {
Stdio: () => stdio,
}));
testUsingContext('runLicenseManager errors for version < 26', () async {
when(sdk.sdkManagerPath).thenReturn('/foo/bar/sdkmanager');
when(sdk.sdkManagerVersion).thenReturn('25.0.0');
expect(AndroidLicenseValidator.runLicenseManager(), throwsToolExit(message: 'To update, run'));
}, overrides: Map<Type, Generator>.unmodifiable(<Type, Generator>{
AndroidSdk: () => sdk,
FileSystem: () => fs,
ProcessManager: () => processManager,
Platform: () => FakePlatform()..environment = <String, String>{'HOME': '/home/me'},
Stdio: () => stdio,
}));
testUsingContext('runLicenseManager errors correctly for null version', () async {
when(sdk.sdkManagerPath).thenReturn('/foo/bar/sdkmanager');
when(sdk.sdkManagerVersion).thenReturn(null);
expect(AndroidLicenseValidator.runLicenseManager(), throwsToolExit(message: 'To update, run'));
}, overrides: Map<Type, Generator>.unmodifiable(<Type, Generator>{
AndroidSdk: () => sdk,
FileSystem: () => fs,
ProcessManager: () => processManager,
Platform: () => FakePlatform()..environment = <String, String>{'HOME': '/home/me'},
Stdio: () => stdio,
}));
testUsingContext('runLicenseManager errors when sdkmanager is not found', () async {
when(sdk.sdkManagerPath).thenReturn('/foo/bar/sdkmanager');
processManager.canRunSucceeds = false;
......
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