Unverified Commit aa230140 authored by stuartmorgan's avatar stuartmorgan Committed by GitHub

Add namespace to Android plugin templates (#126354)

Adds the `namespace` property necessary for AGP 8 compatibility to the plugin templates, with the conditional logic to ensure that it doesn't break AGP <4.2, so that new plugins will be maximally compatible.

Part of https://github.com/flutter/flutter/issues/125181
parent 9c72f5a7
......@@ -22,6 +22,10 @@ rootProject.allprojects {
apply plugin: 'com.android.library'
android {
if (project.android.hasProperty("namespace")) {
namespace '{{androidIdentifier}}'
}
compileSdkVersion {{compileSdkVersion}}
compileOptions {
......
......@@ -25,6 +25,10 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
if (project.android.hasProperty("namespace")) {
namespace '{{androidIdentifier}}'
}
compileSdkVersion 31
compileOptions {
......
......@@ -25,6 +25,10 @@ rootProject.allprojects {
apply plugin: 'com.android.library'
android {
if (project.android.hasProperty("namespace")) {
namespace '{{androidIdentifier}}'
}
// Bumping the plugin compileSdkVersion requires all clients of this plugin
// to bump the version in their app.
compileSdkVersion {{compileSdkVersion}}
......
......@@ -2848,6 +2848,77 @@ void main() {
expect(buildContent.contains('targetSdkVersion flutter.targetSdkVersion'), true);
});
testUsingContext('Android Java plugin contains namespace', () 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("namespace 'com.bar.foo.flutter_project'"), true);
// The namespace should be conditionalized for AGP <4.2.
expect(buildGradleContent.contains('if (project.android.hasProperty("namespace")) {'), true);
});
testUsingContext('Android FFI plugin contains namespace', () async {
Cache.flutterRoot = '../..';
final CreateCommand command = CreateCommand();
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['create', '--no-pub',
'-t', 'plugin_ffi',
'--org', 'com.bar.foo',
'--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("namespace 'com.bar.foo.flutter_project'"), true);
// The namespace should be conditionalized for AGP <4.2.
expect(buildGradleContent.contains('if (project.android.hasProperty("namespace")) {'), true);
});
testUsingContext('Android Kotlin plugin contains namespace', () 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("namespace 'com.bar.foo.flutter_project'"), true);
// The namespace should be conditionalized for AGP <4.2.
expect(buildGradleContent.contains('if (project.android.hasProperty("namespace")) {'), true);
});
testUsingContext('Linux plugins handle partially camel-case project names correctly', () async {
Cache.flutterRoot = '../..';
......
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