[Android] Adds namespace to module build file templates (#126963)
Adds `namespace` to module `build.gradle` file templates. Fixes https://github.com/flutter/flutter/issues/126403.
This commit is contained in:
@@ -24,6 +24,11 @@ apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
android {
|
||||
// Conditional for compatibility with AGP <4.2.
|
||||
if (project.android.hasProperty("namespace")) {
|
||||
namespace '{{androidIdentifier}}'
|
||||
}
|
||||
|
||||
compileSdkVersion {{compileSdkVersion}}
|
||||
defaultConfig {
|
||||
minSdkVersion {{minSdkVersion}}
|
||||
|
||||
@@ -3,6 +3,11 @@ def flutterPluginVersion = 'managed'
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
// Conditional for compatibility with AGP <4.2.
|
||||
if (project.android.hasProperty("namespace")) {
|
||||
namespace "{{androidIdentifier}}.host"
|
||||
}
|
||||
|
||||
compileSdkVersion {{compileSdkVersion}}
|
||||
|
||||
compileOptions {
|
||||
|
||||
@@ -30,6 +30,11 @@ group '{{androidIdentifier}}'
|
||||
version '1.0'
|
||||
|
||||
android {
|
||||
// Conditional for compatibility with AGP <4.2.
|
||||
if (project.android.hasProperty("namespace")) {
|
||||
namespace '{{androidIdentifier}}'
|
||||
}
|
||||
|
||||
compileSdkVersion flutter.compileSdkVersion
|
||||
ndkVersion flutter.ndkVersion
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
package="{{androidIdentifier}}"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<application tools:node="merge">
|
||||
<application
|
||||
tools:node="merge">
|
||||
<meta-data
|
||||
android:name="flutterProjectType"
|
||||
android:value="module" />
|
||||
|
||||
@@ -2919,6 +2919,48 @@ void main() {
|
||||
expect(buildGradleContent.contains('if (project.android.hasProperty("namespace")) {'), true);
|
||||
});
|
||||
|
||||
testUsingContext('Flutter module Android project contains namespace', () async {
|
||||
const String moduleBuildGradleFilePath = '.android/build.gradle';
|
||||
const String moduleAppBuildGradleFlePath = '.android/app/build.gradle';
|
||||
const String moduleFlutterBuildGradleFilePath = '.android/Flutter/build.gradle';
|
||||
await _createProject(
|
||||
projectDir,
|
||||
<String>['--template=module', '--org', 'com.bar.foo'],
|
||||
<String>[moduleBuildGradleFilePath,
|
||||
moduleAppBuildGradleFlePath,
|
||||
moduleFlutterBuildGradleFilePath,
|
||||
],
|
||||
);
|
||||
|
||||
final String moduleBuildGradleFileContent = await globals.fs.file(globals.fs.path.join(projectDir.path, moduleBuildGradleFilePath)).readAsString();
|
||||
final String moduleAppBuildGradleFileContent = await globals.fs.file(globals.fs.path.join(projectDir.path, moduleAppBuildGradleFlePath)).readAsString();
|
||||
final String moduleFlutterBuildGradleFileContent = await globals.fs.file(globals.fs.path.join(projectDir.path, moduleFlutterBuildGradleFilePath)).readAsString();
|
||||
|
||||
// Each build file should contain the expected namespace.
|
||||
const String expectedNameSpace = "namespace 'com.bar.foo.flutter_project'";
|
||||
expect(moduleBuildGradleFileContent.contains(expectedNameSpace), true);
|
||||
expect(moduleFlutterBuildGradleFileContent.contains(expectedNameSpace), true);
|
||||
const String expectedHostNameSpace = 'namespace "com.bar.foo.flutter_project.host"';
|
||||
expect(moduleAppBuildGradleFileContent.contains(expectedHostNameSpace), true);
|
||||
|
||||
// The namespaces should be conditionalized for AGP <4.2.
|
||||
const String expectedConditional = 'if (project.android.hasProperty("namespace")) {';
|
||||
expect(moduleBuildGradleFileContent.contains(expectedConditional), true);
|
||||
expect(moduleAppBuildGradleFileContent.contains(expectedConditional), true);
|
||||
expect(moduleFlutterBuildGradleFileContent.contains(expectedConditional), true);
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
Pub: () => Pub.test(
|
||||
fileSystem: globals.fs,
|
||||
logger: globals.logger,
|
||||
processManager: globals.processManager,
|
||||
usage: globals.flutterUsage,
|
||||
botDetector: globals.botDetector,
|
||||
platform: globals.platform,
|
||||
stdio: mockStdio,
|
||||
),
|
||||
});
|
||||
|
||||
testUsingContext('Linux plugins handle partially camel-case project names correctly', () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user