19

I am using react-native-codepush@1.16.1-beta and part of the setup includes specifying applicationIdSuffix.

I've set this up on a previous app in the past with no issues (React Native 0.37). I've encountered this error twice now with this project (React Native 0.40). The first time I rebuilt my entire project and it went away. It started happening again for no apparent reason so I cloned the last stable version of my project in a fresh directory, and got the same error.

The error occurs when using react-native run-android. The error happens after a successful build:

Starting: Intent { cmp=com.packagename/.MainActivity }
Error type 3
Error: Activity class {com.packagename/com.packagename.MainActivity} does not exist.

The error goes away if I remove applicationIdSuffix ".debug" from app/build.gradle and the app starts on my phone without issue.

My phone is a Nexus 6P with Android 7.0. I've only tried on a physical device since I don't have simulators set up.

I've triple checked everything against to my other project and I don't believe it's a configuration issue.

Jameal G
  • 324
  • 3
  • 10

5 Answers5

39

What Im using for React Native 0.60+ with multiple build configurations

In my app/bundle.gradle file I have the following configuration

productFlavors {
   dev {
       applicationId "com.my.app.development"
       dimension "standard"
   }
   production {
       applicationId "com.my.app"
       dimension "standard"
   }
}

buildTypes {
   release {
        // your release build values
   }
   debug {
       // your debug build values
       debuggable true
   }
}

For a standard debug build

react-native run-android --variant devDebug --appIdSuffix \"development\"

For a Staging build (dev variables, but built for release)

react-native run-android --variant devRelease --appIdSuffix \"development\"

For a Release build

react-native run-android --variant productionRelease


this worked for me on react-native 0.50.3

react-native run-android --appIdSuffix "debug"

Simon
  • 2,065
  • 3
  • 21
  • 28
  • You can see all the available params here - https://github.com/facebook/react-native/blob/master/local-cli/runAndroid/runAndroid.js#L301 – ajack Apr 08 '18 at 11:24
  • File location has changed: https://github.com/react-native-community/react-native-cli/blob/master/packages/cli/src/logAndroid/logAndroid.js – friederbluemle Feb 28 '19 at 04:38
  • ...and has changed again: https://github.com/react-native-community/cli/blob/master/docs/commands.md#run-android – HondaGuy Aug 27 '19 at 05:30
9

From the link above, it's been discussed for a long time (over a year) on github, and there seems to be a few patches on their way, so my fix below may or may not work depending on the version of react-native you're using.

Here's how I've (temporarily) solved the issue. The problem is that react-native-cli tries to call adb shell am start with the wrong argument:

com.packagename/com.packagename.MainActivity

when it should be calling something like

com.packagename.debug/com.packagename.MainActivity

So until your version of react-native is fixed, you can use this command (as recommended in this code-push PR:

cd android && ./gradlew installDebug && adb -s <DEVICE_ID> shell am start -n com.packageName.debug/com.packageName.MainActivity

It's not a perfect fix, but there's a patch on github which does essentially the same thing (in relation to a couple of issues and pull requests here & here).

Laurent S
  • 4,106
  • 3
  • 26
  • 50
  • This solution has the advantage of not introducing a new build variant/flavor if none is needed. All devs can have a run configuration for debug and one for prod – avalancha Apr 08 '23 at 09:24
8

If you have a custom applicationId (different from your Java package name), you have to specify it when running the run-android command

npx react-native run-android --appId com.custompackagename.debug

You will see the result at the end when react is starting the intent

Starting: Intent { cmp=com.custompackagename.debug/com.packagename.MainActivity
Jonasjso
  • 361
  • 3
  • 3
1

I did not find a real solution either. Right now I am using a workaround where I don't use react-native run-... but use AndroidStudio directly.

I found a hint at http://sex-gril.com/project/45838.html which is saying that you have to add the package name to your defaultConfig in the build.gradle.

android {
    ...
    defaultConfig {
        ...
        resValue "string", "build_config_package", "Your App ID LIke in Manifest"
    }
}

But that did not work for me =/.

3rikWtloo
  • 39
  • 1
  • 4
0

I had the same problem, I use applicationIdSuffix to configure a custom environment. From the documentation, we have:

--appId

Specify an applicationId to launch after the build. If not specified, the
package of AndroidManifest.xml will be used.

--appIdSuffix

Specify an applicationIdSuffix to run after the build.

So you should run your application like this

npx react-native run-android --appIdSuffix suffix

NOTE: Your suffix should not contain a dot prefix, it will be added automatically.

Taur
  • 514
  • 3
  • 8