Gradlew bundleRelease doesnt generate release apk in react-native - react-native

I try to get apk of app. I did it before well. However, I tried to use get apk of other app today but it doesnt give me release apk. why ?
I followed these steps : enter link description here
Normally, it takes 2-3 minutes but now it lasts just 3 sec and doesnt generate apk
it says this :
Deprecated Gradle features were used in this build, making it
incompatible with Gradle 6.0. Use '--warning-mode all' to show the
individual deprecation warnings. See
https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings

I had the same problem. Following command worked for me:
After the ./gradlew bundleRelease command we get a .aab version of our app. To get APK, you should run the app with release version on any device with the below command.
Make sure you have connected an android device
For the production ready app, firstly you have to remove the previous app from the device
Run this command in your-project/:
react-native run-android --variant=release
Then APK can be found in android/app/build/outputs/apk/release
Hope this helps

the short answer uses gradlew assembleRelease instead.
not short answer :) The command you are using gradlew bundleRelease builds an android App bundle. read this:
Difference between apk (.apk) and app bundle (.aab)
and this:
https://developer.android.com/guide/app-bundle
AAB file is new and not all stores support it.

Use gradlew bundleRelease to generate an app bundle (.aab file) and gradlew assembleRelease to generate an apk (.apk file). To install a release on your emulator, use react-native run-android --variant=release. I hope this helps

Cutting the long story short the command gradlew bundleRelease is used to generate an .aab file where as the command gradlew assembleRelease is used to generate .apk file so use the command accordingly

I made a file that called build.sh.
When i want to release a new version of android in ReactNative, just type and press sh ./build.sh in terminal.
My shell script in build.sh file:
npx jetify && cd android && ./gradlew clean && ./gradlew assembleRelease && ./gradlew bundleRelease && cd ..

You can simply open the Build Variants window on the bottom left hand corner of Android Studio and choose release as the current variant:

The following should solve your issue:
Open Android Studio and select "build bundle(s)" from Build/Build Bundle(s)/Apk(s)
Then, open your console and run
cd android && ./gradlew bundleRelease
from your project's root. You may encounter an error such as
Cannot add task 'wrapper' as a task with that name already exists., because overriding built-in tasks are deprecated in 4.8 and produces an error.
To prevent it, please update your android/build.gradle, as follows:
FROM:
task wrapper(type: Wrapper) {
gradleVersion = '4.4'
distributionUrl = distributionUrl.replace("bin", "all")
}
TO:
wrapper {
gradleVersion = '4.4'
distributionUrl = distributionUrl.replace("bin", "all")
}
Lastly, don't forget to convert your .aab file to .apk through bundletool in order to test locally your app (exactly as an APK file)

step - 1) ./gradlew bundleRelease
step - 2) react-native run-android --variant=release
Make sure you have connected an android device
For the production-ready app, firstly you have to remove the previous app from the device

./gradlew app:bundleRelease Will fix your problem for sure.

Related

Not able to build ract-native .apk

project directory: cd android
./gradlew bundleRelease
react-native run-android is working fine, which means dev apk is working on device but, release apk is not build and failed with the above error.
How I can solve this issue?

When I link react-native-video show me a error

When I link react-native-video show me a error
cd android && ./gradlew clean
and test again
This doesn't look like an executed link command but like you try to build an APK and run it.
So be aware, that you remove the previous installed APK from your device before you bundle an new one.

React native error, Execution failed for task ':app:processDebugResources'

Any ideas what this error means?
When I try and run, npm run playground-android, I get the error.
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:processDebugResources'.
java.io.IOException: Could not delete path 'C:\sites\ReactMatt\lower-your-drinking\android\app\build\generated\source\r\debug\org\webkit'.
Any ideas?
I one had similar issues. Below is how I fixed it.
cd android //Navigate into the android folder from the root directory
./gradlew clean // Run this
I hope it helps
On windows
i resolved by
1. cd android
2. ./gradlew clean
Try to close Android Studio while building through the CLI
I had this same problem but gradlew clean did not resolve issue until I removed the android and ios folders from my project and then used these commands;
react-native eject
react-native link
react-native run-android
good luck.
This works for me!
1) Navigate to android : cd android
2) Then run this command: ./gradlew clean
In your project,
Navigate to android => cd android
Then, run this command => ./gradlew clean
Then, open your project's Android kloser from Android Studio and Build Gradle

How to rebuild the entire Android folder?

I have messed the files up in the Android folder and would like to rebuild the Android project inside of the Android folder. How do I do this?
Is it safe to delete the Android folder and then run react-native run-android, will that make it again?
Everything I've coded was wrote in index.android.js.
EDIT: Original answer was written in 2017 (RN v.0.47?). React-native environment evolved and AFAIK this solution is no longer valid.
Probably safe to remove.
I had similar problem, and ./gradlew clean
didn't work, but i found hacky solution from How can I regenerate ios folder in React Native project?
Delete android folder (probably ios too), and then hacky part ->:
react-native upgrade
(it regenerates folders, but it shouldn't be used to upgrade RN..)
And then
react-native link
react-native run-android
It worked for me :)
EDIT : one observation -> react-native sometimes goes crazy and cannot run some commands. Launching a new terminal helps. Bizarre :)
The solution if ur version of react-native >= 0.61.0 :
sudo rm -rf android/ ios/
yarn add react-native-eject
npx react-native eject
enjoy !
Try to do this:
cd android
gradlew clean
cd ..
react-native run-android
Here my solution: (I'm doing this for android)
First command:(Navigation to the Android folder of your react-native project)
cd Android
Second command:
./gradlew clean
Third commmand:
./gradlew cleanBuildCache
I'm not fan of deleting android folder. (I think this not a best approaches)
To generate apk file for production: (First one from /Android)(second one from root project)
./gradlew bundleRelease
react-native run-android --variant=release
Happy coding!!!
Running following commands should do the trick:
sudo rm -rf android/ ios/ #Delete Android and ios folders first...
react-native eject
react-native upgrade //rebuilds android/ios folders
react-native link
react-native run-android
react-native run-ios
Below command will create the android and ios folders.
react-native eject
EXPO users: If you've used Expo then you can run expo run:android
If the folder is malformed (or not present) it will clear and rebuild.
Yes, it is safe to delete the Android and IOS folder and you can make it again by following steps:
1.First Method:
react-native eject <=0.59.0
React-native had this command in the previous version. Running this command will check if the ios and android directories exist and then rebuild whichever one is missing.
sudo rm -rf android/ ios/
react-native eject // Will create new Android and IOS folder.
react-native link
react-native run-android
2.Second Method:
react-native upgrade --legacy true>=0.60.0
Now you should use the react-native upgrade --legacy true command to back up your android folders or ios as the case may be as this command will replace your files.
Funny solution here
Create a new react native app and copy the new android folder over and then run $react-native run-android
In 2022 January:
I am using windows.
Inside my VS code terminal:
rm android/
But to delete Android and ios folders first you do "rm android/ ios/"
It may warn you of your action, accept.
Next:
npm run android //rebuilds android/ios folders
npm run ios //rebuilds android/ios folders

Task 'installRelease' not found in root project 'ReactNativeStarter'. Some candidates are: 'uninstallRelease'

I get the above error when I use the command react-native run-android --variant=release like it said in the react native docs. I signed my key just like it said in the docs but it's not working.
I also couldn't use the command cd android && ./gradlew assembleRelease directly from my project folder. I had to do cd android and then gradlew assembleRelease
From react-native documentation
Note that --variant=release is only available if you've set up signing
as described above.
Verify whether you have followed the steps mentioned in the documentation properly.
For your second issue, try this if you are using Windows:
cd android && gradlew assembleRelease