'Error type 3. Activity class {com.awesome_project/ com.awesome_project.MainActivity} does not exist in react native (Android device)

I've created the project using the following command.

react-native init Awesome_Project

I've started the packager using the following command.

react-native start

I've connected my Android mobile using USB drive.

I've opened another command prompt and run the following adb command to make sure that only one device is connected.

adb devices

I've started the application using the following command.

react-native run-android

I've been confronted with the following error.

open: Permission denied
open: Permission denied
Starting: Intent { com.awesome_project/.MainActivity }
Error type 3
Error: Activity class {com.awesome_project/ com.awesome_project.MainActivity} does not exist.

Thanks in advance.



Solution 1:[1]

Make sure android/app/build.gradle

defaultConfig {
        applicationId "WHATEVER_THIS_IS" 
}

needs to match android/app/src/main/java/com/app_name/MainActivity.java line one:

package WHATEVER_THIS_IS;

needs to match android/app/src/main/java/com/app_name/MainApplication.java line one:

package WHATEVER_THIS_IS;

needs to match android/app/src/main/AndroidManifest.xml line one:

package="WHATEVER_THIS_IS">

Solution 2:[2]

I uninstalled the app from my device and was not able to see it in my Settings > Apps at all. The error finally went away after I fully uninstalled the app by doing:

adb uninstall com.appname

Solution 3:[3]

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

Solution 4:[4]

adb uninstall packageName Worked for me. for eg: adb uninstall com.abc

Solution 5:[5]

In my case the app just doesn't open automatically, there's no other issue.

Just search for the app icon in your android device (look at location of all applications) and tap on it to open the app manually. The packager will begin to load the app as usual.

So this seems to be a bug here. Unfortunately I don't really know what's causing it.

Solution 6:[6]

I had changed my application id from com.appName to com.companyName.appName, and I had made this update in android>app>build.gradle:

defaultConfig {
  applicationId "com.companyName.appName" // was previously "com.appName"
}

I also changed my file structure from android>app>src>main>java>com>appName to android>app>src>main>java>com>companyName>appName. This is when I got the error.

To fix the error, I simply did a project wide search (CMD-SHIFT-F in Atom) for com.appName, and replaced them all with com.companyName.appName. Problem solved!

Solution 7:[7]

try running adb command to install the apk (should provide more output) from android dir in your project: adb install app/build/outputs/apk/app-debug.apk

In my case was a insufficient storage case

facebook/react-native issue #2885

Solution 8:[8]

I ran into this issue after having a successful build installed on my phone, but long story short I had to uninstall it in order to do a fresh install. After uninstalling the app and trying to do a react-native run-android, I received this error.

Seems that 'uninstalling' an application on some devices only disables it in case you wish to undo the uninstall within a certain time frame. To remedy this, I went into Applications under settings and selected my app and completely uninstalled it. After that I was able to successfully build my app again. Hope this helps someone out.

Solution 9:[9]

You may have deleted/uninstalled your app, but when you check in your settings/apps, you can see that it's not totally uninstalled.

  • Go to Settings.
  • Go to Apps.
  • Select your app. (here, you can verify that your app is not uninstalled properly).
  • Open the overflow menu on the top right and select Uninstall for all users. Done. Try to install then launch your app again.

Source

Solution 10:[10]

I had a similar issue.

BUILD SUCCESSFUL in 38s
27 actionable tasks: 27 executed
info Connecting to the development server...
info Starting the app on "a77c634"...
Starting: Intent { cmp=com.helloworld/.MainActivity }
Error type 3
Error: Activity class {com.helloworld/com.helloworld.MainActivity} does not exist.e

For me, my target device had multiple accounts, so before running the app for another ime, make sure you uninstall it from all accounts.

Solution 11:[11]

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:

  1. adb uninstall com.appname

  2. 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.

Solution 12:[12]

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",
},
...

Solution 13:[13]

For anyone else running into this issue where there are no solutions, if you've linked libraries, make sure that in the settings.gradle file located in ProjectName/android has your app in the include statement, like so: include ':ThirdPartyLibrary', ':app'. I forgot :app and it was build and installing the 3rd party library, but not the actual app, resulting in the problem.

Solution 14:[14]

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:

  • Use FQDN in your Manifest file for the names of the application class and the activity class.
  • Replace your android cli file with this one. This is the file in /node_modules/react-native/local-cli/runAndroid

This should solve your issue.

Solution 15:[15]

Sometimes you get this error because you don't uninstall another previous version of the app, on the LG phones you must go to app's on settings and uninstall the app, this happens to me.

Solution 16:[16]

This issue occurred in my case when I uninstalled the app and tried installing with react-native run-android again.

Following worked for me:
1. Go to Application List from Settings Menu.
2. You will see your application in the list with a message on the left side "App not installed for this user".
3. Open that app in the settings, and then click on the top-right menu icon and select "Uninstall for all users". Hope it helps!

Solution 17:[17]

In my case.. none of the above solution worked. Then, i found the cause of it, i had previously installed application with same package name. I had uninstalled it from my phone, but as i have Oreo device.. it was installed in another user also. So, by uninstalling from all users.. solved my issue. It might not be helpful in your case.. but still this is my workaround.

Solution 18:[18]

I solved it by installing the debug application manually on the mobile phone.

To do so, go to [Project_Path]\android\app\build\outputs\apk\debug\app-debug.apk

Copy this app-debug.apk to your mobile device.

Now, just install it normally in your mobile and you are good to go.

Solution 19:[19]

Huawei p20 lite. Tried to install app from downloads which would not install. Went back to run to install in android studio and got the error error 3 mainactivity does not exist. Had to delete user 'private space ' to solve the problem

Solution 20:[20]

make sure your applicationid in gradle and package name is same

Solution 21:[21]

cd android

and then

./gradlew uA

works for me.

Solution 22:[22]

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

Solution 23:[23]

I tried all the answers posted above, no any outcome for my use case.

It got resolved finally by executing like this:

react-native run-android --variant=alphaDebug

if there are multiple flavours in the app, then we must mention variant through command line

Solution 24:[24]

In my case, I had the wrong package_name (client.client_info.android_client_info.package_name) in google-services.json (from Firebase). It had to match those four values as @parker mentioned.

Solution 25:[25]

This happened to me after changing my project package name. I tried some of the other answers here but nothing worked until I manually deleted the android/build directory, and re-ran react-native run-android forcing the app to be rebuilt from src. Turns out the build was cached including references to the old package name.

Solution 26:[26]

One that worked for me. Works in case if you accidentally uninstalled app from the connected device

  1. Delete apk: sudo rm -rf android/app/build/outputs/apk/debug
  2. Then: sudo npm run android

Solution 27:[27]

This can be caused too if you're downloading a yarn based application and using npm install instead of yarn install to get your dependencies. So try to redownload the project and use the appropriate one.

Solution 28:[28]

for me removing the applicationId worked.

 defaultConfig {
     applicationId "com.companyName.xyz" // remove or comment out this line
    }

Solution 29:[29]

adb uninstall com.packagename. it worked for me.