Skip to content

Commit 99a053d

Browse files
authored
Merge pull request #180 from whalemare/feature/parse-gradle
Parse app/build.gradle additionaly to find packageId
2 parents 441fee4 + 55e82d2 commit 99a053d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/utils.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,22 @@ export const getAndroidCurrentBundleID = () => {
159159
const selector = 'manifest';
160160
const element = getElementFromXml({ filepath, selector });
161161

162-
return element.attr('package');
162+
// parse AndroidManifest.xml
163+
const bundleIDFromManifest = element.attr('package');
164+
if (bundleIDFromManifest) {
165+
return bundleIDFromManifest;
166+
}
167+
168+
// parse android/app/build.gradle
169+
const gradleFile = path.join(APP_PATH, 'android', 'app', 'build.gradle');
170+
const gradleFileContent = fs.readFileSync(gradleFile, 'utf8');
171+
const bundleIDFromGradle = gradleFileContent.match(/applicationId\s+['"](.+)['"]/)[1];
172+
173+
if (bundleIDFromGradle) {
174+
return bundleIDFromGradle;
175+
}
176+
177+
throw new Error(`Unable to get bundleID from manifest or gradle file for project ${APP_PATH}`);
163178
};
164179

165180
/**

0 commit comments

Comments
 (0)