Closed eihli closed 4 years ago
What the Android docs refer to as "variant" is actually a combination of a build "type" and "flavor". https://developer.android.com/studio/build/build-variants.
"type" is debug vs release. "flavor" is free vs paid, or demo vs full.
I think the proper fix would be to split the --variant
flag into separate --type
and --flavor
flags.
Thank you so much for sending over this PR! Turns out that this is going to be fixed by a PR that we have submitted more than a year ago and never merged.
I came back to the repository and rebased it. Going to ship it within the next release, hoping that the issue goes away.
As @grabbou is no more maintaining this repository so addressing @thymikee and @adamTrz. This issue still persists and not yet fixed. PR #934 has changed and fixed only the launch part of it, however, install APK piece is still broken.
Issue lies in tryInstallAppOnDevice()
function. Use case is when build is triggered using non-interactive manner, via Terminal command, yarn react-native run-android --deviceId=emulator-5554 --mode=demoDebug --appIdSuffix=demo
. As per code, split is done only for selectedTask
, which is populated in case of interactive mode, but not for args.mode
, which is one of the input during manual build.
function tryInstallAppOnDevice(
args: Flags,
adbPath: string,
device: string,
androidProject: AndroidProject,
selectedTask?: string,
) {
try {
// "app" is usually the default value for Android apps with only 1 app
const {appName, sourceDir} = androidProject;
const defaultVariant = (args.mode || 'debug').toLowerCase();
// handle if selected task from interactive mode includes build flavour as well, eg. installProductionDebug should create ['production','debug'] array
const variantFromSelectedTask = selectedTask
?.replace('install', '')
.split(/(?=[A-Z])/);
// create path to output file, eg. `production/debug`
const variantPath =
variantFromSelectedTask?.join('/')?.toLowerCase() ?? defaultVariant;
// create output file name, eg. `production-debug`
const variantAppName =
variantFromSelectedTask?.join('-')?.toLowerCase() ?? defaultVariant;
let pathToApk;
if (!args.binaryPath) {
const buildDirectory = `${sourceDir}/${appName}/build/outputs/apk/${variantPath}`;
const apkFile = getInstallApkName(
appName,
adbPath,
variantAppName,
device,
buildDirectory,
);
pathToApk = `${buildDirectory}/${apkFile}`;
} else {
pathToApk = args.binaryPath;
}
const installArgs = ['-s', device, 'install', '-r', '-d'];
if (args.user !== undefined) {
installArgs.push('--user', `${args.user}`);
}
const adbArgs = [...installArgs, pathToApk];
logger.info(`Installing the app on the device "${device}"...`);
logger.debug(`Running command "cd android && adb ${adbArgs.join(' ')}"`);
execa.sync(adbPath, adbArgs, {stdio: 'inherit'});
} catch (error) {
throw new CLIError(
'Failed to install the app on the device.',
error as any,
);
}
}
Environment
Description
npx react-native run-android
fails withNot found the correct install APK file!
when using flavors.I started getting this error after adding
productFlavors
to mybuild.gradle
Reproducible Demo
It's coming from the following lines in https://github.com/react-native-community/cli/blob/master/packages/platform-android/src/commands/runAndroid/index.ts
The function to get ApkName only checks
variant
, debug/release, and notflavor
(paid/free in my case).For anyone who runs into this issue before it's resolved, my immediate work-around is to just run the
adb
command manually to get the apk to the device.adb -s ${device} install -r -d ${pathToApk}