I've always created my release bundles by running the command ./gradlew bundleRelease
, however, I recently discovered that images with sources from the backend doesn't get to display, while static ones do.
Earlier, I misunderstood the problem to be that static images weren't displaying at all. Then I got suggestions to run
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
, this however created duplicate resources which I had to delete. This turned out not to be the problem since static images were correctly getting render. I haven't found any related solution yet, but would be glad to hear suggestions. Below is what a fraction of my app/build.gradle
looks like:
project.ext.react = [
enableHermes: true, // clean and rebuild if changing
bundleAssetName: "index.android.bundle",
bundleInRelease: true,
bundleInDebug: true
]
apply from: "../../node_modules/react-native/react.gradle"
:
:
:
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
P.S: Creating apk builds with ./gradlew assembleDebug
works perfectly.
After days of fruitless debugging, I got to discover the error wasn't from my code.
Cloudinary, which was serving images from the backend, was returning my images as http instead of https images. And android versions 9 and above wouldn't render http images on release except I ask it to in my AndroidManifest.xml. So, I solved it by doing that. You can reference this stackoverflow question on how to do that.