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

后端 未结 24 1543
甜味超标
甜味超标 2021-01-30 20:10

I\'ve created the project using the following command.

react-native init Awesome_Project

I\'ve started the packager using the following com

相关标签:
24条回答
  • 2021-01-30 20:35

    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",
    },
    ...
    
    0 讨论(0)
  • 2021-01-30 20:36

    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.

    0 讨论(0)
  • 2021-01-30 20:37

    make sure your applicationid in gradle and package name is same

    0 讨论(0)
  • 2021-01-30 20:38

    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

    0 讨论(0)
  • 2021-01-30 20:39

    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.

    0 讨论(0)
  • 2021-01-30 20:41

    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
    
    0 讨论(0)
提交回复
热议问题