Skip to content

Commit 840dc0c

Browse files
karanjthakkarfacebook-github-bot
authored andcommitted
Allow configuring the app source folder for android
Summary: I have been working on integrating React Native into an existing app and realised that the source folder for android code is currently hardcoded as `app`. Being a legacy codebase we can't really change that. So I wanted to be able to customise this folder name so that I can integrate RN seamlessly and start it from the CLI without having to run it from Android Studio. - Create a barebones RN app - `react-native run-android` works successfully - Refactor the name of the app folder inside the android directory to `TestFolderName` using Android Studio - `react-native run-android` now fails - Changing this command to `react-native run-android --appFolder=TestFolderName` works successfully Closes facebook#13273 Differential Revision: D4833396 Pulled By: ericvicenti fbshipit-source-id: 4c62cee6aaa2cc78eede5c7756459430022fffde
1 parent 9d1c626 commit 840dc0c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

local-cli/runAndroid/runAndroid.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function buildAndRun(args) {
8686
: './gradlew';
8787

8888
const packageName = fs.readFileSync(
89-
'app/src/main/AndroidManifest.xml',
89+
`${args.appFolder}/src/main/AndroidManifest.xml`,
9090
'utf8'
9191
).match(/package="(.+?)"/)[1];
9292

@@ -135,7 +135,7 @@ function buildApk(gradlew) {
135135

136136
function tryInstallAppOnDevice(args, device) {
137137
try {
138-
const pathToApk = 'app/build/outputs/apk/app-debug.apk';
138+
const pathToApk = `${args.appFolder}/build/outputs/apk/${args.appFolder}-debug.apk`;
139139
const adbPath = getAdbPath();
140140
const adbArgs = ['-s', device, 'install', pathToApk];
141141
console.log(chalk.bold(
@@ -288,6 +288,10 @@ module.exports = {
288288
description: '--flavor has been deprecated. Use --variant instead',
289289
}, {
290290
command: '--variant [string]',
291+
}, {
292+
command: '--appFolder [string]',
293+
description: 'Specify a different application folder name for the android source.',
294+
default: 'app',
291295
}, {
292296
command: '--appIdSuffix [string]',
293297
description: 'Specify an applicationIdSuffix to launch after build.',

0 commit comments

Comments
 (0)