React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:

无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。

我做错了什么?


当前回答

(快速回答)

在我的工作空间尝试解决这个问题后,我找到了一个解决方案。

此错误是因为Metro使用NPM和Node版本的某些组合时出现了问题。

你有两个选择:

Alternative 1: Try to update or downgrade npm and node version. Alternative 2: Go to this file: \node_modules\metro-config\src\defaults\blacklist.js and change this code: var sharedBlacklist = [ /node_modules[/\\]react[/\\]dist[/\\].*/, /website\/node_modules\/.*/, /heapCapture\/bundle\.js/, /.*\/__tests__\/.*/ ]; and change to this: var sharedBlacklist = [ /node_modules[\/\\]react[\/\\]dist[\/\\].*/, /website\/node_modules\/.*/, /heapCapture\/bundle\.js/, /.*\/__tests__\/.*/ ]; Please note that if you run an npm install or a yarn install you need to change the code again.

其他回答

    this works for me on ubuntu
    
    1. if you are having node version 17 first downgrade its version:-
    You can use n for node's version management.
    
    this is very easy to use.
    $ npm install -g n
    
    then you can show your node version:
    $ node -v
    v16.13.2
    
    2. create an assets folder inside root of the project:-
    project\android\app\src\main\assets
    set folder name should be assets

3. now the final step implement the given code inside the project folder:- 

$cd project 
/project$ react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

4. after following all these step react-native was successfully running on my pc

我也有同样的问题。但是这个方法解决了这个问题。 进入android文件夹使用 CD android然后gradlew clean或。/gradlew clean,以适用于你的操作系统的为准。

在重命名我的android包ID后,我在React Native v0.69中遇到了这个问题。

将/android/app/src/debug/java/old_package_name重命名为 /android/app/src/debug/java/new_package_name,我不小心将AndroidManifest.xml的调试版本移动到新创建的路径中。

在把它移回/android/app/src/debug/后,yarn android又可以正常工作了,没有做任何其他的解决方案。有趣的是,这个错误导致了这个错误,所以如果它发生在其他人身上,检查确保你的文件在他们应该在的地方。

M1芯片

验证您的JAVA_HOME路径,在我的M1芯片的情况下,我将其定义为.zprofile

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"

然后执行source ~/。终端z型线

在这之后,它对我起作用了。

对我来说,这个错误是由react-native的升级引起的

从Android 9.0 (API级别28)开始,默认情况下禁用明文支持。

如果您检查了升级差异,您需要创建一个调试清单 android / app / src /调试/ AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
</manifest>

查看更多信息:https://stackoverflow.com/a/50834600/1713216

https://react-native-community.github.io/upgrade-helper/