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

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.

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.

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

Related

Where can I source help for native crashes of an expo EAS apk build

I am building an app using react-native on Expo and making sure to build with EAS every few days or whenever I add a new dependency.
After every build, I install the apk on an Android device and run the ios build on a simulator.
On my latest build, the build completes successfully but after installing the apk on android 10, the app opens and crashes once I navigate to a certain page.
It works fine on 3 other android phones.
The code difference between the last successful build that doesn't crash to the current one is minimal however very necessary for the app.
How can I see logs from the native crash in order to find the cause of the problem and hopefully find a fix?
I tried to install sentry but at the bottom of the page, it explains it only follows js issues and is not native.
Any ideas will be helpful
Thanks

Not going to release apk after expo eject

I created a new project at Expo, after which I was already building it using expo buildbut over time I needed to move away from Expo a little and execute an expo eject, and then continue development on regular React Native.
I ran into the following situation: I am trying to build an apk file with the ./gradlew assembleRelease command, but I get a debug build instead of release, I don’t understand why this is happening, I tried to follow the build instructions specifically for the release version - unsuccessfully.
I also tried to create a new project without using Expo - the whole scenario described above worked correctly and I got a release build of my application, and with all that, I compared the android/app/build.gradle files in these two projects and they are almost identical in terms of their configuration.
My main task and problem is to build the release version of the apk file and understand why, with different attempts to build, I only get the debug apk.

React Native Android staging build crashes on startup

I have added 2 more buildTypes in my build.gradle file staging & prestaging alongside with release. When I build and run the release buildType it works fine on the real device, but when I build and run staging or prestaging builds both crashes on startup. The crash report on the device shows the following error:
All the builds work without any issue on iOS
My staging and prestaging build failed because the bundle were not packaged correctly as the error says. This is because when building Android app react-native only add the bundle to the package if the buildType name contains the word release. The simple solution for this is to name the buildType's in such a way that the names contain the word release. I renamed the buildType's to stagingRelease and prestagingRelease.

compile apk on a folder "Android" already created previously in react-native

I'm new to react-native, I've seen tutorials but everyone uses expo. I downloaded this project where they don't use expo. I want to compile this application for android, to finally get an .apk
This application already has a folder called "Android" but inside it does not have its respective .apk. How can I generate it?
this is the repository:
https://github.com/zsajjad/BusinessCard
It would be great if you can attach screenshots of how I should do it
Note. I have the latest version of android studio and I don't see the option of "build"
commands like "gradlew" from the console, they don't work, it's as if I didn't have that command installed
Following instructions for build apk using android studio
Hope you installed node and react native on your machine. If not
please follow the link to install it.Install node and react native
open your command prompt or terminal and redirect to your download project - cd /Businesscard Master (change it according to your project location)
Now enter - npm install
Enter - react-native link
Follow the android related linking instructions on following link react native camera
Hope you know about android camera and storage permissions.
same thing for react native text detector. Because your downloaded project have that packages in package.json
Now open your project android folder in android studio using open existing android project.
Then select build your project from android studio build menu and run it also
Generate apk using build menu- same process you have to follow for native android project
You don't need to use the CLI, that's needlessly complicated and it obscures what Android Studio is actually doing. Here's all you need to do.
Open the whole /Android/ folder in Android Studio. This is your "project" similar to how you open a *.xed file in XCode. Except in Android Studio, you just open up the whole folder to get the build.
Android Studio will now prepare your project using Gradle. If there are any errors in the preparation it will tell you about them. Assuming your gradle and Android Studio versions are compatible and you got no errors, you're now ready to emulate, debug and create a production build. At this point the workflow is similar to using XCode. You'll see emulators under Tools -> AVD Manager.
In the file menus go to Build->Generate APK. You can choose between signed APKs, debug APKs and so on. You'll need the key file if you're signing the APK on your computer, otherwise there's also Google Play signing after you upload the APK.
TL;DR: Just open your /Android/ folder in Android Studio.
Side note: When Android Studio gives you popups to upgrade stuff don't do it. NEVER upgrade Gradle or Android Studio unless the RN / Expo team specifically ask you. This will break your whole project and you will need to rebuild the platform.

How to recompile react native app without rebundling assets

I am working on a react native app, but on its native side.
If I run react-native run-android or run-ios it will first build
the native packages, to then start and complete the packager (at least for production). This process takes a long time. Is there a way to tell the script to use the latest built version of the assets, and just recompule the native binaries?
EDIT: I found out that you can add org.gradle.configureondemand=true to your gradle.properties, in order to skip bundleJsAndAssets. However, I can't find how to add the assets manually later.
you can install Webstorm IDE and then install React Native Console plugins for this.
Finally, link to the your project.
It's likely that you can see what you want