Fix androidSdk NPE (#47187)
This commit is contained in:
@@ -86,7 +86,7 @@ class _AndroidBuilderImpl extends AndroidBuilder {
|
||||
buildNumber: buildNumber,
|
||||
);
|
||||
} finally {
|
||||
androidSdk.reinitialize();
|
||||
androidSdk?.reinitialize();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ class _AndroidBuilderImpl extends AndroidBuilder {
|
||||
localGradleErrors: gradleErrors,
|
||||
);
|
||||
} finally {
|
||||
androidSdk.reinitialize();
|
||||
androidSdk?.reinitialize();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ class _AndroidBuilderImpl extends AndroidBuilder {
|
||||
localGradleErrors: gradleErrors,
|
||||
);
|
||||
} finally {
|
||||
androidSdk.reinitialize();
|
||||
androidSdk?.reinitialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ String getAdbPath([ AndroidSdk existingSdk ]) {
|
||||
if (sdk?.latestVersion == null) {
|
||||
return os.which('adb')?.path;
|
||||
} else {
|
||||
return sdk.adbPath;
|
||||
return sdk?.adbPath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ Future<void> checkGradleDependencies() async {
|
||||
workingDirectory: flutterProject.android.hostAppGradleRoot.path,
|
||||
environment: gradleEnvironment,
|
||||
);
|
||||
androidSdk.reinitialize();
|
||||
androidSdk?.reinitialize();
|
||||
progress.stop();
|
||||
}
|
||||
|
||||
@@ -224,9 +224,13 @@ Future<void> buildGradleApp({
|
||||
bool shouldBuildPluginAsAar = false,
|
||||
int retries = 1,
|
||||
}) async {
|
||||
if (androidSdk == null) {
|
||||
exitWithNoSdkMessage();
|
||||
}
|
||||
assert(project != null);
|
||||
assert(androidBuildInfo != null);
|
||||
assert(target != null);
|
||||
assert(isBuildingBundle != null);
|
||||
assert(localGradleErrors != null);
|
||||
assert(androidSdk != null);
|
||||
|
||||
if (!project.android.isUsingGradle) {
|
||||
_exitWithProjectNotUsingGradleMessage();
|
||||
}
|
||||
@@ -489,10 +493,7 @@ Future<void> buildGradleAar({
|
||||
assert(target != null);
|
||||
assert(androidBuildInfo != null);
|
||||
assert(outputDirectory != null);
|
||||
|
||||
if (androidSdk == null) {
|
||||
exitWithNoSdkMessage();
|
||||
}
|
||||
assert(androidSdk != null);
|
||||
|
||||
final FlutterManifest manifest = project.manifest;
|
||||
if (!manifest.isModule && !manifest.isPlugin) {
|
||||
|
||||
@@ -41,7 +41,7 @@ class ApplicationPackageFactory {
|
||||
case TargetPlatform.android_arm64:
|
||||
case TargetPlatform.android_x64:
|
||||
case TargetPlatform.android_x86:
|
||||
if (androidSdk?.licensesAvailable == true && androidSdk.latestVersion == null) {
|
||||
if (androidSdk?.licensesAvailable == true && androidSdk?.latestVersion == null) {
|
||||
await checkGradleDependencies();
|
||||
}
|
||||
return applicationBinary == null
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
import 'dart:async';
|
||||
|
||||
import '../android/android_builder.dart';
|
||||
import '../android/android_sdk.dart';
|
||||
import '../android/gradle_utils.dart';
|
||||
import '../base/common.dart';
|
||||
import '../base/os.dart';
|
||||
import '../build_info.dart';
|
||||
@@ -85,6 +87,9 @@ class BuildAarCommand extends BuildSubCommand {
|
||||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
if (androidSdk == null) {
|
||||
exitWithNoSdkMessage();
|
||||
}
|
||||
final Set<AndroidBuildInfo> androidBuildInfo = <AndroidBuildInfo>{};
|
||||
|
||||
final Iterable<AndroidArch> targetArchitectures =
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
import 'dart:async';
|
||||
|
||||
import '../android/android_builder.dart';
|
||||
import '../android/android_sdk.dart';
|
||||
import '../android/gradle_utils.dart';
|
||||
import '../base/terminal.dart';
|
||||
import '../build_info.dart';
|
||||
import '../cache.dart';
|
||||
@@ -77,6 +79,9 @@ class BuildApkCommand extends BuildSubCommand {
|
||||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
if (androidSdk == null) {
|
||||
exitWithNoSdkMessage();
|
||||
}
|
||||
final BuildInfo buildInfo = getBuildInfo();
|
||||
final AndroidBuildInfo androidBuildInfo = AndroidBuildInfo(
|
||||
buildInfo,
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
import 'dart:async';
|
||||
|
||||
import '../android/android_builder.dart';
|
||||
import '../android/android_sdk.dart';
|
||||
import '../android/gradle_utils.dart';
|
||||
import '../build_info.dart';
|
||||
import '../cache.dart';
|
||||
import '../project.dart';
|
||||
@@ -69,6 +71,9 @@ class BuildAppBundleCommand extends BuildSubCommand {
|
||||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
if (androidSdk == null) {
|
||||
exitWithNoSdkMessage();
|
||||
}
|
||||
final AndroidBuildInfo androidBuildInfo = AndroidBuildInfo(getBuildInfo(),
|
||||
targetArchs: stringsArg('target-platform').map<AndroidArch>(getAndroidArchForName),
|
||||
shrink: boolArg('shrink'),
|
||||
|
||||
@@ -29,14 +29,15 @@ FlutterProjectFactory get projectFactory => context.get<FlutterProjectFactory>()
|
||||
class FlutterProjectFactory {
|
||||
FlutterProjectFactory();
|
||||
|
||||
final Map<String, FlutterProject> _projects =
|
||||
@visibleForTesting
|
||||
final Map<String, FlutterProject> projects =
|
||||
<String, FlutterProject>{};
|
||||
|
||||
/// Returns a [FlutterProject] view of the given directory or a ToolExit error,
|
||||
/// if `pubspec.yaml` or `example/pubspec.yaml` is invalid.
|
||||
FlutterProject fromDirectory(Directory directory) {
|
||||
assert(directory != null);
|
||||
return _projects.putIfAbsent(directory.path, /* ifAbsent */ () {
|
||||
return projects.putIfAbsent(directory.path, /* ifAbsent */ () {
|
||||
final FlutterManifest manifest = FlutterProject._readManifest(
|
||||
directory.childFile(bundle.defaultManifestPath).path,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user