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

@@ -237,6 +237,7 @@ void main() {
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Ptrack-widget-creation=true',
'-Pshrink=true',
'-Ptree-shake-icons=true',
'assembleRelease',
],
@@ -265,6 +266,7 @@ void main() {
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Ptrack-widget-creation=true',
'-Pshrink=true',
'-Psplit-debug-info=${tempDir.path}',
'-Ptree-shake-icons=true',
'assembleRelease',
@@ -298,6 +300,7 @@ void main() {
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Ptrack-widget-creation=true',
'-Pextra-front-end-options=foo,bar',
'-Pshrink=true',
'-Ptree-shake-icons=true',
'assembleRelease',
],
@@ -353,6 +356,7 @@ void main() {
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Ptrack-widget-creation=true',
'-Pshrink=true',
'-Ptree-shake-icons=true',
'assembleRelease',
],
@@ -420,6 +424,7 @@ void main() {
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Ptrack-widget-creation=true',
'-Pshrink=true',
'-Ptree-shake-icons=true',
'assembleRelease',
],
@@ -476,6 +481,7 @@ void main() {
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Ptrack-widget-creation=true',
'-Pshrink=true',
'-Ptree-shake-icons=true',
'assembleRelease',
],

View File

@@ -207,6 +207,131 @@ void main() {
});
});
testUsingContext('shrinking is enabled by default on release mode', () async {
final String projectPath = await createProject(
tempDir,
arguments: <String>['--no-pub', '--template=app'],
);
await expectLater(() async {
await runBuildAppBundleCommand(projectPath);
}, throwsToolExit(message: 'Gradle task bundleRelease failed with exit code 1'));
verify(mockProcessManager.start(
<String>[
gradlew,
'-q',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Ptrack-widget-creation=true',
'-Pshrink=true',
'-Ptree-shake-icons=true',
'bundleRelease',
],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
},
overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk,
FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir),
ProcessManager: () => mockProcessManager,
});
testUsingContext('shrinking is disabled when --no-shrink is passed', () async {
final String projectPath = await createProject(
tempDir,
arguments: <String>['--no-pub', '--template=app'],
);
await expectLater(() async {
await runBuildAppBundleCommand(
projectPath,
arguments: <String>['--no-shrink'],
);
}, throwsToolExit(message: 'Gradle task bundleRelease failed with exit code 1'));
verify(mockProcessManager.start(
<String>[
gradlew,
'-q',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Ptrack-widget-creation=true',
'-Ptree-shake-icons=true',
'bundleRelease',
],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).called(1);
},
overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk,
FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir),
ProcessManager: () => mockProcessManager,
});
testUsingContext('guides the user when the shrinker fails', () async {
final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub', '--template=app']);
when(mockProcessManager.start(
<String>[
gradlew,
'-q',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Ptrack-widget-creation=true',
'-Pshrink=true',
'-Ptree-shake-icons=true',
'bundleRelease',
],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenAnswer((_) {
const String r8StdoutWarning =
"Execution failed for task ':app:transformClassesAndResourcesWithR8ForStageInternal'.\n"
'> com.android.tools.r8.CompilationFailedException: Compilation failed to complete';
return Future<Process>.value(
createMockProcess(
exitCode: 1,
stdout: r8StdoutWarning,
),
);
});
await expectLater(() async {
await runBuildAppBundleCommand(
projectPath,
);
}, throwsToolExit(message: 'Gradle task bundleRelease failed with exit code 1'));
expect(
testLogger.statusText,
containsIgnoringWhitespace('The shrinker may have failed to optimize the Java bytecode.'),
);
expect(
testLogger.statusText,
containsIgnoringWhitespace('To disable the shrinker, pass the `--no-shrink` flag to this command.'),
);
expect(
testLogger.statusText,
containsIgnoringWhitespace('To learn more, see: https://developer.android.com/studio/build/shrink-code'),
);
verify(mockUsage.sendEvent(
'build',
'appbundle',
label: 'gradle-r8-failure',
parameters: anyNamed('parameters'),
)).called(1);
},
overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk,
FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir),
ProcessManager: () => mockProcessManager,
Usage: () => mockUsage,
});
testUsingContext("reports when the app isn't using AndroidX", () async {
final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub', '--template=app']);
@@ -224,6 +349,7 @@ void main() {
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Ptrack-widget-creation=true',
'-Pshrink=true',
'assembleRelease',
],
workingDirectory: anyNamed('workingDirectory'),
@@ -279,6 +405,7 @@ void main() {
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Ptrack-widget-creation=true',
'-Pshrink=true',
'assembleRelease',
],
workingDirectory: anyNamed('workingDirectory'),

View File

@@ -2115,7 +2115,7 @@ void main() {
expect(env['flutter'].allows(Version(1, 19, 0)), false);
});
testUsingContext('default app uses Android SDK 30', () async {
testUsingContext('default app uses Android sdk 29', () async {
Cache.flutterRoot = '../..';
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
@@ -2129,8 +2129,8 @@ void main() {
final String buildContent = await globals.fs.file(projectDir.path + '/android/app/build.gradle').readAsString();
expect(buildContent.contains('compileSdkVersion 30'), true);
expect(buildContent.contains('targetSdkVersion 30'), true);
expect(buildContent.contains('compileSdkVersion 29'), true);
expect(buildContent.contains('targetSdkVersion 29'), true);
});
testUsingContext('Linux plugins handle partially camel-case project names correctly', () async {

View File

@@ -441,7 +441,7 @@ Command: /home/android/gradlew assembleRelease
expect(testLogger.statusText,
contains(
'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.'
)
);

View File

@@ -316,7 +316,7 @@ void main() {
any,
label: 'gradle-expected-file-not-found',
parameters: const <String, String> {
'cd37': 'androidGradlePluginVersion: 6.7, fileExtension: .aab',
'cd37': 'androidGradlePluginVersion: 5.6.2, fileExtension: .aab',
},
),
).called(1);
@@ -771,9 +771,6 @@ flutter:
expect(getGradleVersionFor('3.4.0'), '5.6.2');
expect(getGradleVersionFor('3.5.0'), '5.6.2');
expect(getGradleVersionFor('4.0.0'), '6.7');
expect(getGradleVersionFor('4.1.0'), '6.7');
});
testWithoutContext('throws on unsupported versions', () {

View File

@@ -70,7 +70,7 @@ void main() {
'distributionPath=wrapper/dists\n'
'zipStoreBase=GRADLE_USER_HOME\n'
'zipStorePath=wrapper/dists\n'
'distributionUrl=https\\://services.gradle.org/distributions/gradle-6.7-all.zip\n');
'distributionUrl=https\\://services.gradle.org/distributions/gradle-5.6.2-all.zip\n');
}, overrides: <Type, Generator>{
Cache: () => Cache.test(rootOverride: tempDir, fileSystem: memoryFileSystem),
FileSystem: () => memoryFileSystem,
@@ -111,7 +111,7 @@ void main() {
'distributionPath=wrapper/dists\n'
'zipStoreBase=GRADLE_USER_HOME\n'
'zipStorePath=wrapper/dists\n'
'distributionUrl=https\\://services.gradle.org/distributions/gradle-6.7-all.zip\n');
'distributionUrl=https\\://services.gradle.org/distributions/gradle-5.6.2-all.zip\n');
}, overrides: <Type, Generator>{
Cache: () => Cache.test(rootOverride: tempDir, fileSystem: memoryFileSystem),
FileSystem: () => memoryFileSystem,
@@ -119,6 +119,108 @@ void main() {
});
});
group('migrateToR8', () {
MemoryFileSystem memoryFileSystem;
setUp(() {
memoryFileSystem = MemoryFileSystem.test();
});
testUsingContext("throws ToolExit if gradle.properties doesn't exist", () {
final Directory sampleAppAndroid = globals.fs.directory('/sample-app/android');
sampleAppAndroid.createSync(recursive: true);
expect(() {
gradleUtils.migrateToR8(sampleAppAndroid);
}, throwsToolExit(message: 'Expected file ${sampleAppAndroid.path}'));
}, overrides: <Type, Generator>{
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('throws ToolExit if it cannot write gradle.properties', () {
final MockDirectory sampleAppAndroid = MockDirectory();
final MockFile gradleProperties = MockFile();
when(gradleProperties.path).thenReturn('foo/gradle.properties');
when(gradleProperties.existsSync()).thenReturn(true);
when(gradleProperties.readAsStringSync()).thenReturn('');
when(gradleProperties.writeAsStringSync('android.enableR8=true\n', mode: FileMode.append))
.thenThrow(const FileSystemException());
when(sampleAppAndroid.childFile('gradle.properties'))
.thenReturn(gradleProperties);
expect(() {
gradleUtils.migrateToR8(sampleAppAndroid);
},
throwsToolExit(message:
'The tool failed to add `android.enableR8=true` to foo/gradle.properties. '
'Please update the file manually and try this command again.'));
});
testUsingContext('does not update gradle.properties if it already uses R8', () {
final Directory sampleAppAndroid = globals.fs.directory('/sample-app/android');
sampleAppAndroid.createSync(recursive: true);
sampleAppAndroid.childFile('gradle.properties')
.writeAsStringSync('android.enableR8=true');
gradleUtils.migrateToR8(sampleAppAndroid);
expect(testLogger.traceText,
contains('gradle.properties already sets `android.enableR8`'));
expect(sampleAppAndroid.childFile('gradle.properties').readAsStringSync(),
equals('android.enableR8=true'));
}, overrides: <Type, Generator>{
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('sets android.enableR8=true', () {
final Directory sampleAppAndroid = globals.fs.directory('/sample-app/android');
sampleAppAndroid.createSync(recursive: true);
sampleAppAndroid.childFile('gradle.properties')
.writeAsStringSync('org.gradle.jvmargs=-Xmx1536M\n');
gradleUtils.migrateToR8(sampleAppAndroid);
expect(testLogger.traceText, contains('set `android.enableR8=true` in gradle.properties'));
expect(
sampleAppAndroid.childFile('gradle.properties').readAsStringSync(),
equals(
'org.gradle.jvmargs=-Xmx1536M\n'
'android.enableR8=true\n'
),
);
}, overrides: <Type, Generator>{
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('appends android.enableR8=true to the new line', () {
final Directory sampleAppAndroid = globals.fs.directory('/sample-app/android');
sampleAppAndroid.createSync(recursive: true);
sampleAppAndroid.childFile('gradle.properties')
.writeAsStringSync('org.gradle.jvmargs=-Xmx1536M');
gradleUtils.migrateToR8(sampleAppAndroid);
expect(testLogger.traceText, contains('set `android.enableR8=true` in gradle.properties'));
expect(
sampleAppAndroid.childFile('gradle.properties').readAsStringSync(),
equals(
'org.gradle.jvmargs=-Xmx1536M\n'
'android.enableR8=true\n'
),
);
}, overrides: <Type, Generator>{
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any()
});
});
group('GradleUtils.getExecutable', () {
final String gradlewFilename = globals.platform.isWindows ? 'gradlew.bat' : 'gradlew';
@@ -139,6 +241,7 @@ void main() {
androidDirectory.childFile('gradle.properties').createSync();
when(gradleUtils.injectGradleWrapperIfNeeded(any)).thenReturn(null);
when(gradleUtils.migrateToR8(any)).thenReturn(null);
expect(
GradleUtils().getExecutable(FlutterProject.current()),
@@ -170,6 +273,7 @@ void main() {
when(androidProject.hostAppGradleRoot).thenReturn(androidDirectory);
when(gradleUtils.injectGradleWrapperIfNeeded(any)).thenReturn(null);
when(gradleUtils.migrateToR8(any)).thenReturn(null);
GradleUtils().getExecutable(flutterProject);
@@ -200,6 +304,7 @@ void main() {
when(androidProject.hostAppGradleRoot).thenReturn(androidDirectory);
when(gradleUtils.injectGradleWrapperIfNeeded(any)).thenReturn(null);
when(gradleUtils.migrateToR8(any)).thenReturn(null);
GradleUtils().getExecutable(flutterProject);
@@ -230,6 +335,7 @@ void main() {
when(androidProject.hostAppGradleRoot).thenReturn(androidDirectory);
when(gradleUtils.injectGradleWrapperIfNeeded(any)).thenReturn(null);
when(gradleUtils.migrateToR8(any)).thenReturn(null);
GradleUtils().getExecutable(flutterProject);

View File

@@ -919,7 +919,7 @@ String gradleFileWithApplicationId(String id) {
return '''
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
compileSdkVersion 29
defaultConfig {
applicationId '$id'
@@ -936,7 +936,7 @@ version '1.0-SNAPSHOT'
apply plugin: 'com.android.library'
android {
compileSdkVersion 30
compileSdkVersion 29
}
''';
}

View File

@@ -22,6 +22,7 @@ void main() {
'apk',
'--debug',
'--target-platform', 'android-arm',
'--no-shrink',
'--verbose',
], workingDirectory: woringDirectory);
print(result.stdout);