Revert "Migrate template to Gradle 6.7 and AGP 4.1.0 (#70808)" (#71096)

This reverts commit 8e73bab94c.
This commit is contained in:
Amir Hardon
2020-11-23 12:27:36 -08:00
committed by GitHub
parent 8737472af1
commit 7df04fdbd3
170 changed files with 742 additions and 352 deletions

View File

@@ -324,6 +324,9 @@ Future<void> buildGradleApp({
if (androidBuildInfo.splitPerAbi) {
command.add('-Psplit-per-abi=true');
}
if (androidBuildInfo.shrink) {
command.add('-Pshrink=true');
}
if (androidBuildInfo.buildInfo.dartDefines?.isNotEmpty ?? false) {
command.add('-Pdart-defines=${encodeDartDefines(androidBuildInfo.buildInfo.dartDefines)}');
}

View File

@@ -228,7 +228,7 @@ final GradleHandledError androidXFailureHandler = GradleHandledError(
}
if (hasPlugins && usesAndroidX && !shouldBuildPluginAsAar) {
globals.printStatus(
'The build failed likely due to AndroidX incompatibilities in a plugin. '
'The built failed likely due to AndroidX incompatibilities in a plugin. '
'The tool is about to try using Jetfier to solve the incompatibility.'
);
BuildEvent(

View File

@@ -40,6 +40,9 @@ class GradleUtils {
/// This is the `gradlew` or `gradlew.bat` script in the `android/` directory.
String getExecutable(FlutterProject project) {
final Directory androidDir = project.android.hostAppGradleRoot;
// Update the project if needed.
// TODO(egarciad): https://github.com/flutter/flutter/issues/40460
gradleUtils.migrateToR8(androidDir);
gradleUtils.injectGradleWrapperIfNeeded(androidDir);
final File gradle = androidDir.childFile(
@@ -59,6 +62,37 @@ class GradleUtils {
return null;
}
/// Migrates the Android's [directory] to R8.
/// https://developer.android.com/studio/build/shrink-code
@visibleForTesting
void migrateToR8(Directory directory) {
final File gradleProperties = directory.childFile('gradle.properties');
if (!gradleProperties.existsSync()) {
throwToolExit(
'Expected file ${gradleProperties.path}. '
'Please ensure that this file exists or that ${gradleProperties.dirname} can be read.'
);
}
final String propertiesContent = gradleProperties.readAsStringSync();
if (propertiesContent.contains('android.enableR8')) {
globals.printTrace('gradle.properties already sets `android.enableR8`');
return;
}
globals.printTrace('set `android.enableR8=true` in gradle.properties');
try {
if (propertiesContent.isNotEmpty && !propertiesContent.endsWith('\n')) {
// Add a new line if the file doesn't end with a new line.
gradleProperties.writeAsStringSync('\n', mode: FileMode.append);
}
gradleProperties.writeAsStringSync('android.enableR8=true\n', mode: FileMode.append);
} on FileSystemException {
throwToolExit(
'The tool failed to add `android.enableR8=true` to ${gradleProperties.path}. '
'Please update the file manually and try this command again.'
);
}
}
/// Injects the Gradle wrapper files if any of these files don't exist in [directory].
void injectGradleWrapperIfNeeded(Directory directory) {
globals.fsUtils.copyDirectorySync(
@@ -92,7 +126,7 @@ distributionUrl=https\\://services.gradle.org/distributions/gradle-$gradleVersio
}
}
}
const String _defaultGradleVersion = '6.7';
const String _defaultGradleVersion = '5.6.2';
final RegExp _androidPluginRegExp = RegExp(r'com\.android\.tools\.build:gradle:\(\d+\.\d+\.\d+\)');
@@ -191,9 +225,6 @@ String getGradleVersionFor(String androidPluginVersion) {
if (_isWithinVersionRange(androidPluginVersion, min: '3.4.0', max: '3.5.0')) {
return '5.6.2';
}
if (_isWithinVersionRange(androidPluginVersion, min: '4.0.0', max: '4.1.0')) {
return '6.7';
}
throwToolExit('Unsupported Android Plugin version: $androidPluginVersion.');
return '';
}

View File

@@ -222,6 +222,7 @@ class AndroidBuildInfo {
AndroidArch.x86_64,
],
this.splitPerAbi = false,
this.shrink = false,
this.fastStart = false,
});
@@ -235,6 +236,9 @@ class AndroidBuildInfo {
/// will be produced.
final bool splitPerAbi;
/// Whether to enable code shrinking on release mode.
final bool shrink;
/// The target platforms for the build.
final Iterable<AndroidArch> targetArchs;

View File

@@ -95,6 +95,7 @@ class BuildApkCommand extends BuildSubCommand {
buildInfo,
splitPerAbi: boolArg('split-per-abi'),
targetArchs: stringsArg('target-platform').map<AndroidArch>(getAndroidArchForName),
shrink: boolArg('shrink'),
);
validateBuild(androidBuildInfo);

View File

@@ -84,6 +84,7 @@ class BuildAppBundleCommand extends BuildSubCommand {
}
final AndroidBuildInfo androidBuildInfo = AndroidBuildInfo(await getBuildInfo(),
targetArchs: stringsArg('target-platform').map<AndroidArch>(getAndroidArchForName),
shrink: boolArg('shrink'),
);
validateBuild(androidBuildInfo);
await androidBuilder.buildAab(

View File

@@ -587,10 +587,14 @@ abstract class FlutterCommand extends Command<void> {
void addShrinkingFlag() {
argParser.addFlag('shrink',
negatable: true,
hide: true,
help: 'This flag is deprecated. Code shrinking is always enabled in release builds. '
'To learn more, see: https://developer.android.com/studio/build/shrink-code'
);
defaultsTo: true,
help: 'Whether to enable code shrinking on release mode. '
'When enabling shrinking, you also benefit from obfuscation, '
'which shortens the names of your app’s classes and members, '
'and optimization, which applies more aggressive strategies to '
'further reduce the size of your app. '
'To learn more, see: https://developer.android.com/studio/build/shrink-code',
);
}
void addNullSafetyModeOptions({ @required bool hide }) {