Bundling React Native during Android release builds

Bundling #reactnative during Android release builds

  • Again, the sample project is the key, look at the sample app’s build.gradle file.Notice the config section:/** * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets * and bundleReleaseJsAndAssets).
  • By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the * bundle directly from the development server.
  • * * project.ext.react = [ * // the name of the generated asset file containing your JS bundle * bundleAssetName: “index.android.bundle”, * * // the entry file for bundle generation * entryFile: “index.android.js”, * * // whether to bundle JS and assets in debug mode * bundleInDebug: false,…*/These values allow…
  • gradle file, we were able to hook into the bundling command on all our release builds.Our config:// Configures the bundleJS commands for React-Nativeproject.
  • ext.react = [ // whether to bundle JS and assets in debug mode bundleInDebug: false, // whether to bundle JS and assets in release mode bundleInRelease: true, // the root of your RN project, i.e. where “package.json” lives root: from: “path to RN this, we can correctly build our signed,…

I would have expected this to be a straightforward, well documented workflow, but was unfortunately a bit disappointed. It took a bit of digging to finally automate bundling process within our release

I’ve spent some time recently incorporating React Native components into our existing app.

This comes with the extra requirement of release builds requiring the creation of the bundle file.

I would have expected this to be a straightforward, well documented workflow, but was unfortunately a bit disappointed. It took a bit of digging, along with some trial and error, to finally automate the bundling process within our release builds.

The linked page below describes how to properly build a signed apk:

It hints at where to look, but doesn’t do a great job of indicating how to actually configure the project.

file.

Notice the config section:

* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets

* and bundleReleaseJsAndAssets).

* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the

* bundle directly from the development server. Below you can see all the possible configurations

* and their defaults. If you decide to add a configuration block, make sure to add it before the

* `apply from: “../../node_modules/react-native/react.gradle”` line.

* bundleAssetName: “index.android.bundle”,

* entryFile: “index.android.js”,

* bundleInDebug: false,

These values allow the customization of the bundle task behavior including:

file, we were able to hook into the bundling command on all our release builds.

Our config:

Bundling React Native during Android release builds