Thanks so much for filing an issue or feature request! Please fill out the following (wherever relevant):
I followed the instructions in the README for installing both debug and release builds simultaneously on the same device. It mostly works, but when I build the debug version with react-native run-android it installs the debug version on the device but launches the release version when the install is done. Not a serious problem but a minor annoyance to have to launch the debug version by hand. There must be a setting missing in the gradle files.
Sometimes, when the release version is already running, run-android will print the following message:
Starting: Intent { cmp=io.malamode/.MainActivity }
Warning: Activity not started, its current task has been brought to the front
(The more info the faster we will be able to address it!)
Hi @chetstone
It is problem of react-native, which ignores applicationIdSuffix property from build.gradle file. There are two ways to resolve this problem - either run debug version manually (something that you already mentioned) or run the following script from your app directory:
cd android && ./gradlew installDebug && adb -s <DEVICE_ID> shell am start -n <PACKAGE_ID>.debug/<PACKAGE_ID>.MainActivity
cd android && gradlew.bat installDebug && adb -s <DEVICE_ID> shell am start -n <PACKAGE_ID>.debug/<PACKAGE_ID>.MainActivity
where PACKAGE_ID is you package identifier (something like com.mycompany.myapp) and DEVICE_ID is a device identifier as listed by adb devices
Based on this I'd suggest you to report this issue in react-native or use these workarounds.
@matrosov-nikita Thanks very much for the script. I'll give it a try.
This issue has been reported on Product Pains and there is a PR pending to fix it.
Cool, thanks for the links, @chetstone!
@matrosov-nikita: thanks for your workaround which is still necessary even a year after your suggestion. this issue is still valid and its initial PR pointed out from @chetstone led to a corresponding PR which has been closed misleadingly without merge. At least it has gotten some attention since last week. Unfortunately it seems like a new issue needs to be filed..
a short addition
-d instead of -s <DEVICE_ID>
can be used if there is only one device connected via usb. e.g.
$ cd android && ./gradlew installAlphaRelease && adb -d shell am start -n <PACKAGE_ID>.alpha/<PACKAGE_ID>.MainActivity
while Alpha is a build flavour
You can run your app with the appIdSuffix param
react-native run-android --appIdSuffix "debug"
You can find all the available params here: https://github.com/facebook/react-native/blob/master/local-cli/runAndroid/runAndroid.js#L301
I'm writing new versions of old apps, and thus I have inherited old app id's.
My code have the package com.common.package (in source files and AndroidManifest.xml).
My build.gradle contains
buildTypes {
debug {
}
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
flavorDimensions "appName"
productFlavors {
appAAA {
dimension "appName"
applicationId "com.AAA.app"
versionCode 100
versionName "3.0.0"
}
appBBB {
dimension "appName"
applicationId "com.BBB.app"
versionCode 100
versionName '3.0.0'
}
}
First the app can be installed with gradlew
cd android && ./gradlew installAppBBBDebug
The I can start it manually with
adb -s emulator-5554 shell am start -n com.BBB.app/com.common.package.MainActivity
This is a bloody hassle. I would rather not have to mess with it like this.
This is still an issue using android debug with launch.json in vscode. Is there no fix yet or planned?
As @matrosov-nikita mentioned, react-native is ignoring applicationIdSuffix property from build.gradle.
This is still an issue. The code in this PR seems to solve it, but in the meantime, I guess the CLI has been moved here and since it fails to find the correct package, I assume the new file has a bug.
My assumption is that the manifest file is not picked up correctly from the build folder in android.
Most helpful comment
You can run your app with the appIdSuffix param
You can find all the available params here: https://github.com/facebook/react-native/blob/master/local-cli/runAndroid/runAndroid.js#L301
Source: https://stackoverflow.com/a/48340408/5791025