Generate apk using gradle & Nodejs - javascript

I am trying to generate apk files using Nodejs along with Gradle with the NodeJs sync process and the following code:
const exec = require('child_process').execSync;
exec(`cd ~/appFolder && ./gradlew assembleRelease`);
Now please note that when I execute:
cd ~/appFolder && ./gradlew assembleRelease
from the command line, it works perfectly and I get build successful. But when I run the javascript above, I get the following error:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> SDK location not found. Define location with sdk.dir in
the local.properties file or with an ANDROID_HOME environment variable.
Note that I did set ANDROID_HOME and the local.properties file exist in the app folder.
Thank you very much.

Related

React Native, unable to clean gradlew

I'm trying to clean my android gradlew file by cd android and ./gradlew clean but it's showing that error, can anyone tell me how to clean it without getting that error?? please help
Task :react-native-localization:clean FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-localization:clean'.
> java.io.IOException: Unable to delete file 'C:\Users\DAWOR\Go-polo-master\node_modules\react-native-localization\android\build'
cd android
gradlew clean
no need for ./ if your in the android directory unless your using linux as for the error this just means it could not delete the specified folder could be due to permissions or a file in the folder still being in use by something
i would suggest deleting the folder your self then rerunning the command this can happen if you still have metro or the emulator open if a file is still in use by something

React Native, Failed to launch emulator. Reason: No emulators found as an output

I'm trying to run my react native app in emulator by using command react-native run-android but it's throwing that error
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.3/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 44s
info Connecting to the development server...
warn Failed to connect to development server using "adb reverse": spawnSync /Opt/Android/platform-tools/adb ENOENT
info Starting the app...
The system cannot find the path specified.
error Failed to start the app. Run CLI with --verbose flag for more details.
Error: Command failed: /Opt/Android/platform-tools/adb shell am start -n com.reactproject/com.reactproject.MainActivity
at makeError (C:\Users\Danger World\ReactProject\node_modules\execa\index.js:174:9)
I already setup my android studio and sdk manager, avd manager like it's shown in doc also I already set path but it's still showing that error, anyone know why? Can anyone help please?
You can fix it by using the command :
react-native doctor
This command shows all issues that need to be fixed.
Press f to fix the issues and don't forget to restart your windows
And after then open the emulator before running your project.
Once emulator opened,
run command:
react-native run-android
After fixed:
Don't forget to give me an upvote if that's work.
In My Case, I have to re-run the command in the same terminal where you are trying to run npx react-native run-android
Step 1. paste the source command first
source ~/.bash_profile OR source ~/.bashrc
Step 2. RUN Next command
npx react-native run-android
set your AVD manager path and JDK path like this , also you have to add Android Home path

React native can't run in ios by command but it can run in Xcode?

I used two libraries: "native-base" and "react-native-elements" but when I used it, I could not use the command react-native run-ios. But when I open the Xcode project, it can run and work as well.
This is my error below when I try to use the command react-native run-ios:
error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by opening DesignComponents.xcodeproj
One more error:
The following build commands failed:
Analyze /Users/my_path_project/node_modules/react-native/React/Base/RCTAssert.m normal x86_64
(1 failure)
I try to resolve it by clean cache, clean folder node_modules and something that I can, but it's not working.

error path sdk react native linux

I have installed some needed like: nodejs, python2, android studio, but when running react, error, possibly wrong path, but I check for the path I think is correct, please help
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug...
Failed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes precedence.
java.lang.RuntimeException: SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
at com.android.build.gradle.internal.SdkHandler.getAndCheckSdkFolder(SdkHandler.java:102)
FAILURE: Build failed with an exception.
* Where:
Build file '/home/rojib/Documents/react/lat3/React-Native-Sample/android/app/build.gradle' line: 104
* What went wrong:
A problem occurred evaluating project ':app'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
* 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: 27.013 secs
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/android-setup.html
SDK location on android studio : /home/rojib/Android/Sdk, Is there something wrong ?
Try this
enter this line to your package.json file in scripts
"android": "ANDROID_HOME='Your android SDK Location' node node_modules/react-native/local-cli/cli.js run-android",
and after enter this line open terminal and run this
npm run android
hope it'll work for you...

JS server already running react native app

I'm following the Getting Started tutorial from here: https://facebook.github.io/react-native/docs/getting-started.html. I'm able to boot up my package manager with react-native start. But running the application itself always results in a crash.
$ react-native run-android
JS server already running.
Building and installing the app on the device (cd android && gradlew.bat installDebug...
Error occurred during initialization of VM
Unable to use shared archive.
An error has occurred while processing the shared archive file.
Unable to unmap shared space.
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/android-setup.html
What is the problem?
You already have a react native process running in the background on the same port.
Use ps -ef | grep react
and then kill the process using the process id
kill -9 pid
and then re execute the command:
react-native run-android
First of all give proper permission to your gradlew, in your root directory run following command
chmod 755 android/gradlew
After this make sure you have local.properties file in your android folder with sdk file path like
sdk.dir = /home/username/Android/Sdk/

Categories