Problem while installing a React Native App on physical phone - android

When I run "yarn android", to install the app on the phone I get this error:
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
Unable to install /home/dapedo/Projects/CJR/test/AwesomeProject/android/app/build/outputs/apk/debug/app-debug.apk
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I already checked the system PATH and all seems to be correct:
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
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
export PATH=$PATH:~/android-studio/bin
I tried to run it on Android Studio, and it install the app, but I get some error, probably because there's no connection. When I run "yarn android" with the app open, I get a blank page instead of the errors, but the same error appears on the terminal.

Run the following command
chmod 755 android/gradlew
inside your app root folder
then run
react-native run-android

I went to the Android SDK cofigs, and disabled all the unused things, than initialized a new React Native project, that solved my problem.

Related

Trying to build react native app for Android on Mac M1 - Error: No emulators found as an output of `emulator -list-avds`

I have installed Android Studio on my mac M1
I have added a virtual device in Android Studio using Device Manager
The app builds fine from inside Android Studio......however when I run npx react-native run-android from command line in VSCode, I get the error No emulators found as an output of emulator -list-avds
However when I navigate to emulator folder using cd ~/Library/Android/sdk/emulator and run command ./emulator -avd {AVD_NAME}, the emulator starts fine.....however even with the emulator running, the command npx react-native run-android still gives the error No emulators found as an output of emulator -list-avds
UPDATE 04/26 - I followed instructions from #qqNade, however I am still getting same error...see screenshot below:
Just noticed from the screenshot above, the error
/bin/sh: adb: command not found
..also, when I run echo $PATH in terminal, I get the following response:
/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
I dont see any reference to android in there, so I assume thats not a good thing
UPDATE 04/26 #2
I added a ~/.zshrc file and populated it as per below:
export ANDROID_HOME="$HOME/Library/Android/sdk"
export
PATH="$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$PATH"
..that solved the /bin/sh: adb: command not found error, but now I have a new one:
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: spawn ./gradlew EACCES
at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
at onErrorNT (node:internal/child_process:476:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
....at least its launching the emulator now
UPDATE 04/26 #3
A number of SO posts told me to run the following command from android folder (and then clean)
chmod +x gradlew;
...now Im getting a different error:
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
./gradlew: line 188: syntax error: unexpected end of file
Im wondering if this has anything to do with fact that I created the app originally on Windows.....and this is the first time Im trying to build on Mac?
I checked gradlew file in VSCode and its showing as LF (not CRLF) which as I understand it is correct when building for Mac
I also faced such a problem, to solve it you need to open a command prompt and enter
nano ~/.zsh_profile
after which you need to add this to the file and save
export ANDROID_HOME=$HOME/Library/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
then enter on the command line
source $HOME/.zsh_profile
I want to help you.
You're in the home directory (you can go there with cd $HOME or cd ~)
export ANDROID_HOME=$HOME/Library/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
source ~/.bash_profile (or source ~/.zshrc, take a look at my note at the end please)
After that, when you execute command vi .bash_profile (or vi .zshrc), you should see something like that
At this point, you can try to execute emulator -list-avds command again
And yes, echo $PATH should show you entries related with Android like ~/Library/Android/sdk/platform-tools
echo $ANDROID_HOME as well
If still not working, I would try to navigate to android folder and run the commands below one more time
chmod +x gradlew
./gradlew clean
react-native run-android
NOTE: Please be sure which shell your mac is using with the command below.
echo $0
Further reading
setting up development environment
I have used homebrew for setting up
echo $PATH
/bin:/usr/bin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/userName/Library/Android/sdk/emulator:/Users/userName/Library/Android/sdk/platform-tools
when we get this error,
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: spawn ./gradlew EACCES
at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
at onErrorNT (node:internal/child_process:476:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
try running this command and it will update the gradlew file with access permission, this is for M1 chip machine only
cd android
chmod +x gradlew
This solved my issue

Can't access my android emulator in react native "/bin/sh: adb: command not found"

I use mac and setting up the development environment by React Native CLI Quickstart. https://reactnative.dev/docs/environment-setup
It works for me in ios but in android i'm getting an error.
My steps:
1.open ~/.zshrc
2.add to the file
> export ANDROID_HOME=$HOME/Library/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
save and run source ~/.zshrc
4.open emulator, run yarn android and getting the error:
/bin/sh: adb: command not found.
error Failed to launch emulator. Reason: No emulators found as an
output of emulator -list-avds.
warn Failed to connect to development server using "adb reverse": spawnSync adb ENOENT
error Failed to start the app. Error: spawnSync adb ENOENT at Object.spawnSync (internal/child_process.js:1070:20)
** when i run "emulator -list-avds" i can see the emulator
Run the below three commands before running npm run android
export ANDROID_HOME=/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH

npx react-native run-android doesn't start emulator and doesn't run if emulator is running

I've created a new project using react-native 0.63
and when I run on ios simulator everything works fine
but when try to run it on android, it does not work and gives me this error
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:installDebug'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Volumes/SSD2/developer/MyProject/AwesomeProject/android/local.properties'.
* 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 2s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
i install react-native like
react-native Setting up
and this is the output from my react-native doctor
✓ Node.js
✓ npm
✓ Watchman - Used for watching changes in the filesystem when in development mode
Android
✓ JDK
✓ Android Studio - Required for building and installing your app on Android
✖ Android SDK - Required for building and installing your app on Android
- Versions found: N/A
- Version supported: 29.0.2
✖ ANDROID_HOME
iOS
✓ Xcode - Required for building and installing your app on iOS
✓ CocoaPods - Required for installing iOS dependencies
✓ ios-deploy - Required for installing your app on a physical device with the CLI
Errors: 2
Warnings: 0
and if I run npx react-native start then the application runs from android studio smoothly.
Edit
if i run project from terminal source .bash_profile
emulator start but project not run
"--no-jetifier" flag.
Jetifier found 5194 file(s) to forward-jetify. Using 12 workers...
info JS server already running.
info Installing the app...
env: sh\r: No such file or directory
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
env: sh\r: No such file or directory
Looks like you need to set the ANDROID_HOME environment variable.
Add the following lines to your $HOME/.bash_profile or $HOME/.bashrc (if you are using zsh then ~/.zprofile or ~/.zshrc) config file:
export ANDROID_HOME=$HOME/Library/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
Type source $HOME/.bash_profile for bash or source $HOME/.zprofile to load the config into your current shell. Verify that ANDROID_HOME has been set by running echo $ANDROID_HOME and the appropriate directories have been added to your path by running echo $PATH.
Please make sure you use the correct Android SDK path. You can find the actual location of the SDK in the Android Studio "Preferences" dialog, under Appearance & Behavior → System Settings → Android SDK.
References:
https://reactnative.dev/docs/environment-setup 3. Configure the ANDROID_HOME environment variable
Configure the ANDROID_HOME environment variable
The React Native tools require some environment variables to be set up in order to build apps with native code.
Go to Home directory and show hidden files then add the following lines to your ~/.zprofile or ~/.zshrc (if you are using bash terminal, then ~/.bash_profile or ~/.bashrc) config file:
export ANDROID_HOME=$HOME/Library/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
Run source ~/.zprofile or source ~/.zshrc (or source ~/.bash_profile or source ~/.bashrc for bash) in your root terminal to load the config into your current shell. Verify that ANDROID_HOME has been set by running echo $ANDROID_HOME and the appropriate directories have been added to your path by running echo $PATH.
Restart your system if still error persists.

Error setting up react-native on ubuntu 16.04

I just started learning react native. I am following this tutorial to set up my environment: https://www.raywenderlich.com/178012/react-native-tutorial-building-android-apps-javascript
Everything seems okay until the point where I have to run 'react-native run-android'. I get the error below:
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
FAILURE: Build failed with an exception.
What went wrong:
Could not determine java version from '9.0.4'.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
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
I have both JAVA 8 and 9 installed but I am pointing to Java 8. This is what $JAVA_HOME returns when I echo:
"/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java"
Note, I have an emulator running too.
Have you tried to do what s on this link below as-well:
https://facebook.github.io/react-native/docs/getting-started.html
This page will help you install and build your first React Native app.
The commands:
$npm install -g create-react-native-app
$create-react-native-app AwesomeProject
$cd AwesomeProject
$npm start
(I also tried a Youtube video regarding how to start and run a project on Ubuntu : https://www.youtube.com/watch?v=OZ5nCNOzflM )
I did it myself and for me it worked, at least for what I showed above.
This part is about building projects with React Native:
https://facebook.github.io/react-native/docs/getting-started.html
Commands :
$npm install -g react-native-cli
Install JS needed:
Add the following lines to your $HOME/.bash_profile config file:
export JAVASCRIPT_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
Create project:
$react-native init AwesomeProject
Run:
$cd AwesomeProject
$react-native run-android
Let me know if I was of any help or not.
I am also trying to integrate Boilerplate for Android using React Native on a Linux Platform (Ubuntu) and I still didn t find a solution to do that, except what I described above.
Good Luck :)

Phonegap android build error on macosx

I'm trying to build an apk from my phonegap project. When I run phonegap build android I get Error: EPERM, operation not permitted error so I tried sudo phonegap build android but I get this error:
[Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.]
When I run sudo android I get the android manager so I have correctly exported android path. What is the problem then?
This is part of my .profile file:
export ANDROID_HOME=/Users/Iman/Documents/SDKs/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
For OSX:
export ANDROID_HOME=/<installation location>/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Reference the Installation guide here: http://spring.io/guides/gs/android/

Categories

Resources