Android failed to load JS bundle Ask Question

Android failed to load JS bundle Ask Question

I'm trying to run AwesomeProject on my Nexus5 (android 5.1.1).

I'm able to build the project and install it on the device. But when I run it, I got a red screen saying

Unable to download JS bundle. Did you forget to start the development server or connect your device?

In react native iOS, I can choose to load jsbundle offline. How can I do the same thing for Android? (Or at least, where can I configure the server address?)

Update

ローカルサーバーで実行するには、React-Nativeプロジェクトのルートディレクトリで次のコマンドを実行します。

  1. react-native start > /dev/null 2>&1 &
  2. adb reverse tcp:8081 tcp:8081

詳細については、dsissitka の回答をご覧ください。

サーバーなしで実行するには、次のコマンドを実行して jsfile を apk にバンドルします。

  1. アセットフォルダを作成しますandroid/app/src/main
  2. curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"

詳細については、kzzzf の回答をご覧ください。

ベストアンサー1

サーバーを実行しながら JS ファイルを apk にバンドルするには ( react-native start)、バンドルをアプリのアセット ディレクトリにダウンロードします。

curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"

次のリリース (0.12) では、react-native bundleAndroid プロジェクトで期待どおりに動作するようにコマンドを修正します。

おすすめ記事