React native apk generation fails - react-native

After building the project the APK is generated but it throw the below error when trying to open the app in Android phone.

This happened because you are building a DEBUG type apk, which require JS bundling every time you start the app. You can run react-native start at your project root to startup the metro bundle.
Alternatively, you could build APK for RELEASE mode. Check your project structure, make sure debuggable is set to false.

If you want to run your app in release mode then your can try below command :
react-native run-android --variant="release"
Note: If you have not generated keystore for your project you have to generate it. You can generate keystore by following official doc here.

i think you generate a debug APK, first you must generate a key using jdk -> here is the official doc, here is the summary
generate a keystore
place the generated keystore inside android/app/
Setting up Gradle variables in android/gradle.properties
add release code to android/app/build.gradle
in cmd to generate apk use
cd android && gradlew assembleRelease
the output apk will be in android\app\build\outputs\apk\release
in cmd if you want to generate a bundle use
cd android && gradlew bundleRelease

Related

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.

Debugging signed react native apk

I generated a signed apk but for some reason it does not work as the debug apk does, how can I test it with the debugging feature to view the console and see what issue is there?
if you want to debug the signed apk of react native then please install and run android studio and show the log of signed apk.
2.and second way is"react-native run-android --variant=release" run this command and install signed apk on your phone and then connect with cli and you able to see the log
run project with this commend" react-native run-android --variant=release", release build..

Why I have this problem with the appbundle?

I published this app on the playstore (https://play.google.com/store/apps/details?id=com.brawlcalculator) and I want to reduce the dimension of the app using an app bundle. I created the app with React Native and I used in the same project this command to create the apk(./gradlew clean && ./gradlew assembleRelease) and I successfull published it into the playstore, then I created the app bundle with this command (./gradlew bundleDebug) and when I tried to upload the appbundle it gives me an error: "The appbundle have the wrong key". Does I have to upload the apk and the appbundle together?
assembleRelease signs the APK with your release key, while bundleDebug signs the Bundle with your debug key.
Instead, you should upload the Bundle built with your release key, which you can do using the bundleRelease task.

Do we need to merge node module folder in production environment for react-native app?

Do we need to merge node module folder when code goes to production Do we need to merge node module folder in production for react-native app for react-native app.
If yes then why we need this folder and if no how can we ignore the folder.
No need to manually merge something (e.g. node_modules) to the final app.
You can, of course, use Android Studio or XCode to build the release version, but using below commands to package the apps will be much more handy:
//Build release version
react-native run-android --variant=release
react-native run-ios --configuration Release
Reference:
https://facebook.github.io/react-native/docs/running-on-device.html

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