Unverified Commit 5c691893 authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by GitHub

Migrate AGP and Gradle versions to 7.1.2/7.4 (#99723)

parent 6baca0db
This diff is collapsed.
......@@ -262,7 +262,7 @@ Future<void> main() async {
} catch (e) {
return TaskResult.failure(e.toString());
} finally {
// rmTree(tempDir);
rmTree(tempDir);
}
});
}
......@@ -235,7 +235,6 @@ Future<void> main() async {
await runProjectTest((FlutterProject project) async {
section('gradlew assembleLocal (plugin with custom build type)');
await project.addCustomBuildType('local', initWith: 'debug');
await project.addGlobalBuildType('local', initWith: 'debug');
section('Add plugin');
project.addPlugin('path_provider');
await project.getPackages();
......
......@@ -37,7 +37,8 @@ Future<void> runProjectTest(Future<void> Function(FlutterProject project) testFu
try {
await testFunction(project);
} finally {
rmTree(tempDir);
print('tempDir=$tempDir');
// rmTree(tempDir);
}
}
......@@ -274,26 +275,6 @@ android {
''');
}
Future<void> addGlobalBuildType(String name, {required String initWith}) async {
final File buildScript = File(
path.join(androidPath, 'build.gradle'),
);
buildScript.openWrite(mode: FileMode.append).write('''
subprojects {
afterEvaluate {
android {
buildTypes {
$name {
initWith $initWith
}
}
}
}
}
''');
}
/// Adds a plugin to the pubspec.
/// In pubspec, each dependency is expressed as key, value pair joined by a colon `:`.
/// such as `plugin_a`:`^0.0.1` or `plugin_a`:`\npath: /some/path`.
......
......@@ -77,6 +77,7 @@ final List<GradleHandledError> gradleErrors = <GradleHandledError>[
multidexErrorHandler,
incompatibleKotlinVersionHandler,
minCompileSdkVersionHandler,
jvm11Required,
];
const String _boxTitle = 'Flutter Fix';
......@@ -538,3 +539,25 @@ final GradleHandledError minCompileSdkVersionHandler = GradleHandledError(
},
eventLabel: 'min-compile-sdk-version',
);
@visibleForTesting
final GradleHandledError jvm11Required = GradleHandledError(
test: (String line) {
return line.contains('Android Gradle plugin requires Java 11 to run');
},
handler: ({
required String line,
required FlutterProject project,
required bool usesAndroidX,
required bool multidexEnabled,
}) async {
globals.printBox(
'${globals.logger.terminal.warningMark} You need Java 11 or higher to build your app with this version of Gradle.\n\n'
'To get Java 11, update to the latest version of Android Studio on https://developer.android.com/studio/install.\n\n'
'To check the Java version used by Flutter, run `flutter doctor -v`.',
title: _boxTitle,
);
return GradleBuildStatus.exit;
},
eventLabel: 'java11-required',
);
......@@ -27,8 +27,10 @@ import 'android_sdk.dart';
// For more information about the latest version, check:
// https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
// https://kotlinlang.org/docs/gradle.html#plugin-and-versions
const String templateDefaultGradleVersion = '6.7';
const String templateAndroidGradlePluginVersion = '4.1.0';
const String templateDefaultGradleVersion = '7.4';
const String templateAndroidGradlePluginVersion = '7.1.2';
// TODO(egarciad): Gradle 7 breaks AARs builds: https://github.com/flutter/flutter/issues/101083
const String templateAndroidGradlePluginVersionForModule = '4.1.0';
const String templateKotlinGradlePluginVersion = '1.6.10';
final RegExp _androidPluginRegExp = RegExp(r'com\.android\.tools\.build:gradle:(\d+\.\d+\.\d+)');
......@@ -192,6 +194,9 @@ String getGradleVersionFor(String androidPluginVersion) {
if (_isWithinVersionRange(androidPluginVersion, min: '4.0.0', max: '4.1.0')) {
return '6.7';
}
if (_isWithinVersionRange(androidPluginVersion, min: '7.0', max: '7.4')) {
return '7.4';
}
throwToolExit('Unsupported Android Plugin version: $androidPluginVersion.');
}
......
......@@ -587,6 +587,7 @@ class AndroidProject extends FlutterProjectPlatform {
'androidIdentifier': androidIdentifier,
'androidX': usesAndroidX,
'agpVersion': gradle.templateAndroidGradlePluginVersion,
'agpVersionForModule': gradle.templateAndroidGradlePluginVersionForModule,
'kotlinVersion': gradle.templateKotlinGradlePluginVersion,
'gradleVersion': gradle.templateDefaultGradleVersion,
},
......
......@@ -7,7 +7,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:{{agpVersion}}'
classpath 'com.android.tools.build:gradle:{{agpVersionForModule}}'
}
}
......
......@@ -8,7 +8,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:{{agpVersion}}'
}
}
......
......@@ -11,7 +11,7 @@ buildscript {
dependencies {
// The Android Gradle Plugin knows how to build native code with the NDK.
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:{{agpVersion}}'
}
}
......
......@@ -35,6 +35,7 @@ void main() {
multidexErrorHandler,
incompatibleKotlinVersionHandler,
minCompileSdkVersionHandler,
jvm11Required,
])
);
});
......@@ -955,6 +956,49 @@ Execution failed for task ':app:checkDebugAarMetadata'.
ProcessManager: () => FakeProcessManager.empty(),
});
});
group('Java 11 requirement', () {
testWithoutContext('pattern', () {
expect(
jvm11Required.test('''
* What went wrong:
A problem occurred evaluating project ':flutter'.
> Failed to apply plugin 'com.android.internal.library'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.'''
),
isTrue,
);
});
testUsingContext('suggestion', () async {
await jvm11Required.handler();
expect(
testLogger.statusText,
contains(
'\n'
'┌─ Flutter Fix ─────────────────────────────────────────────────────────────────┐\n'
'│ [!] You need Java 11 or higher to build your app with this version of Gradle. │\n'
'│ │\n'
'│ To get Java 11, update to the latest version of Android Studio on │\n'
'│ https://developer.android.com/studio/install. │\n'
'│ │\n'
'│ To check the Java version used by Flutter, run `flutter doctor -v`. │\n'
'└───────────────────────────────────────────────────────────────────────────────┘\n'
)
);
}, overrides: <Type, Generator>{
GradleUtils: () => FakeGradleUtils(),
Platform: () => fakePlatform('android'),
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.empty(),
});
});
}
bool formatTestErrorMessage(String errorMessage, GradleHandledError error) {
......
......@@ -357,7 +357,7 @@ void main() {
'gradle',
label: 'gradle-expected-file-not-found',
parameters: CustomDimensions.fromMap(<String, String> {
'cd37': 'androidGradlePluginVersion: 6.7, fileExtension: .aab',
'cd37': 'androidGradlePluginVersion: 7.4, fileExtension: .aab',
}),
),
));
......
......@@ -445,6 +445,10 @@ flutter:
expect(getGradleVersionFor('4.0.0'), '6.7');
expect(getGradleVersionFor('4.1.0'), '6.7');
expect(getGradleVersionFor('7.0'), '7.4');
expect(getGradleVersionFor('7.1.2'), '7.4');
expect(getGradleVersionFor('7.2'), '7.4');
});
testWithoutContext('throws on unsupported versions', () {
......
......@@ -73,7 +73,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-7.4-all.zip\n');
});
testWithoutContext('injects the wrapper when some files are missing', () {
......@@ -110,7 +110,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-7.4-all.zip\n');
});
testWithoutContext('injects the wrapper and the Gradle version is derivated from the AGP version', () {
......
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