mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Update Android plugin templates for newer AGP (#156533)
Now that Flutter requires AGP 7+, we can use Java 11 as the compatibility version in the plugin template rather than 1.8, avoiding warnings with newer toolchains, and we can remove the check for 'namespace' existing that was only necessary to support AGP 4.1. See also https://github.com/flutter/packages/pull/7795 which made this change in Flutter-team-owned plugins. Part of https://github.com/flutter/flutter/issues/156111
This commit is contained in:
parent
225e4aabb5
commit
e8254b2024
@ -22,15 +22,13 @@ rootProject.allprojects {
|
||||
apply plugin: "com.android.library"
|
||||
|
||||
android {
|
||||
if (project.android.hasProperty("namespace")) {
|
||||
namespace = "{{androidIdentifier}}"
|
||||
}
|
||||
namespace = "{{androidIdentifier}}"
|
||||
|
||||
compileSdk = {{compileSdkVersion}}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
|
@ -25,19 +25,17 @@ apply plugin: "com.android.library"
|
||||
apply plugin: "kotlin-android"
|
||||
|
||||
android {
|
||||
if (project.android.hasProperty("namespace")) {
|
||||
namespace = "{{androidIdentifier}}"
|
||||
}
|
||||
namespace = "{{androidIdentifier}}"
|
||||
|
||||
compileSdk = {{compileSdkVersion}}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_1_8
|
||||
jvmTarget = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
@ -25,9 +25,7 @@ rootProject.allprojects {
|
||||
apply plugin: "com.android.library"
|
||||
|
||||
android {
|
||||
if (project.android.hasProperty("namespace")) {
|
||||
namespace = "{{androidIdentifier}}"
|
||||
}
|
||||
namespace = "{{androidIdentifier}}"
|
||||
|
||||
// Bumping the plugin compileSdk version requires all clients of this plugin
|
||||
// to bump the version in their app.
|
||||
@ -55,8 +53,8 @@ android {
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
|
@ -3231,6 +3231,54 @@ void main() {
|
||||
expect(buildGradleContent.contains('namespace = "com.bar.foo.flutter_project"'), true);
|
||||
});
|
||||
|
||||
testUsingContext('Android Java plugin sets explicit compatibility version', () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
|
||||
await runner.run(<String>['create', '--no-pub',
|
||||
'-t', 'plugin',
|
||||
'--org', 'com.bar.foo',
|
||||
'-a', 'java',
|
||||
'--platforms=android',
|
||||
projectDir.path]);
|
||||
|
||||
final File buildGradleFile = globals.fs.file('${projectDir.path}/android/build.gradle');
|
||||
|
||||
expect(buildGradleFile.existsSync(), true);
|
||||
|
||||
final String buildGradleContent = await buildGradleFile.readAsString();
|
||||
|
||||
expect(buildGradleContent.contains('sourceCompatibility = JavaVersion.VERSION_11'), true);
|
||||
expect(buildGradleContent.contains('targetCompatibility = JavaVersion.VERSION_11'), true);
|
||||
});
|
||||
|
||||
testUsingContext('Android Kotlin plugin sets explicit compatibility version', () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
|
||||
await runner.run(<String>['create', '--no-pub',
|
||||
'-t', 'plugin',
|
||||
'--org', 'com.bar.foo',
|
||||
'-a', 'kotlin',
|
||||
'--platforms=android',
|
||||
projectDir.path]);
|
||||
|
||||
final File buildGradleFile = globals.fs.file('${projectDir.path}/android/build.gradle');
|
||||
|
||||
expect(buildGradleFile.existsSync(), true);
|
||||
|
||||
final String buildGradleContent = await buildGradleFile.readAsString();
|
||||
|
||||
expect(buildGradleContent.contains('sourceCompatibility = JavaVersion.VERSION_11'), true);
|
||||
expect(buildGradleContent.contains('targetCompatibility = JavaVersion.VERSION_11'), true);
|
||||
// jvmTarget should be set to the same value.
|
||||
expect(buildGradleContent.contains('jvmTarget = JavaVersion.VERSION_11'), true);
|
||||
});
|
||||
|
||||
testUsingContext('Flutter module Android project contains namespace', () async {
|
||||
const String moduleBuildGradleFilePath = '.android/build.gradle';
|
||||
const String moduleAppBuildGradleFlePath = '.android/app/build.gradle';
|
||||
|
Loading…
Reference in New Issue
Block a user