Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Adds namespace to module build file templates #126963

Merged
merged 13 commits into from
May 23, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}'
}

compileSdkVersion {{compileSdkVersion}}

compileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2919,6 +2919,45 @@ 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 namespace.
expect(moduleBuildGradleFileContent.contains("namespace 'com.bar.foo.flutter_project'"), true);
camsim99 marked this conversation as resolved.
Show resolved Hide resolved
expect(moduleAppBuildGradleFileContent.contains("namespace 'com.bar.foo.flutter_project'"), true);
expect(moduleFlutterBuildGradleFileContent.contains("namespace 'com.bar.foo.flutter_project'"), true);

// The namespaces should be conditionalized for AGP <4.2.
expect(moduleBuildGradleFileContent.contains('if (project.android.hasProperty("namespace")) {'), true);
camsim99 marked this conversation as resolved.
Show resolved Hide resolved
expect(moduleAppBuildGradleFileContent.contains('if (project.android.hasProperty("namespace")) {'), true);
expect(moduleFlutterBuildGradleFileContent.contains('if (project.android.hasProperty("namespace")) {'), 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 = '../..';

Expand Down