React Native crashes in release mode - react-native

When I run react-native run-android --variant=release it is continuously crashing without any errors on both the simulator and mobile phone.
I tried the suggestions in this article but when I run ./gradlew clean && ./gradlew assembleRelease it gives this error:
> Task :react-native-navigation:verifyReleaseResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-navigation:verifyReleaseResources'.
> java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
/Users/balwindersingh/Desktop/WEBSITETOON/teamwallpaper/node_modules/react-native-navigation/android/app/build/intermediates/res/merged/release/values-v28/values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
/Users/balwindersingh/Desktop/WEBSITETOON/teamwallpaper/node_modules/react-native-navigation/android/app/build/intermediates/res/merged/release/values-v28/values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
/Users/balwindersingh/Desktop/WEBSITETOON/teamwallpaper/node_modules/react-native-navigation/android/app/build/intermediates/res/merged/release/values/values.xml:3083: error: resource android:attr/fontVariationSettings not found.
/Users/balwindersingh/Desktop/WEBSITETOON/teamwallpaper/node_modules/react-native-navigation/android/app/build/intermediates/res/merged/release/values/values.xml:3084: error: resource android:attr/ttcIndex not found.
error: failed linking references.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 59s
180 actionable tasks: 168 executed, 12 up-to-date

The issue is probably that you are building your app with sdkVersion 28 while react-navigation uses an older version.
You could overwrite the version in your android/build.gradle file:
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion compileSdkVersion
buildToolsVersion "$buildToolsVersion"
}
}
}
}
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 27
supportLibVersion = "28.0.0"
}
(I am not sure whether this is the best way though...)
Alternatively you could fork react-navigation and change the version in their android/app/build.gradle file to 28.

Don't delete the drawable folders in your res folder. if you followed that article then deleting those drawable folders causing the error. try without deleting drawable folders.

In my case I had left a console.log() statement in app therefore it was running completely fine on debug mode but crashed on release mode. After digging my mind in, I realized that it was this small problem.
So do check your app pages as well for such minor problems.

Related

Error in second time execute application React Native

I'm a difficulty to run my application in genymotion.
When a first time i run the commands npx react-native start and npx react-native run-android, my application works ok, but when i install libraries which i use in my project and follow the commands again the console show me a error, i tried uninstall the application from android emulator, ./gradlew clean but nothing to work.
My ambiance variable it's ok, because the application run in first time which execute.
Somebody can help? Please
Follow the error:
npx react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 956 file(s) to forward-jetify. Using 4 workers...
info JS server already running.
info Installing the app...
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
> Task :app:checkDebugAarMetadata FAILED
7 actionable tasks: 2 executed, 5 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not download material-1.1.0.aar (com.google.android.material:material:1.1.0)
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/google/android/material/material/1.1.0/material-1.1.0.aar'.
> Read timed out
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 4m 37s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not download material-1.1.0.aar (com.google.android.material:material:1.1.0)
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/google/android/material/material/1.1.0/material-1.1.0.aar'.
> Read timed out
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 4m 37s
at makeError (/mnt/hd/www/react-native/projects/tutorial-projects/notas/node_modules/execa/index.js:174:9)
at /mnt/hd/www/react-native/projects/tutorial-projects/notas/node_modules/execa/index.js:278:16
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async runOnAllDevices (/mnt/hd/www/react-native/projects/tutorial-projects/notas/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:5)
at async Command.handleAction (/mnt/hd/www/react-native/projects/tutorial-projects/notas/node_modules/#react-native-community/cli/build/index.js:186:9)
info Run CLI with --verbose flag for more details.
I solved this issue.
I change my build.gradle file.
Before:
ext {
buildToolsVersion = "29.0.3"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
ndkVersion = "20.1.5948944"
}
After:
buildscript {
ext {
buildToolsVersion = "29.0.3"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "20.1.5948944"
}

Failed to build react native app after linking with ble-plx

react-native run-android failed after linking with react-native-ble-plx
Task :react-native-ble-plx:compileDebugJavaWithJavac FAILED
This is a newly created app with react-native init, didn't change anything except the min sdk.
Already tried to clean project, set min sdk to 18, tried to build with android studio to get more specific error but still can't understand where is the problem coming from.
The Error i get:
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
12 actionable tasks: 2 executed, 10 up-to-date
warning: [options] source value 7 is obsolete and will be removed in a future release
warning: [options] target value 7 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
/Users/oriamd/Documents/MyDev/DudeWheresMyCar/node_modules/react-native-ble-plx/android/src/main/java/com/polidea/reactnativeble/converter/RxBleScanResultConverter.java:3: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
^
/Users/oriamd/Documents/MyDev/DudeWheresMyCar/node_modules/react-native-ble-plx/android/src/main/java/com/polidea/reactnativeble/wrapper/Characteristic.java:5: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
^
full logs here :
https://pastebin.com/NJAmjUJm
Can supply more information if needed.
Thank you
This issue is similar to this issue.
As mentioned in #Kreator answer it is related to some packages that are not converted to AndroidX.
To fix this issue you can use jetifier.
I have the same issue mentioned in the question and these steps solved it and application run again.
First, use Android Studio's refactoring tool to convert your app re: the Android developer docs
npm install --save-dev jetifier
npx jetify
npx react-native run-android (your app should correctly compile and work)
Call npx jetify run in the postinstall target of your package.json (Any time your dependencies update you have to jetify again)
Problem was that i was using Android Studio Preview, and with that AndroidX and more unsupported packages.
I HAD THIS SAME ISSUE.
"Task :react-native-ble-plx:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task
':react-native-ble-plx:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 54s
error Failed to install the app. Make sure you have the Android
development environment set up:
https://reactnative.dev/docs/environment-setup.
Solution
this was my build.gradle project:
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
ndkVersion = "21.4.7075529"
kotlin_version = "1.6.0" // Update this to your version
}
repositories {
google()
mavenCentral()
}
...
}
I changed the some version to as following:
compileSdkVersion = 29
targetSdkVersion = 29
And now the Build is successful!

Android dependency 'com.airbnb.android:lottie' has different version for the compile (2.5.5)and runtime (2.5.6) classpath

I get this error when I try to run my react native app I manually changed the version to 2.5.6 but I got different error here below:
[CIRCULAR REFERENCE:com.android.tools.r8.ApiLevelException: Invoke-customs ae only supported starting with Android O (--min-api 26)]
FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.
com.android.build.api.transform.TransformException: com.android.builder.dexing.DexrchiveBuilderException: com.android.builder.dexing.DexArchiveBuilderException: Faile to process C:\Users\Dell.gradle\caches\transforms-1\files-1.1\lottie-2.5.6.aar\adddb5cebf38e2804a0cb857e5cf364\jars\classes.jar
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug optin to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 21s
147 actionable tasks: 1 executed, 146 up-to-date
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
Here is my dependency
dependencies {
compile project(':lottie-react-native')
implementation project(':lottie-react-native')
implementation('com.airbnb.android:lottie:2.5.5') {
exclude group: 'com.android.support'
}
It looks like you have added an additional dependency to your dependencies.
Looking at the example project in the lottie-react-native repo they only add the compile project(':lottie-react-native')
Here are the dependencies that they have for their example project. (Note that compile should be replaced with implementation)
dependencies {
compile project(':lottie-react-native')
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:support-annotations:26.1.0'
compile "com.facebook.react:react-native:+" // From node_modules
}
Notice that they do not have
implementation('com.airbnb.android:lottie:2.5.5') {
exclude group: 'com.android.support'
}
In any project that I have used Lottie I have never added
implementation('com.airbnb.android:lottie:2.5.5')
If you remove that line, you should solve your problem.
Invoke-customs are only supported starting with Android O (--min-api 26)]
This error is caused by the fact that the Lottie dependency requires Java 8 bytecode. So to get it to work we need to enable desugaring in the app/build.gradle. So we need to tell it to use Java 8. We do this by updating the android section.
android {
defaultConfig {
...
}
// add the following
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

React Native Project won't build on expo or on avd

I just got a react native project and I am trying to run it. When I run:
react-native run-android
, this is my output.
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
> Configure project :app
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
Checking the license for package Android SDK Platform 27 in C:\Users\oriont\AppData\Local\Android\Sdk\licenses
Warning: License for package Android SDK Platform 27 not accepted.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
platforms;android-27 Android SDK Platform 27
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html
Using Android SDK: C:\Users\oriont\AppData\Local\Android\Sdk
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
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
Command failed: gradlew.bat installDebug
Error: Command failed: gradlew.bat installDebug
at checkExecSyncError (child_process.js:637:11)
at Object.execFileSync (child_process.js:655:13)
at runOnAllDevices (C:\Users\oriont\dev\proj\node_modules\react-native\local-cli\runAndroid\runAndroid.js:299:19)
at buildAndRun (C:\Users\oriont\dev\proj\node_modules\react-native\local-cli\runAndroid\runAndroid.js:135:12)
at isPackagerRunning.then.result (C:\Users\oriont\dev\proj\node_modules\react-native\local-cli\runAndroid\runAndroid.js:65:12)
at processTicksAndRejections (internal/process/next_tick.js:81:5)
I have followed all of the directions on the facebook getting started page, but this error keeps popping up. When I run it, I have my AVD running, which is on Android 9. From there, I tried to accept the licenses.
C:\Users\oriont\AppData\Local\Android\Sdk\tools\bin>sdkmanager.bat --licenses
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 5 more
And I don't know what to do from here. I tried expo and it was another rabbit hole... Someone please help! Thanks!
Android Studio > Preferences > Appearance & Behavior > System Settings > Android SDK
Tick the latest Android versions, click Apply.
It's at this point where Android will ask you to agree to its license(s) and the updated version(s) will be installed.
From Here GitHub
I read an answer (Thank you) but it sadly didn't work. I now think that the licenses aren't the problem anymore. I had realized that the project wanted android 27 and I had android 28 installed, so I tried downgrading to android 27. That didn't work, so I just upgraded (I think) the project to android 28 by changing ext in android/build.gradle to:
ext {
buildToolsVersion = "28.0.0"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 26
supportLibVersion = "28.0.0"
}
and add this to android in android/app/build.gradle
packagingOptions {
pickFirst 'lib/x86/libc++_shared.so'
pickFirst 'lib/x86_64/libjsc.so'
pickFirst 'lib/arm64-v8a/libjsc.so'
pickFirst 'lib/arm64-v8a/libc++_shared.so'
pickFirst 'lib/x86_64/libc++_shared.so'
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
}
I also had java 10.0.2 installed and I downgraded to java 8. (not sure if that made a difference)
Anyways I hope this helps people get their old projects up to date!

Getting "verifyReleaseResources" error after upgrading React Native

I'm trying to upgrade an application to React Native 0.57.1. I think I've followed all the steps, upgraded all the right files, yet I'm still getting an error that I cannot understand:
:react-native-document-picker:compileReleaseSources UP-TO-DATE
:react-native-document-picker:mergeReleaseResources UP-TO-DATE
:react-native-document-picker:verifyReleaseResourcesC:\Users\USERNAME\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\b3b5480809d523e6f8b8de92faafbcda\res\values-v26\values-v26.xml:9:5-12:13: AAPT: error: resource android:attr/colorError not found.
C:\Users\USERNAME\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\b3b5480809d523e6f8b8de92faafbcda\res\values-v26\values-v26.xml:13:5-16:13: AAPT: error: resource android:attr/colorError not found.
C:\Users\USERNAME\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\b3b5480809d523e6f8b8de92faafbcda\res\values-v26\values-v26.xml:17:5-93: AAPT: error: style attribute 'android:attr/keyboardNavigationCluster' not found.
C:\Users\USERNAME\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\b3b5480809d523e6f8b8de92faafbcda\res\values\values.xml:251:5-69: AAPT: error: resource android:attr/fontStyle not found.
C:\Users\USERNAME\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\b3b5480809d523e6f8b8de92faafbcda\res\values\values.xml:251:5-69: AAPT: error: resource android:attr/font not found.
C:\Users\USERNAME\.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\b3b5480809d523e6f8b8de92faafbcda\res\values\values.xml:251:5-69: AAPT: error: resource android:attr/fontWeight not found.
error: failed linking references.
:react-native-document-picker:verifyReleaseResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-document-picker:verifyReleaseResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt
I can't really make sense of these errors, any idea what they mean? How can I find out how to fix this?
I've tried various things, including deleting the .cache directory, changing the gradle version but nothing seems to help. Any idea?
You need to add following code in your project's android/build.gradle:
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
}
}
}
}
For me, what fixed the issue was prefixing with app
./gradlew app:assembleRelease
Reason for the error:
You have installed react-native-document-picker as a dependency, And the reason for this error is that the configurations of your android/app/build.gradle and node_modules/react-native-document-picker/android/build.gradle mismatch.
Solution
Navigate to node_modules/react-native-document-picker/android/build.gradle
Edit and keep the compileSdkVersion buildToolsVersion minSdkVersion
targetSdkVersion same as you have in android/app/build.gradle
Sync the project again.
Run ./gradlew assembleRelease from the terminal.
Had another reason for this issue, I had previously modified minSdkVersion.
All you need to do is to remove /node_modules/ folder, /android/build and /android/app/build folders, re npm install and perform ./gradlew assembleRelease again.
The command cd android && ./gradlew app:assembleRelease do the magic.
I've found a github link where a command help in almost every type of verifyReleaseResource errors. Ref: https://github.com/luggit/react-native-config/issues/330#issuecomment-494915023
Reason for the error:
In my case, I had installed react-native-thermal-receipt-printer as a dependency, And the reason for this error is that the configurations of your android/build.gradle and node_modules/react-native-thermal-receipt-printer/android/build.gradle mismatch.
Solution
Navigate to node_modules/react-native-thermal-receipt-printer/android/build.gradle
Edit and keep the compileSdkVersion buildToolsVersion minSdkVersion targetSdkVersion same as you have in android/build.gradle
Save it and change dir cd android.
Run ./gradlew clean
Run ./gradlew assembleRelease