Robin Claes
Robin Claes

Reputation: 502

React Native: Android Studio doesn't automatically bundle when building

I am building a react native application and we're doing the production release. I noticed that everything works in my iOS app (there's a build phase that generates the offline bundle) but when I run the release build in Android Studio, my app builds but it crashes because it can't find the bundle.

Upvotes: 1

Views: 3610

Answers (2)

Robin Claes
Robin Claes

Reputation: 502

I was able to resolve my own question:

We changed our build types/flavors to match our desired configuration.

The react.gradle file that comes with React Native has a configuration for Debug and Release, these are the common build tasks in a native application. BUT once you change things up you need to tell the react library in android whether or not you want it to bundle for you.

You can find this in your app's build.gradle (under ./android/app/build.gradle). There's an entire block of guidelines commented out that explain you what to do.

In my case I had to add the following code before apply from: "../../node_modules/react-native/react.gradle"

ext.react = [
    bundleInNameDebug: false,
    bundleInNameBeta: true,
    bundleInNameRelease: true
]

NameDebug, NameBeta, NameRelease are all custom BuildTypes/BuildFlavors I have configured.

Upvotes: 5

Harshana
Harshana

Reputation: 543

If you have the signing configuration, it should build a apk for testing when you run react-native run-android --variant=release with the offline bundle. If you want to make a release build for Playstore, run ./gradlew assembleRelease inside the android folder.

You can find more info here

Upvotes: 0

Related Questions