From 840dc0cc8289eb6f7bce0b33ae5625fe6d3e6cbb Mon Sep 17 00:00:00 2001 From: Karan Thakkar Date: Tue, 11 Apr 2017 12:02:59 -0700 Subject: [PATCH] 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 https://github.com/facebook/react-native/pull/13273 Differential Revision: D4833396 Pulled By: ericvicenti fbshipit-source-id: 4c62cee6aaa2cc78eede5c7756459430022fffde --- local-cli/runAndroid/runAndroid.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/local-cli/runAndroid/runAndroid.js b/local-cli/runAndroid/runAndroid.js index 5cf9d8eba1c..e7fa0790cae 100644 --- a/local-cli/runAndroid/runAndroid.js +++ b/local-cli/runAndroid/runAndroid.js @@ -86,7 +86,7 @@ function buildAndRun(args) { : './gradlew'; const packageName = fs.readFileSync( - 'app/src/main/AndroidManifest.xml', + `${args.appFolder}/src/main/AndroidManifest.xml`, 'utf8' ).match(/package="(.+?)"/)[1]; @@ -135,7 +135,7 @@ function buildApk(gradlew) { function tryInstallAppOnDevice(args, device) { try { - const pathToApk = 'app/build/outputs/apk/app-debug.apk'; + const pathToApk = `${args.appFolder}/build/outputs/apk/${args.appFolder}-debug.apk`; const adbPath = getAdbPath(); const adbArgs = ['-s', device, 'install', pathToApk]; console.log(chalk.bold( @@ -288,6 +288,10 @@ module.exports = { description: '--flavor has been deprecated. Use --variant instead', }, { command: '--variant [string]', + }, { + command: '--appFolder [string]', + description: 'Specify a different application folder name for the android source.', + default: 'app', }, { command: '--appIdSuffix [string]', description: 'Specify an applicationIdSuffix to launch after build.',