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

feat: extract android applicationId #1951

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply package: "com.android.application"
apply package: "com.facebook.react"

android {
namespace 'com.some.example'
namespace "com.some.example"
defaultConfig {
applicationId "com.example"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`android::getProjectConfig returns an object with android project configuration for flat structure 1`] = `
Object {
"appName": "",
"applicationId": "com.some.example",
"dependencyConfiguration": undefined,
"packageName": "com.some.example",
"sourceDir": "/flat/android",
Expand All @@ -14,6 +15,7 @@ Object {
exports[`android::getProjectConfig returns an object with android project configuration for multiple 1`] = `
Object {
"appName": "",
"applicationId": "com.some.example",
"dependencyConfiguration": undefined,
"packageName": "com.some.example",
"sourceDir": "/multiple/android",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ export function validatePackageName(packageName: string) {

// Search for applicationId at defaultConfig object
export function parseApplicationIdFromBuildGradleFile(buildGradlePath: string) {
if (!buildGradlePath) {
return null;
}
const buildGradle = fs.readFileSync(buildGradlePath, 'utf8');

const matchArray = buildGradle.match(/defaultConfig\s*{([\s\S]*?)}/);
Expand Down
9 changes: 5 additions & 4 deletions packages/cli-platform-android/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ export function projectConfig(
);
}

const applicationId =
getApplicationId(buildGradlePath as string) || packageName;
const applicationId = buildGradlePath
? getApplicationId(buildGradlePath, packageName)
: packageName;

return {
sourceDir,
Expand All @@ -77,8 +78,8 @@ export function projectConfig(
};
}

function getApplicationId(buildGradlePath: string) {
let appId = '';
function getApplicationId(buildGradlePath: string, packageName: string) {
let appId = packageName;

const applicationId = parseApplicationIdFromBuildGradleFile(buildGradlePath);
if (applicationId) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const pkgJson = require('../package.json');
const program = new CommanderCommand()
.usage('[command] [options]')
.version(pkgJson.version, '-v', 'Output the current version')
.option('--verbose', 'Increase logging verbosity')
.enablePositionalOptions();
.option('--verbose', 'Increase logging verbosity');
// .enablePositionalOptions();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you intend to remove this line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah. That should be reverted 👌


const handleError = (err: Error) => {
logger.enable();
Expand Down