Generating the release APK - react-native

while Generating the release APK it gives error:
Task :app:bundleReleaseJsAndAssets
Scanning folders for symlinks in C:\root\React_Native\rncourse\node_modules (83ms)
Scanning folders for symlinks in C:\root\React_Native\rncourse\node_modules (108ms)
Loading dependency graph, done.
warning: the transform cache was reset.
bundle: Writing bundle output to: C:\root\React_Native\rncourse\android\app\build\intermediates\assets\release\index.android.bundle
bundle: Done writing bundle output
bundle: Copying 4 asset files
bundle: Done copying assets
C:\root\React_Native\rncourse\android\app\build\intermediates\res\merged\release\drawable-mdpi\src_assets_logopng.png: error: uncompiled PNG file passed as argument. Must be compiled first into .flat file..
error: failed parsing overlays.
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:processReleaseResources'.
Failed to process resources, see aapt output above 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

For a workaround solution you can add this line to your android/gradle.properties file:
android.enableAapt2=false
but as I said, it's a workaround and is deprecated.
I didn't find a complete solution for this but if I do find a better solution, I'll edit my answer!

Two things you can do to avoid this error
1. You can try with delete build folder and make a new release build
2. try deleting android\app\build\intermediates\res\merged\release\drawable-mdpi in your project
may be these points avoids your problem

Related

How to execute Gradle tests using Kotlin when getting the 'Please add kotlin-script-runtime.jar to the module dependencies' error?

These are the logs of the error:
./gradlew :clean :cleanTest :test -Ddebug=true -PenvironmentName=PROD --tests="*dummytest"
> Task :compileKotlin FAILED
e: /home/gpligoropoulos/xm/research_portal/rp_api_automation/src/main/kotlin/Person.kts: (1, 1): No script runtime was found in the classpath: class 'kotlin.script.templates.standard.ScriptTemplateWithArgs' not found. Please add kotlin-script-runtime.jar to the module dependencies.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileKotlin'.
> Compilation error. See log for more 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
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 2s
3 actionable tasks: 2 executed, 1 up-to-date
The solution is to simply add a single line in dependencies the kotlin script runtime
Similar to here:
dependencies {
...
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-script-runtime
compile group: 'org.jetbrains.kotlin', name: 'kotlin-script-runtime', version: '1.4.10'
...
}

I got below error while generating release build in react native android .file already exist

D:\ReactNative Workspace\awesome\android>gradlew clean
BUILD SUCCESSFUL in 4s
2 actionable tasks: 2 executed
D:\ReactNative Workspace\awesome\android>gradlew assembleRelease
> Task :app:bundleReleaseJsAndAssets
warning: the transform cache was reset.
Loading dependency graph, done.
info Writing bundle output to:, D:\ReactNative
info Writing sourcemap output to:, D:\ReactNative
info Done writing bundle output
info Done writing sourcemap output
info Copying 1 asset files
error EEXIST: file already exists, mkdir 'D:\ReactNative'. Run CLI with --verbos
e flag for more details.
Error: EEXIST: file already exists, mkdir 'D:\ReactNative'
> Task :app:bundleReleaseJsAndAssets FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> Process 'command 'npx.cmd'' finished with non-zero exit value 1
* 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 1m 14s
7 actionable tasks: 7 executed
D:\ReactNative Workspace\awesome\android>
I was facing the same issue, It's actually not an error you just need to check the path of your "Key Store Path" If there is any space between your path the build fails, Try changing the path which is free from spaces, then build the project you should not see any errors now.

Error: The resource `Path-to-project-root-directory\index.ts` was not found

I am working on a react-native project and wanted to generate the signed apk for deployment on Play store. I am following the
official documentation for this:
https://facebook.github.io/react-native/docs/signed-apk-android
Building unsigned apk, works just fine.
But for signed apk, after generating "my-upload-key.keystore" and placing it in /android/app directory (inlcluding other settings as guided in docs.), whenever I run command
"gradlew bundleRelease", it gives the following error:
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
Task :app:bundleReleaseJsAndAssets
warning: the transform cache was reset.
error The resource Path-to-project-root-directory\index.ts was not found.. Run CLI with --verbose flag for more details.
Task :app:bundleReleaseJsAndAssets FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
Process 'command 'cmd'' finished with non-zero exit value 1
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 1m 39s
4 actionable tasks: 1 executed, 3 up-to-date

RNC Slider lint FAILED on ./gradlew clean build and release apk crashes on app start

Before assembling release, I'm trying to make clean build but it throws error and fails the task. When I generate release apk (succesfully generates), after installing it on my LG G4 phone (also tried Samsung Galaxy J3), it is crashing and not starting.
My app succesfully works with react-native run-android on my phone.
Before assembling release build, I typed
cd android
./gradlew clean
./gradlew buildcache
./gradlew clean build
and the last command always gives errors.
After adding
android {
lintOptions {
abortOnError false
}
}
to RNC Slider's build.gradle file as the errors say, ./gradlew clean build succesfully finishes its task. But still I can't open the app after generating and installing release apk.
./gradlew clean build error:
...
> Task :#react-native-community_slider:lint FAILED
Ran lint on variant release: 3 issues found
Ran lint on variant debug: 3 issues found
Wrote HTML report to file:///D:/React/Pure%20RN/dassist/node_modules/#react-native-community/slider/android/build/reports/lint-results.html
Wrote XML report to file:///D:/React/Pure%20RN/dassist/node_modules/#react-native-community/slider/android/build/reports/lint-results.xml
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':#react-native-community_slider:lint'.
> Lint found errors in the project; aborting build.
Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
lintOptions {
abortOnError false
}
}
...
Errors found:
D:\React\Pure RN\dassist\node_modules\#react-native-community\slider\android\src\main\java\com\reactnativecommunity\slider\ReactSliderManager.java:68: Error: Value must be ? 0 (was -2) [Range]
ViewGroup.LayoutParams.WRAP_CONTENT,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 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
BU¦LD FAILED in 35s
163 actionable tasks: 154 executed, 9 up-to-date
And this is a part of the xml report file (warnings excluded) mentioned in output logs:
<issues format="5" by="lint 3.3.1">
<issue
id="Range"
severity="Error"
message="Value must be ≥ 0 (was -2)"
category="Correctness"
priority="6"
summary="Outside Range"
explanation="Some parameters are required to in a particular numerical range; this check makes sure that arguments passed fall within the range. For arrays, Strings and collections this refers to the size or length."
errorLine1=" ViewGroup.LayoutParams.WRAP_CONTENT,"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="D:\React\Pure RN\dassist\node_modules\#react-native-community\slider\android\src\main\java\com\reactnativecommunity\slider\ReactSliderManager.java"
line="68"
column="13"/>
</issue>
</issues>

react native apk build fail when using react-native-razorpay

I'm trying to build an signed apk for my react-native code. I've used react-native-razorpay library for payment integration purpose.
On running cd android && ./gradlew assembleRelease in my project root directory I got stuck on following error.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-razorpay:verifyReleaseResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt
* 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 22s
102 actionable tasks: 2 executed, 100 up-to-date
While running ./gradlew assembleRelease --info i get following in the last few lines-
....
....
Successfully started process 'command '/Users/clove/Library/Android/sdk/build-tools/27.0.3/aapt''
/Users/clove/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.1.0.aar/37abea56216e7a3ad9a6c076b6dd1a92/res/values-v24/values-v24.xml:3:5-157: AAPT: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.
/Users/clove/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.1.0.aar/37abea56216e7a3ad9a6c076b6dd1a92/res/values-v24/values-v24.xml:4:5-135: AAPT: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.
/Users/clove/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.1.0.aar/37abea56216e7a3ad9a6c076b6dd1a92/res/values-v26/values-v26.xml:13:5-16:13: AAPT: No resource found that matches the given name: attr 'android:keyboardNavigationCluster'.
> Task :react-native-razorpay:verifyReleaseResources FAILED
Putting task artifact state for task ':react-native-razorpay:verifyReleaseResources' into context took 0.0 secs.
Up-to-date check for task ':react-native-razorpay:verifyReleaseResources' took 0.0 secs. It is not up-to-date because:
Task has failed previously.
All input files are considered out-of-date for incremental task ':react-native-razorpay:verifyReleaseResources'.
Unable do incremental execution: full task run
QueuedCruncher is using /Users/clove/Library/Android/sdk/build-tools/27.0.3/aapt
Shutdown finished in 0ms
:react-native-razorpay:verifyReleaseResources (Thread[Daemon worker Thread 18,5,main]) completed. Took 0.402 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-razorpay:verifyReleaseResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt
* Try:
Run with --stacktrace option to get the stack trace. Run with --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 1m 16s
102 actionable tasks: 9 executed, 93 up-to-date
Found a solution. Turned out that the problem was due to configuration mismatch. the gradle version I was using was above 3, which requires the android sdk version 25 or above. Whereas react-native-razorpay was shipped with sdk version 23. So I changed those settings in node_modules and the build completed successfully.