且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

npm run android无法启动Android应用

更新时间:2023-08-21 20:41:52

我认为您可能必须在运行npm run android之前运行metro bundler.

I think you maybe have to run the metro bundler before running npm run android.

react-native start --reset-cache

这将启动捆绑器,因此您必须运行

This will start the bundler, so you will have to run

npm run android

在另一个终端窗口中,但是在相同的项目目录中.下面提到了该脚本!这就是我这样做的方式.自RN 57.2以来一直存在一个问题,即地铁捆绑器存在一些问题,这是解决之道.同时,我已经更新到RN 57.8和最新的RNN,但是我仍然像这样运行该项目.

in a different terminal window, but same project directory. This script is mentioned below! This is the way I'm doing it. It has been an issues since RN 57.2 that there were some problems with the metro bundler and this is the way to go. I have updated in the meantime to RN 57.8 and the latest RNN also, but I still run the project like that.

我还必须提到,我是在具有API 26和Android Studio 3.3的仿真器上运行此程序的,通常,如果如上所述运行它,它将在仿真器中启动该应用程序.

I also have to mention that I'm running this on a emulator with API 26 and Android Studio 3.3 and normally If I run it as I said above, it will start the app in the emulator.

内置脚本

"scripts": {
    "build-android": "cd ./android && ./gradlew app:assembleDebug && ./gradlew installDebug && cd ../",
    "android": "npm run build-android && (adb reverse tcp:8081 tcp:8081 || true) && react-native run-android"
}

编辑

按照RNN小组在此链接下提供的说明在Android上运行您的应用程序尤为重要: RNN小组在Android上运行应用程序的说明模拟器或设备.

It is especially important that you follow the instructions given by RNN team under this link for running your app on Android: The instructions from RNN team for running your app on an Android emulator or device.

编辑2

根据请求,需要API 26,因为这是您的编译SDK版本(当前为RNN v2.7.1)以及您的目标SDK版本.您可以在上述链接的RNN文档中找到此信息.

As per request, API 26 is required as that is your compile SDK version(currently for RNN v2.7.1) as well as your target SDK version. This info you can find in the documentation for RNN at the same link as above.