16
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ReactNativeでAndroidのリリースビルドだけが落ちる

Last updated at Posted at 2018-04-28

概要

具体的にはlogcatで覗ける以下のエラーの対処法について。

04-28 19:51:21.349 22127-22151/? E/AndroidRuntime: FATAL EXCEPTION: Thread-6266
    Process: com.hogehoge, PID: 22127
    java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server.
        at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
        at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:215)
        at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:34)
        at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:232)
        at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1131)
        at com.facebook.react.ReactInstanceManager.access$800(ReactInstanceManager.java:112)
        at com.facebook.react.ReactInstanceManager$4.run(ReactInstanceManager.java:927)
        at java.lang.Thread.run(Thread.java:841)

これは、ReactNativeのAndroidリリースビルドの際にJavaScript側のバンドルが走らず、ランタイムに読み込み対象のバンドルアセットが見つからないためアプリがクラッシュするというもの。

対処法

以下の行を追記すればよい。

/android/app/build.gradle
 project.ext.react = [
+    bundleInDebug: false,
+    bundleInRelease: true,
     entryFile: "index.js"
 ]

react-native bundle というコマンドを長ったらしいオプションと一緒に実行するという解決策もあるようだが、こちらのほうがソースコードとして残る上に次回以降はさくっとまともなリリースビルドが作れるようになるのでラクチン。

参考: https://proandroiddev.com/bundling-react-native-during-android-release-builds-ec52c24e200d

16
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?