React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
当前回答
试试这个命令
~/Library/Android/sdk/platform-tools/adb -s emulator-5554 reverse tcp:8081 tcp:8081
其他回答
显然,没有一个答案能帮我解决这个问题。我能够在模拟器上运行反应本机应用程序,但相同的代码(即使服务器正在运行),在设备上运行应用程序时给了我这个错误。
我能够通过在终端中执行以下命令来解决它:
Adb reverse tcp:8081 tcp:8081
如果你已经尝试了上述解决方案中的所有方法,可以尝试以下步骤:
在android/app/src/main/assets中创建文件 执行如下命令:
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
现在运行命令构建react-native run-android
对我来说,这个问题始于升级react-native。为了添加64位支持,必须进行升级。
Before:
--------
Environment:
Node: 10.15.0
npm: 6.9.0
Watchman: 4.9.0
Xcode: Not Found
Android Studio: 3.4 AI-183.6156.11.34.5692245
Packages: (wanted => installed)
react: 16.0.0-alpha.12 => 16.0.0-alpha.12
react-native: ~0.55.2 => 0.55.4
react-native-cli: 2.0.1
After:
------
info
React Native Environment Info:
Binaries:
Node: 10.15.0
npm: 6.9.0
Watchman: 4.9.0
SDKs:
Android SDK:
API Levels: 23, 26, 27, 28
Build Tools: 27.0.3, 28.0.3
System Images: android-28 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.4 AI-183.6156.11.34.5692245
Xcode: /undefined - /usr/bin/xcodebuild
npmPackages:
react: ^16.8.6 => 16.9.0
react-native: 0.59.9 => 0.59.9
npmGlobalPackages:
create-react-native-app: 2.0.2
react-native-cli: 2.0.1
另外,我为升级做了一个重要的改变是在../android/build/build.gradle中
android {
...
defaultConfig {
...
targetSdkVersion 28
...
}
...
}
当我试图将构建(.apk)上传到goole play控制台时,我不得不将targetSdkVersion从27更改为28。 我没有意识到这是导致我上述错误的根本原因。@tom和@tinmarfrutos的立即回答是完全有道理的。
我通过添加android:usesCleartextTraffic="true"到我的android/app/src/debug/AndroidManifest.xml解决了这个问题
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
以下是我在不改变构建的情况下解决这个问题的方法:
1-关闭虚拟设备
2-在物理设备上测试-(它工作)
3-创建新的虚拟设备API 30 Android 10+
4-在新创建的虚拟设备上再次尝试,所有工作都像一个魅力。