Unverified Commit 6d03cb65 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Clean up null assumptions for Gradle classes (#83443)

parent 43e31977
......@@ -190,7 +190,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
@required FlutterProject project,
@required Set<AndroidBuildInfo> androidBuildInfo,
@required String target,
@required String outputDirectoryPath,
String outputDirectoryPath,
@required String buildNumber,
}) async {
Directory outputDirectory =
......@@ -361,7 +361,8 @@ class AndroidGradleBuilder implements AndroidBuilder {
if (target != null) {
command.add('-Ptarget=$target');
}
if (project.manifest.deferredComponents != null) {
final List<DeferredComponent> deferredComponents = project.manifest.deferredComponents;
if (deferredComponents != null) {
if (deferredComponentsEnabled) {
command.add('-Pdeferred-components=true');
androidBuildInfo.buildInfo.dartDefines.add('validate-deferred-components=$validateDeferredComponents');
......@@ -369,7 +370,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
// Pass in deferred components regardless of building split aot to satisfy
// android dynamic features registry in build.gradle.
final List<String> componentNames = <String>[];
for (final DeferredComponent component in project.manifest.deferredComponents) {
for (final DeferredComponent component in deferredComponents) {
componentNames.add(component.name);
}
if (componentNames.isNotEmpty) {
......@@ -756,7 +757,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
Future<void> buildPluginsAsAar(
FlutterProject flutterProject,
AndroidBuildInfo androidBuildInfo, {
Directory buildDirectory,
@required Directory buildDirectory,
}) async {
final File flutterPluginFile = flutterProject.flutterPluginsFile;
if (!flutterPluginFile.existsSync()) {
......@@ -806,14 +807,13 @@ class AndroidGradleBuilder implements AndroidBuilder {
/// Prints how to consume the AAR from a host app.
void printHowToConsumeAar({
@required Set<String> buildModes,
@required String androidPackage,
String androidPackage = 'unknown',
@required Directory repoDirectory,
@required Logger logger,
@required FileSystem fileSystem,
String buildNumber,
}) {
assert(buildModes != null && buildModes.isNotEmpty);
assert(androidPackage != null);
assert(repoDirectory != null);
buildNumber ??= '1.0';
......@@ -919,10 +919,11 @@ Iterable<String> findApkFilesModule(
if (apkFile.existsSync()) {
return <File>[apkFile];
}
if (buildInfo.flavor != null) {
final String flavor = buildInfo.flavor;
if (flavor != null) {
// Android Studio Gradle plugin v3 adds flavor to path.
apkFile = apkDirectory
.childDirectory(buildInfo.flavor)
.childDirectory(flavor)
.childDirectory(modeName)
.childFile(apkFileName);
if (apkFile.existsSync()) {
......
......@@ -18,8 +18,8 @@ typedef GradleErrorTest = bool Function(String);
/// A Gradle error handled by the tool.
class GradleHandledError {
const GradleHandledError({
this.test,
this.handler,
@required this.test,
@required this.handler,
this.eventLabel,
});
......@@ -29,10 +29,10 @@ class GradleHandledError {
/// The handler function.
final Future<GradleBuildStatus> Function({
String line,
FlutterProject project,
bool usesAndroidX,
bool shouldBuildPluginAsAar,
@required String line,
@required FlutterProject project,
@required bool usesAndroidX,
@required bool shouldBuildPluginAsAar,
}) handler;
/// The [BuildEvent] label is named gradle-[eventLabel].
......@@ -85,10 +85,10 @@ final GradleHandledError permissionDeniedErrorHandler = GradleHandledError(
'Permission denied',
]),
handler: ({
String line,
FlutterProject project,
bool usesAndroidX,
bool shouldBuildPluginAsAar,
@required String line,
@required FlutterProject project,
@required bool usesAndroidX,
@required bool shouldBuildPluginAsAar,
}) async {
globals.printStatus('${globals.logger.terminal.warningMark} Gradle does not have execution permission.', emphasis: true);
globals.printStatus(
......@@ -122,10 +122,10 @@ final GradleHandledError networkErrorHandler = GradleHandledError(
'Gateway Time-out'
]),
handler: ({
String line,
FlutterProject project,
bool usesAndroidX,
bool shouldBuildPluginAsAar,
@required String line,
@required FlutterProject project,
@required bool usesAndroidX,
@required bool shouldBuildPluginAsAar,
}) async {
globals.printError(
'${globals.logger.terminal.warningMark} Gradle threw an error while downloading artifacts from the network. '
......@@ -152,10 +152,10 @@ final GradleHandledError r8FailureHandler = GradleHandledError(
'com.android.tools.r8',
]),
handler: ({
String line,
FlutterProject project,
bool usesAndroidX,
bool shouldBuildPluginAsAar,
@required String line,
@required FlutterProject project,
@required bool usesAndroidX,
@required bool shouldBuildPluginAsAar,
}) async {
globals.printStatus('${globals.logger.terminal.warningMark} The shrinker may have failed to optimize the Java bytecode.', emphasis: true);
globals.printStatus('To disable the shrinker, pass the `--no-shrink` flag to this command.', indent: 4);
......@@ -191,10 +191,10 @@ final GradleHandledError androidXFailureHandler = GradleHandledError(
_androidXFailureRegex.hasMatch(line);
},
handler: ({
String line,
FlutterProject project,
bool usesAndroidX,
bool shouldBuildPluginAsAar,
@required String line,
@required FlutterProject project,
@required bool usesAndroidX,
@required bool shouldBuildPluginAsAar,
}) async {
final bool hasPlugins = project.flutterPluginsFile.existsSync();
if (!hasPlugins) {
......@@ -259,10 +259,10 @@ final GradleHandledError licenseNotAcceptedHandler = GradleHandledError(
'You have not accepted the license agreements of the following SDK components',
]),
handler: ({
String line,
FlutterProject project,
bool usesAndroidX,
bool shouldBuildPluginAsAar,
@required String line,
@required FlutterProject project,
@required bool usesAndroidX,
@required bool shouldBuildPluginAsAar,
}) async {
const String licenseNotAcceptedMatcher =
r'You have not accepted the license agreements of the following SDK components:\s*\[(.+)\]';
......@@ -293,10 +293,10 @@ final GradleHandledError flavorUndefinedHandler = GradleHandledError(
return _undefinedTaskPattern.hasMatch(line);
},
handler: ({
String line,
FlutterProject project,
bool usesAndroidX,
bool shouldBuildPluginAsAar,
@required String line,
@required FlutterProject project,
@required bool usesAndroidX,
@required bool shouldBuildPluginAsAar,
}) async {
final RunResult tasksRunResult = await globals.processUtils.run(
<String>[
......@@ -366,10 +366,10 @@ final GradleHandledError minSdkVersion = GradleHandledError(
return _minSdkVersionPattern.hasMatch(line);
},
handler: ({
String line,
FlutterProject project,
bool usesAndroidX,
bool shouldBuildPluginAsAar,
@required String line,
@required FlutterProject project,
@required bool usesAndroidX,
@required bool shouldBuildPluginAsAar,
}) async {
final File gradleFile = project.directory
.childDirectory('android')
......@@ -405,10 +405,10 @@ final GradleHandledError transformInputIssue = GradleHandledError(
return line.contains('https://issuetracker.google.com/issues/158753935');
},
handler: ({
String line,
FlutterProject project,
bool usesAndroidX,
bool shouldBuildPluginAsAar,
@required String line,
@required FlutterProject project,
@required bool usesAndroidX,
@required bool shouldBuildPluginAsAar,
}) async {
final File gradleFile = project.directory
.childDirectory('android')
......@@ -438,10 +438,10 @@ final GradleHandledError lockFileDepMissing = GradleHandledError(
return line.contains('which is not part of the dependency lock state');
},
handler: ({
String line,
FlutterProject project,
bool usesAndroidX,
bool shouldBuildPluginAsAar,
@required String line,
@required FlutterProject project,
@required bool usesAndroidX,
@required bool shouldBuildPluginAsAar,
}) async {
final File gradleFile = project.directory
.childDirectory('android')
......
......@@ -19,6 +19,7 @@ import '../cache.dart';
import '../globals_null_migrated.dart' as globals;
import '../project.dart';
import '../reporting/reporting.dart';
import 'android_sdk.dart';
const String _defaultGradleVersion = '6.7';
......@@ -133,8 +134,13 @@ bool _isWithinVersionRange(
assert(min != null);
assert(max != null);
final Version parsedTargetVersion = Version.parse(targetVersion);
return parsedTargetVersion >= Version.parse(min) &&
parsedTargetVersion <= Version.parse(max);
final Version minVersion = Version.parse(min);
final Version maxVersion = Version.parse(max);
return minVersion != null &&
maxVersion != null &&
parsedTargetVersion != null &&
parsedTargetVersion >= minVersion &&
parsedTargetVersion <= maxVersion;
}
/// Returns the Gradle version that is required by the given Android Gradle plugin version
......@@ -217,8 +223,9 @@ void updateLocalProperties({
changed = true;
}
if (globals.androidSdk != null) {
changeIfNecessary('sdk.dir', globals.fsUtils.escapePath(globals.androidSdk.directory.path));
final AndroidSdk androidSdk = globals.androidSdk;
if (androidSdk != null) {
changeIfNecessary('sdk.dir', globals.fsUtils.escapePath(androidSdk.directory.path));
}
changeIfNecessary('flutter.sdk', globals.fsUtils.escapePath(Cache.flutterRoot));
......@@ -248,8 +255,9 @@ void updateLocalProperties({
/// Writes the path to the Android SDK, if known.
void writeLocalProperties(File properties) {
final SettingsFile settings = SettingsFile();
if (globals.androidSdk != null) {
settings.values['sdk.dir'] = globals.fsUtils.escapePath(globals.androidSdk.directory.path);
final AndroidSdk androidSdk = globals.androidSdk;
if (androidSdk != null) {
settings.values['sdk.dir'] = globals.fsUtils.escapePath(androidSdk.directory.path);
}
settings.writeContents(properties);
}
......
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