Fall-back to platform tools in Android SDK detection logic. (#28863)
This commit is contained in:
committed by
Jonah Williams
parent
cd1b89c696
commit
df465c7718
@@ -365,6 +365,14 @@ class AndroidSdk {
|
||||
}
|
||||
|
||||
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'));
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import 'base/context.dart';
|
||||
import 'base/file_system.dart';
|
||||
import 'base/os.dart' show os;
|
||||
import 'base/process.dart';
|
||||
import 'base/user_messages.dart';
|
||||
import 'build_info.dart';
|
||||
import 'globals.dart';
|
||||
import 'ios/ios_workflow.dart';
|
||||
@@ -94,7 +95,7 @@ class AndroidApk extends ApplicationPackage {
|
||||
factory AndroidApk.fromApk(File apk) {
|
||||
final String aaptPath = androidSdk?.latestVersion?.aaptPath;
|
||||
if (aaptPath == null) {
|
||||
printError('Unable to locate the Android SDK; please run \'flutter doctor\'.');
|
||||
printError(userMessages.aaptNotFound);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -115,6 +115,8 @@ class UserMessages {
|
||||
String get androidStudioResetDir =>
|
||||
'Consider removing your android-studio-dir setting by running:\n'
|
||||
'flutter config --android-studio-dir=';
|
||||
String get aaptNotFound =>
|
||||
'Could not locate aapt. Please ensure you have the Android buildtools installed.';
|
||||
|
||||
// Messages used in NoAndroidStudioValidator
|
||||
String androidStudioMissing(String location) =>
|
||||
|
||||
@@ -65,6 +65,34 @@ void main() {
|
||||
).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 {
|
||||
when(sdk.latestVersion).thenReturn(null);
|
||||
final FlutterProject project = await FlutterProject.current();
|
||||
|
||||
Reference in New Issue
Block a user