Not able to build ract-native .apk - react-native

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?

Related

Task :react-native-location:compileDebugJavaWithJavac FAILED while building apk

I'm trying to build my apk & I'm getting this error while building my release apk in react native. Is there any way to fix this react-native-location error?
I was facing this issue while building my apk in react native. To solve this issue you need to:
1- cd android and then ./gradlew clean
2- then in your root directory run yarn jetify or npx jetify

Error when building apk with gradlew assembleRelease

When I build the apk an error message appears like this.
But if the apk builds successfully and then installs it on the smartphone, the application crashes.

Gradlew bundleRelease doesnt generate release apk in 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.

react-native run-android not working on ubuntu 16.04

i have a problem with react native in ubuntu, i have installed,
java jdk 8 (both javac --version) as well as echo $JAVA_HOME gives the proper output.
I have also installed android studio and set the android environment variables as well as the tools and echo $ANDROID_HOME gives output of the sdk location.
I have also installed gradle version 4.4.
I am unable to start the android app using react-native run-android. can any one let me know if i have missed something during installation.
And react-native as well as android studio works fine as I am currently using react-native start to start the metro builder as well as the other react-native cli commands. also android studio and gradle is also able to generate debug as well as release apks with no problems.
The error i get,
Scanning folders for symlinks in /home/igate-naveed/Documents/ReactNative/mobile-app-android/node_modules (16ms)
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
First of all you need to create a project like this:
react-native init myProjectName
Then, start an emulator from Android Studio... Afterwards:
npm install && npm start
in your project directory, and from another terminal, inside your project directory, run :
react-native run-android
Is this working?
Instead of using the npm install manager, I used yarn and it worked for me. In your project directory, just do:
(project-directory)$ yarn
Update the gradle version.
Create new project:
react-native init projectname
Uninstall the npm pack.
Reinstall the npm pack again.
npm start
react-native start
react-native run-android

react-native run-android installs the wrong project on simulator

running:
react-native run-android
The build goes well and then it tries to install one of the dependencies (react-native-vector-icons) on the simulator instead of the main app: