I cloned a react-native project from github and below are the steps that I followed in order to make it work on my local ubuntu 20.04 machine:
(The project was expo managed earlier, but now it is ejected because there are android and ios folders)
created my local feature branch -> git checkout -b feature
installed all the packages in package.json -> yarn install
ran npx react-native run-android to run the app on android emulator
1st Encountered error:-
Could not write standard input to Gradle build daemon.
java.io.IOException: Stream closed
* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please read the following process output to find out more:
-----------------------
Unrecognized VM option 'MaxPermSize=512m'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
In order to solve this issue, I used this https://stackoverflow.com/a/69630720/11685381 answer and removed -XX:MaxPermSize=512m from my gradle.properties
2nd Encountered error:-
Again used npx react-native run-android and ran into another build error:-
* What went wrong:
Could not open settings generic class cache for settings file '/home/user/project/android/settings.gradle' (/home/user/.gradle/caches/6.9/scripts/5bii70nilhgbvb8zyo7v963b7).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61
To fix this, I used this solution: https://www.codegrepper.com/code-examples/whatever/BUG!+exception+in+phase+'semantic+analysis'+in+source+unit+'_BuildScript_'+Unsupported+class+file+major+version+61
3rd Encountered error:-
Again ran npx react-native run-android and ran into these 2 build error this time:
1: Task failed with an exception.
-----------
* Where:
Build file '/home/user/project/node_modules/expo-gl-cpp/android/build.gradle' line: 307
* What went wrong:
Default side-by-side NDK installation is not found.
Set $ANDROID_NDK_HOME environment variable correctly or setup ndk.dir in local.properties.
> NDK is not installed
2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':expo'.
> compileSdkVersion is not specified. Please add it to build.gradle
To solve the 1st issue i.e. NDK is not installed (it is installed though), I created a local.properties inside project/android directory and pasted the following path:
sdk.dir=/home/user/Android/Sdk
ndk.dir=/home/user/Android/Sdk/ndk/24.0.8215888
4th Encountered error:-
> Task :app:generatePackageList FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
* Where:
Script '/home/user/project/node_modules/#react-native-community/cli-platform-android/native_modules.gradle' line: 131
* What went wrong:
Execution failed for task ':app:generatePackageList'.
> argument type mismatch
To solve this, I tried this solution: https://stackoverflow.com/a/68180959/11685381 but this again downloaded the gradle 6.9 which I had earlier also, and again to the 2nd Encountered error
I've been doing this since 2 days, can someone please help me out here what am I doing wrong?
Try updating build.grade from
classpath("com.android.tools.build:gradle:3.5.3")
To
classpath("com.android.tools.build:gradle:3.5.4")
It's just an example. try to update Gradle.
I'm trying to build JPostal as described in this link using the following command:
./gradlew assemble
However, the command produces the following output claiming the file C:\x\Program Files\Msys64\usr\share does not exist when it clearly does:
$ ./gradlew assemble
:buildJniLibaclocal-1.16: error: aclocal: file '/x/Program Files/Msys64/usr/share/aclocal/tcl-tea.m4' does not exist
autoreconf-2.71: error: aclocal failed with exit status: 1
configure: WARNING: you should use --build, --host, --target
configure: WARNING: invalid host type: Files/JPostal/src/main/jniLibs
configure: error: cannot find required auxiliary files: compile config.guess config.sub ltmain.sh missing install-sh
make: *** No rule to make target 'install'. Stop.
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':buildJniLib'.
> Process 'command 'sh'' finished with non-zero exit value 2
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 5.844 secs
I can clearly see a file named tcl-tea.m4 in the directory: C:\x\Program Files\Msys64\usr\share\aclocal
See the screenshot below:
If the file clearly exists, why am I getting this error? Why is the file being discriminated against?
Despite these are supported, but paths with spaces generally tend to be problematic on Linux.
Even without the build.gradle, the path is obviously wrong; this likely needs to be escaped:
"C:\\x\\Program\ Files\\Msys64\\usr\\share\\aclocal"
Where \\ gives \ and \ gives .
To use ${File.separator} would be the alternate cross-platform approach.
This would give \ on Windows and / on Linux.
I run npx react-native run-android and I get this
This seems to be the problem, It's looking for platform tools in ~/ and not in ~/Android/Sdk
java.io.IOException: Cannot run program "/home/u/platform-tools/adb": error=2, No such file or directory
`
You can ignore this, stack won't let me post this if I don't add more text, but I think it's already a good explanation
> Task :app:compileDebugJavaWithJavac
> Task :app:stripDebugDebugSymbols
Unable to strip the following libraries, packaging them as they are: libbetter.so, libc++_shared.so, libevent-2.1.so, libevent_core-2.1.so, libevent_extra-2.1.so, libfabricjni.so, libfb.so, libfbjni.so, libflipper.so, libfolly_futures.so, libfolly_json.so, libglog.so, libglog_init.so, libimagepipeline.so, libjsc.so, libjscexecutor.so, libjsi.so, libjsijniprofiler.so, libjsinspector.so, liblogger.so, libmapbufferjni.so, libnative-filters.so, libnative-imagetranscoder.so, libreact_codegen_rncore.so, libreact_debug.so, libreact_nativemodule_core.so, libreact_render_animations.so, libreact_render_attributedstring.so, libreact_render_componentregistry.so, libreact_render_core.so, libreact_render_debug.so, libreact_render_graphics.so, libreact_render_imagemanager.so, libreact_render_leakchecker.so, libreact_render_mapbuffer.so, libreact_render_mounting.so, libreact_render_runtimescheduler.so, libreact_render_scheduler.so, libreact_render_telemetry.so, libreact_render_templateprocessor.so, libreact_render_textlayoutmanager.so, libreact_render_uimanager.so, libreact_utils.so, libreactconfig.so, libreactnativeblob.so, libreactnativejni.so, libreactnativeutilsjni.so, libreactperfloggerjni.so, librrc_image.so, librrc_modal.so, librrc_progressbar.so, librrc_root.so, librrc_scrollview.so, librrc_slider.so, librrc_switch.so, librrc_text.so, librrc_textinput.so, librrc_unimplementedview.so, librrc_view.so, libturbomodulejsijni.so, libyoga.so.
> Task :app:installDebug FAILED
31 actionable tasks: 31 executed
Note: /home/u/Desktop/workdir/Math_App/mathapp/android/app/src/debug/java/com/mathapp/ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
[adb]: Cannot run program "/home/u/platform-tools/adb": error=2, No such file or directory
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:installDebug'.
> java.io.IOException: Cannot run program "/home/u/platform-tools/adb": error=2, No such file or directory
* 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 13m 4s
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
Note: /home/u/Desktop/workdir/Math_App/mathapp/android/app/src/debug/java/com/mathapp/ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
[adb]: Cannot run program "/home/u/platform-tools/adb": error=2, No such file or directory
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:installDebug'.
> java.io.IOException: Cannot run program "/home/u/platform-tools/adb": error=2, No such file or directory
* 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 13m 4s
at makeError (/home/u/Desktop/workdir/Math_App/mathapp/node_modules/#react-native-community/cli-platform-android/node_modules/execa/index.js:174:9)
at /home/u/Desktop/workdir/Math_App/mathapp/node_modules/#react-native-community/cli-platform-android/node_modules/execa/index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (/home/u/Desktop/workdir/Math_App/mathapp/node_modules/#react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
at async Command.handleAction (/home/u/Desktop/workdir/Math_App/mathapp/node_modules/#react-native-community/cli/build/index.js:192:9)
Check where your $ANDROID_HOME variable is pointing to.
echo $ANDROID_HOME
If must be equal to the path of Android/Sdk, usually at ~/Android/Sdk
A solution, if you know where the variable ANDROID_HOME is (maybe ~/.bashrc, ~/.profile):
Go to the file you've the var ANDROID_HOME and edit it so it looks like this
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
After you changed them, do source .bashrc or source {whatever file they're on} and it should work (it works on the terminal you did it, it, do it in whatever terminal you want it to work, if it's on .bashrc it'll work next time you restart without doing source)
That's how it's done if Android is installed in ~/ (you can check out by doing cd, and then ls, Android should appear, if it didn't, change $HOME for the direction of where you installed it).
If you don't have those variables at all: just open ~/.bashrc and add them to the file. And do the same as it's explained before.
And yeah, that's it. I'd appreciate if someone translated this to the Windows and Mac way.
App works in debug mode just fine by running react-native run-android
But, when I try to build in relase mode by running cd android && ./gradlew assembleRelease
it gives me this error:
android\app\build\intermediates\res\merged\release\drawable-hdpi\node_modules_reactnavigation_src_views_assets_backicon.png: error: uncompiled PNG file passed as argument. Must be compiled first into .flat file..
error: failed parsing overlays.
Failed to execute aapt
com.android.ide.common.process.ProcessException: Failed to execute aapt
I tried workarounds like putting android.enableAapt2=false and org.gradle.configureondemand=true in android/gradle.properties
They both helped me create signed apk but app was crashing on start,
I tried to debug that crash by adb logcat and error is:
FATAL EXCEPTION: Thread-139
java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server.
Please help me out, I cant seem to figure out how to solve this.
if anyone wonders, we ended up downgrading gradle to
classpath 'com.android.tools.build:gradle:2.2.3'
and it worked.
I have been trying to do CI using Jenkins for my Android application. I am new to this. After following some of the tutorials, I am able to atleast set up and run the build now option. It download every pom required but while building it give below error.
============================================
C:\Windows\System32\config\systemprofile.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\e796469c387c11565d873216f24c3b6f\res\drawable\abc_ic_go_search_api_material.xml: error: file not found.
C:\Windows\System32\config\systemprofile.gradle\caches\transforms-1\files-1.1\play-services-base-15.0.1.aar\7207fbd3bdb6cb696445cfc77c16e5ed\res\drawable-hdpi-v4\googleg_standard_color_18.png: error: file not found.
C:\Windows\System32\config\systemprofile.gradle\caches\transforms-1\files-1.1\appcompat-v7-27.1.1.aar\e796469c387c11565d873216f24c3b6f\res\layout\select_dialog_singlechoice_material.xml: error: file not found.
Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details
:app:mergeDebugResources FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:mergeDebugResources'.
Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs 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.
======================================================
Can you please let me know how to resolve it?
Do let me know if anything else is required.
Maybe the path is too long. Try this:
Jenkins --> Project --> Project Configuration --> Build
Select advanced option
Check the option box "Force GRADLE_USER_HOME to use workspace"
Build your project
I solved my problem by this way, good luck!
Try updating your android gradle plugin version to 3.2.0-alpha12 or newer. AAPT2's version included in these versions contains many fixes for path support on Windows which resulted in similar errors.
you can solve this by separating into smaller group of task
make separate invoke gradle script under build tab
clean build assembleDebug
test
connectedAndroidTest
i had similar issues, when i ran assembleDebug and test together in Jenkins as a single task
When using Jenkins with Window to build Android, I face this problem myself.
I fix by add GRADLE_USER_HOME to Environment Variable:
GRADLE_USER_HOME = C:\Users\*MyUserName*\.gradle
hope this help,