7
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.

React Native Android 版の Debug ビルドにバンドルを埋め込む

Last updated at Posted at 2018-09-18

React Native アプリの開発時は、起動するたびに Metro Bundler から bundle ファイルをロードしますが、デバッグ版でもリリース版と同様に、bundle ファイルを apk に組み込んだ状態でビルドする方法です。ちょっと古めですが、以下は React Native 0.53.3 で試した情報です。

方法

eject 済みであることが前提になります。

build.gradle の修正

  • プロジェクトの ./android/app/build.gradle の project.ext.reactbundleInDebug: true を追加します。
  • さらに開発モードも無効化(__dev__ = false にする1)なら、devDisabledInDebug: true を追加します。
./android/app/build.gradle

project.ext.react = [
    entryFile: "index.js",
    bundleInDebug: true,
    devDisabledInDebug: true,
]

apply from: "../../node_modules/react-native/react.gradle"

buildIn〜devDisabledIn〜 部は、実際はフレーバー名とビルドタイプを指定するものです。詳しくはbuild.gradle のコメント欄参照。

gradle.properties の修正

Configure On Demand が有効だと、バンドルファイルが埋め込まれないことがあるようです。
ので、gradle.properties で明示的に設定をオフにします。

gradle.properties
org.gradle.configureondemand=false

ビルド

bundleInDebug の true / false を切り替えたときは、クリーンビルドしないと反映されないことがありました。以下は gradle デーモンも停止し、ビルド結果もすべて削除してからクリーンビルドしています。

$ ./gradlew --stop
$ rm -rf ./app/build
$ ./gradlew clean & ./gradlew assembleDebug
  1. 端末を振ると出てくる開発者メニューの無効化にはなりません。開発者メニューも無効にする場合は、build.gradle の buildTypes の debug バリアントで debuggablefalse にします。

7
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
7
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?