使用 applicationIdSuffix 时 React Native 应用程序不会启动 [英] React Native app won't start when using applicationIdSuffix
问题描述
我正在使用 react-native-codepush@1.16.1-beta
和 部分设置 包括指定 applicationIdSuffix.
I am using react-native-codepush@1.16.1-beta
and part of the setup includes specifying applicationIdSuffix.
我过去在以前的应用程序上设置过,没有任何问题(React Native 0.37).我现在在这个项目(React Native 0.40)中遇到过两次这个错误.我第一次重建我的整个项目时它就消失了.它无缘无故地再次发生,所以我在一个新目录中克隆了我项目的最后一个稳定版本,并得到了同样的错误.
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.
使用react-native run-android
时出现错误.成功构建后发生错误:
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.
如果我从 app/build.gradle
中删除 applicationIdSuffix ".debug"
并且应用程序在我的手机上正常启动,错误就会消失.
The error goes away if I remove applicationIdSuffix ".debug"
from app/build.gradle
and the app starts on my phone without issue.
我的手机是搭载 Android 7.0 的 Nexus 6P.我只在实体设备上试过,因为我没有设置模拟器.
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.
推荐答案
从上面的链接看,已经在github上讨论了很长时间(一年多),而且好像有几个补丁在路上,所以根据您使用的 react-native
版本,我在下面的修复可能有效也可能无效.
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.
这是我(暂时)解决问题的方法.问题是 react-native-cli
尝试使用错误的参数调用 adb shell am start
:
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
什么时候应该调用类似
com.packagename.debug/com.packagename.MainActivity
因此,在您的 react-native
版本被修复之前,您可以使用此命令(如 此代码推送 PR:
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
这不是一个完美的修复,但是 github 上有一个补丁基本上做同样的事情(关于几个问题和拉取请求这里 & 这里).
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).
这篇关于使用 applicationIdSuffix 时 React Native 应用程序不会启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!