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プロジェクトのルートディレクトリで次のコマンドを実行します。
react-native start > /dev/null 2>&1 &
adb reverse tcp:8081 tcp:8081
詳細については、dsissitka の回答をご覧ください。
サーバーなしで実行するには、次のコマンドを実行して jsfile を apk にバンドルします。
- アセットフォルダを作成します
android/app/src/main
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 bundle
Android プロジェクトで期待どおりに動作するようにコマンドを修正します。