I\'ve created the project using the following command.
react-native init Awesome_Project
I\'ve started the packager using the following com
When working with react-native-config, I ran into this issue when using applicationIdSuffix
with productFlavors
.
adding --appIdSuffix=[YOUR_FLAVOR]
to my react-native run-android
commands did the job.
e.g
...
flavorDimensions "env"
productFlavors {
dev {
resValue "string", "app_name", "[DEV] My App"
applicationIdSuffix ".dev"
}
staging {
resValue "string", "app_name", "[STG] My App"
applicationIdSuffix ".staging"
}
prod {
resValue "string", "app_name", "My App"
}
}
...
...
"scripts": {
"android": "react-native run-android --variant=devDebug --appIdSuffix=dev",
"android:staging": "react-native run-android --variant=stagingDebug --appIdSuffix=staging",
"android:prod": "react-native run-android --variant=prodDebug",
"android:staging:release": "react-native run-android --variant=stagingRelease --appIdSuffix=staging",
"android:prod:release": "react-native run-android --variant=prodRelease",
},
...
I had a slightly different take on the same issue.
I'm not using react, however I did run into this same issue.
I tried all of the solutions on this page and, oddly enough, each of them worked once. But the problem continued to come back.
In the end I found that doing:
adb uninstall com.appname
followed by a restart of the handset
Solved the issue every time since discovering.
Using a Samsung S8 and Android 3.4.1. No crazy libraries other than OKHttp. Running on a Mac.
make sure your applicationid in gradle and package name is same
Well, This happens when we uninstall apk from mobile manually.It shows MainActivity does not exist. Solution: Go to apps in setting and uninstall the instance of App for all users and run again using react-native run-android will resolve your issue
This is happening if you have enabled build varaints in your app build.gradle file.
When react-native runs, it seems to prefix test or something to your application id which changes the package names in some files but leaves others the same. Your application cannot find .MainActivity because it actually does not exist in the new package namespace that was generated.
Here are some things to try to fix this issue:
/node_modules/react-native/local-cli/runAndroid
This should solve your issue.
If you have appIdSuffix you should add it to the command for react native run command.
eg. react-native run-android --appIdSuffix beta
Should add shortcut to package.json and run via npm.
...
"scripts": {
...
"android-beta": "react-native run-android --appIdSuffix beta",
},
Then just run:
npm run android-beta