@react-native-community/cli-platform-android
Advanced tools
Comparing version 2.0.0-alpha.17 to 2.0.0-alpha.18
@@ -83,3 +83,2 @@ "use strict"; | ||
var _default = { | ||
parseDevicesResult, | ||
getDevices, | ||
@@ -86,0 +85,0 @@ getAvailableCPUs |
@@ -72,8 +72,7 @@ "use strict"; | ||
} | ||
/** | ||
* Starts the app on a connected Android emulator or device. | ||
*/ | ||
function runAndroid(argv, ctx, args) { | ||
function runAndroid(argv, config, args) { | ||
if (!checkAndroid(args.root)) { | ||
@@ -98,3 +97,3 @@ _cliTools().logger.error('Android project not found. Are you sure this is a React Native project?'); | ||
startServerInNewWindow(args.port, args.terminal, ctx.reactNativePath); | ||
startServerInNewWindow(args.port, args.terminal, config.reactNativePath); | ||
} | ||
@@ -134,7 +133,3 @@ | ||
if (args.deviceId) { | ||
if (typeof args.deviceId === 'string') { | ||
return runOnSpecificDevice(args, cmd, packageNameWithSuffix, packageName, adbPath); | ||
} | ||
_cliTools().logger.error('Argument missing for parameter --deviceId'); | ||
return runOnSpecificDevice(args, cmd, packageNameWithSuffix, packageName, adbPath); | ||
} else { | ||
@@ -148,8 +143,12 @@ return (0, _runOnAllDevices.default)(args, cmd, packageNameWithSuffix, packageName, adbPath); | ||
if (devices && devices.length > 0) { | ||
if (devices.indexOf(args.deviceId) !== -1) { | ||
const { | ||
deviceId | ||
} = args; | ||
if (devices.length > 0 && deviceId) { | ||
if (devices.indexOf(deviceId) !== -1) { | ||
buildApk(gradlew); | ||
installAndLaunchOnDevice(args, args.deviceId, packageNameWithSuffix, packageName, adbPath); | ||
installAndLaunchOnDevice(args, deviceId, packageNameWithSuffix, packageName, adbPath); | ||
} else { | ||
_cliTools().logger.error(`Could not find device with the id: "${args.deviceId}". Choose one of the following:`, ...devices); | ||
_cliTools().logger.error(`Could not find device with the id: "${deviceId}". Please choose one of the following:`, ...devices); | ||
} | ||
@@ -163,10 +162,14 @@ } else { | ||
try { | ||
_cliTools().logger.info('Building the app...'); // using '-x lint' in order to ignore linting errors while building the apk | ||
// using '-x lint' in order to ignore linting errors while building the apk | ||
const gradleArgs = ['build', '-x', 'lint']; | ||
_cliTools().logger.info('Building the app...'); | ||
(0, _child_process().execFileSync)(gradlew, ['build', '-x', 'lint'], { | ||
stdio: [process.stdin, process.stdout, process.stderr] | ||
_cliTools().logger.debug(`Running command "${gradlew} ${gradleArgs.join(' ')}"`); | ||
(0, _child_process().execFileSync)(gradlew, gradleArgs, { | ||
stdio: 'inherit' | ||
}); | ||
} catch (error) { | ||
throw new (_cliTools().CLIError)('Could not build the app, read the error above for details', error); | ||
throw new (_cliTools().CLIError)('Failed to build the app.', error); | ||
} | ||
@@ -187,9 +190,11 @@ } | ||
_cliTools().logger.info(`Installing the app on the device (cd android && adb -s ${device} install -r -d ${pathToApk}`); | ||
_cliTools().logger.info(`Installing the app on the device "${device}"...`); | ||
_cliTools().logger.debug(`Running command "cd android && adb -s ${device} install -r -d ${pathToApk}"`); | ||
(0, _child_process().execFileSync)(adbPath, adbArgs, { | ||
stdio: [process.stdin, process.stdout, process.stderr] | ||
stdio: 'inherit' | ||
}); | ||
} catch (e) { | ||
_cliTools().logger.error(`${e.message}\nCould not install the app on the device, read the error above for details.`); | ||
} catch (error) { | ||
throw new (_cliTools().CLIError)('Failed to install the app on the device.', error); | ||
} | ||
@@ -294,4 +299,2 @@ } | ||
options: [{ | ||
name: '--install-debug' | ||
}, { | ||
name: '--root [string]', | ||
@@ -301,6 +304,4 @@ description: 'Override the root directory for the android build (which contains the android directory)', | ||
}, { | ||
name: '--flavor [string]', | ||
description: '--flavor has been deprecated. Use --variant instead' | ||
}, { | ||
name: '--variant [string]', | ||
description: "Specify your app's build variant", | ||
default: 'debug' | ||
@@ -337,4 +338,8 @@ }, { | ||
default: _cliTools().getDefaultUserTerminal | ||
}, { | ||
name: '--tasks [list]', | ||
description: 'Run custom Gradle tasks. By default it\'s "installDebug"', | ||
parse: val => val.split(',') | ||
}] | ||
}; | ||
exports.default = _default; |
@@ -8,2 +8,12 @@ "use strict"; | ||
function _chalk() { | ||
const data = _interopRequireDefault(require("chalk")); | ||
_chalk = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _child_process() { | ||
@@ -45,34 +55,24 @@ const data = require("child_process"); | ||
*/ | ||
function getCommand(appFolder, command) { | ||
return appFolder ? `${appFolder}:${command}` : command; | ||
function getTaskNames(appFolder, commands) { | ||
return appFolder ? commands.map(command => `${appFolder}:${command}`) : commands; | ||
} | ||
function toPascalCase(value) { | ||
return value[0].toUpperCase() + value.slice(1); | ||
} | ||
function runOnAllDevices(args, cmd, packageNameWithSuffix, packageName, adbPath) { | ||
try { | ||
const gradleArgs = []; | ||
const tasks = args.tasks || ['install' + toPascalCase(args.variant)]; | ||
const gradleArgs = getTaskNames(args.appFolder, tasks); | ||
if (args.installDebug) { | ||
gradleArgs.push(getCommand(args.appFolder, args.installDebug)); | ||
} else if (args.variant) { | ||
gradleArgs.push(`${getCommand(args.appFolder, 'install')}${args.variant[0].toUpperCase()}${args.variant.slice(1)}`); | ||
} else if (args.flavor) { | ||
_cliTools().logger.warn('--flavor has been deprecated. Use --variant instead'); | ||
_cliTools().logger.info('Installing the app...'); | ||
gradleArgs.push(`${getCommand(args.appFolder, 'install')}${args.flavor[0].toUpperCase()}${args.flavor.slice(1)}`); | ||
} else { | ||
gradleArgs.push(getCommand(args.appFolder, 'installDebug')); | ||
} | ||
_cliTools().logger.debug(`Running command "cd android && ${cmd} ${gradleArgs.join(' ')}"`); | ||
_cliTools().logger.info(`Building and installing the app on the device (cd android && ${cmd} ${gradleArgs.join(' ')})...`); | ||
(0, _child_process().execFileSync)(cmd, gradleArgs, { | ||
stdio: [process.stdin, process.stdout, process.stderr] | ||
stdio: ['inherit', 'inherit', 'pipe'] | ||
}); | ||
} catch (e) { | ||
_cliTools().logger.error('Could not install the app on the device, read the error above for details.\n' + 'Make sure you have an Android emulator running or a device connected and have\n' + 'set up your Android development environment:\n' + 'https://facebook.github.io/react-native/docs/getting-started.html'); // stderr is automatically piped from the gradle process, so the user | ||
// should see the error already, there is no need to do | ||
// `logger.info(e.stderr)` | ||
return Promise.reject(e); | ||
} catch (error) { | ||
throw createInstallError(error); | ||
} | ||
@@ -82,27 +82,24 @@ | ||
if (devices && devices.length > 0) { | ||
devices.forEach(device => { | ||
(0, _tryRunAdbReverse.default)(args.port, device); | ||
(0, _tryLaunchAppOnDevice.default)(device, packageNameWithSuffix, packageName, adbPath, args.mainActivity); | ||
}); | ||
} else { | ||
try { | ||
// If we cannot execute based on adb devices output, fall back to | ||
// shell am start | ||
const fallbackAdbArgs = ['shell', 'am', 'start', '-n', `${packageNameWithSuffix}/${packageName}.MainActivity`]; | ||
(devices.length > 0 ? devices : [undefined]).forEach(device => { | ||
(0, _tryRunAdbReverse.default)(args.port, device); | ||
(0, _tryLaunchAppOnDevice.default)(device, packageNameWithSuffix, packageName, adbPath, args.mainActivity); | ||
}); | ||
} | ||
_cliTools().logger.info(`Starting the app (${adbPath} ${fallbackAdbArgs.join(' ')}...`); | ||
function createInstallError(error) { | ||
const stderr = (error.stderr || '').toString(); | ||
const docs = 'https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment'; | ||
let message = `Make sure you have the Android development environment set up: ${_chalk().default.underline.dim(docs)}`; // Pass the error message from the command to stdout because we pipe it to | ||
// parent process so it's not visible | ||
(0, _child_process().spawnSync)(adbPath, fallbackAdbArgs, { | ||
stdio: 'inherit' | ||
}); | ||
} catch (e) { | ||
_cliTools().logger.error('adb invocation failed. Do you have adb in your PATH?'); // stderr is automatically piped from the gradle process, so the user | ||
// should see the error already, there is no need to do | ||
// `logger.info(e.stderr)` | ||
_cliTools().logger.log(stderr); // Handle some common failures and make the errors more helpful | ||
return Promise.reject(e); | ||
} | ||
if (stderr.includes('No connected devices')) { | ||
message = 'Make sure you have an Android emulator running or a device connected'; | ||
} else if (stderr.includes('licences have not been accepted') || stderr.includes('accept the SDK license')) { | ||
message = `Please accept all necessary SDK licenses using SDK Manager: "${_chalk().default.bold('$ANDROID_HOME/tools/bin/sdkmanager --licenses')}"`; | ||
} | ||
return new (_cliTools().CLIError)(`Failed to install the app. ${message}.`, error); | ||
} | ||
@@ -109,0 +106,0 @@ |
@@ -38,11 +38,19 @@ "use strict"; | ||
try { | ||
const adbArgs = ['-s', device, 'shell', 'am', 'start', '-n', `${packageNameWithSuffix}/${packageName}.${mainActivity}`]; | ||
const adbArgs = ['shell', 'am', 'start', '-n', `${packageNameWithSuffix}/${packageName}.${mainActivity}`]; | ||
_cliTools().logger.info(`Starting the app on ${device} (${adbPath} ${adbArgs.join(' ')})...`); | ||
if (device) { | ||
adbArgs.unshift('-s', device); | ||
_cliTools().logger.info(`Starting the app on "${device}"...`); | ||
} else { | ||
_cliTools().logger.info('Starting the app...'); | ||
} | ||
_cliTools().logger.debug(`Running command "${adbPath} ${adbArgs.join(' ')}"`); | ||
(0, _child_process().spawnSync)(adbPath, adbArgs, { | ||
stdio: 'inherit' | ||
}); | ||
} catch (e) { | ||
_cliTools().logger.error('adb invocation failed. Do you have adb in your PATH?'); | ||
} catch (error) { | ||
throw new (_cliTools().CLIError)('Failed to start the app.', error); | ||
} | ||
@@ -49,0 +57,0 @@ } |
@@ -50,9 +50,11 @@ "use strict"; | ||
_cliTools().logger.info(`Running ${adbPath} ${adbArgs.join(' ')}`); | ||
_cliTools().logger.info('Connecting to the development server...'); | ||
_cliTools().logger.debug(`Running command "${adbPath} ${adbArgs.join(' ')}"`); | ||
(0, _child_process().execFileSync)(adbPath, adbArgs, { | ||
stdio: [process.stdin, process.stdout, process.stderr] | ||
stdio: 'inherit' | ||
}); | ||
} catch (e) { | ||
_cliTools().logger.info(`Could not run adb reverse: ${e.message}`); | ||
_cliTools().logger.warn(`Failed to connect to development server using "adb reverse": ${e.message}`); | ||
} | ||
@@ -59,0 +61,0 @@ } |
{ | ||
"name": "@react-native-community/cli-platform-android", | ||
"version": "2.0.0-alpha.17", | ||
"version": "2.0.0-alpha.18", | ||
"main": "build/index.js", | ||
"dependencies": { | ||
"@react-native-community/cli-tools": "^2.0.0-alpha.17", | ||
"@react-native-community/cli-tools": "^2.0.0-alpha.18", | ||
"logkitty": "^0.4.0", | ||
@@ -16,3 +16,3 @@ "node-fetch": "^2.2.0", | ||
], | ||
"gitHead": "483003e5d6ad4769067bb12e6feb3790cd759046" | ||
"gitHead": "1e60601fac5e5a6d5bd4a55b98ba73aa6c23633f" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1354
56990