Warm tip: This article is reproduced from stackoverflow.com, please click
android react-native adb build.gradle

React Native app won't start when using applicationIdSuffix

发布于 2020-03-28 23:17:06

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.

Questioner
Jameal G
Viewed
230
Laurent S 2017-04-30 03:13

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