Commit df465c77 authored by Dan Field's avatar Dan Field Committed by Jonah Williams

Fall-back to platform tools in Android SDK detection logic. (#28863)

parent cd1b89c6
...@@ -365,6 +365,14 @@ class AndroidSdk { ...@@ -365,6 +365,14 @@ class AndroidSdk {
} }
static bool validSdkDirectory(String dir) { static bool validSdkDirectory(String dir) {
return sdkDirectoryHasLicneses(dir) || sdkDirectoryHasPlatformTools(dir);
}
static bool sdkDirectoryHasPlatformTools(String dir) {
return fs.isDirectorySync(fs.path.join(dir, 'platform-tools'));
}
static bool sdkDirectoryHasLicneses(String dir) {
return fs.isDirectorySync(fs.path.join(dir, 'licenses')); return fs.isDirectorySync(fs.path.join(dir, 'licenses'));
} }
......
...@@ -14,6 +14,7 @@ import 'base/context.dart'; ...@@ -14,6 +14,7 @@ import 'base/context.dart';
import 'base/file_system.dart'; import 'base/file_system.dart';
import 'base/os.dart' show os; import 'base/os.dart' show os;
import 'base/process.dart'; import 'base/process.dart';
import 'base/user_messages.dart';
import 'build_info.dart'; import 'build_info.dart';
import 'globals.dart'; import 'globals.dart';
import 'ios/ios_workflow.dart'; import 'ios/ios_workflow.dart';
...@@ -94,7 +95,7 @@ class AndroidApk extends ApplicationPackage { ...@@ -94,7 +95,7 @@ class AndroidApk extends ApplicationPackage {
factory AndroidApk.fromApk(File apk) { factory AndroidApk.fromApk(File apk) {
final String aaptPath = androidSdk?.latestVersion?.aaptPath; final String aaptPath = androidSdk?.latestVersion?.aaptPath;
if (aaptPath == null) { if (aaptPath == null) {
printError('Unable to locate the Android SDK; please run \'flutter doctor\'.'); printError(userMessages.aaptNotFound);
return null; return null;
} }
......
...@@ -115,6 +115,8 @@ class UserMessages { ...@@ -115,6 +115,8 @@ class UserMessages {
String get androidStudioResetDir => String get androidStudioResetDir =>
'Consider removing your android-studio-dir setting by running:\n' 'Consider removing your android-studio-dir setting by running:\n'
'flutter config --android-studio-dir='; 'flutter config --android-studio-dir=';
String get aaptNotFound =>
'Could not locate aapt. Please ensure you have the Android buildtools installed.';
// Messages used in NoAndroidStudioValidator // Messages used in NoAndroidStudioValidator
String androidStudioMissing(String location) => String androidStudioMissing(String location) =>
......
...@@ -65,6 +65,34 @@ void main() { ...@@ -65,6 +65,34 @@ void main() {
).path)..createSync(recursive: true); ).path)..createSync(recursive: true);
}); });
testUsingContext('Licenses not available, platform and buildtools available, apk exists', () async {
const String aaptPath = 'aaptPath';
final File apkFile = fs.file('app.apk');
final AndroidSdkVersion sdkVersion = MockitoAndroidSdkVersion();
when(sdkVersion.aaptPath).thenReturn(aaptPath);
when(sdk.latestVersion).thenReturn(sdkVersion);
when(sdk.platformToolsAvailable).thenReturn(true);
when(sdk.licensesAvailable).thenReturn(false);
when(mockProcessManager.runSync(
argThat(equals(<String>[
aaptPath,
'dump',
'xmltree',
apkFile.path,
'AndroidManifest.xml',
])),
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
),
).thenReturn(ProcessResult(0, 0, _aaptDataWithDefaultEnabledAndMainLauncherActivity, null));
final ApplicationPackage applicationPackage = await ApplicationPackageFactory.instance.getPackageForPlatform(
TargetPlatform.android_arm,
applicationBinary: apkFile,
);
expect(applicationPackage.name, 'app.apk');
}, overrides: overrides);
testUsingContext('Licenses available, build tools not, apk exists', () async { testUsingContext('Licenses available, build tools not, apk exists', () async {
when(sdk.latestVersion).thenReturn(null); when(sdk.latestVersion).thenReturn(null);
final FlutterProject project = await FlutterProject.current(); final FlutterProject project = await FlutterProject.current();
......
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