Run react-native on android emulator - android-emulator

I try to run react-native app on genymotion android emulator on my mac.
When I write react-native run-android It gets
Running /usr/local/opt/android-sdk/platform-tools/adb reverse tcp:8081 tcp:8081
error: closed
Could not run adb reverse: Command failed: /usr/local/opt/android-sdk/platform-tools/adb reverse tcp:8081 tcp:8081
Building and installing the app on the device (cd android && ./gradlew installDebug...
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
MacBook-Pro-MacBook:ART-CarefulPeople macbook$
Then I've tried:
react-native start
react-native run-android
The same result.
Then I've tried:
react-native bundle --entry-file index.android.js --platform android --bundle-output android/app/src/main/assets/index.android.bundle
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
react-native run-android
The same result.
I've tried just adb reverse tcp:8081 tcp:8081 and it says error: closed
When I try to run app on android-sdk emulator it gets the same error above but without error: closed.
From android studio I can run this app and it works on genymotion.
Tell me please what should I do to run my app on android emulator?

I had a similar problem, and after spending so much time and lots of searching about this issue the only trick worked for me:
Please Install the Required SDKs as shown in this figure
Configure Required SDKs
If You have already installed it, so you must have to update the following SDKs:
Android SDK Tool (update it to latest version)
Android SDK Platform-tools (update it to latest version)
Android SDK Build-tools (update it to latest version)
Android Support Repository under Extra folder (update it to latest version)
You Must have at least Installed the Same version Android API as the installed Android SDK Build-tools & Android SDK Platform-tools version as shown in the Configure Required SDKs figure above.
Note: Local Maven repository for Support Libraries which is listed as the SDK requirement in the official docs of React-native is now named as Android Support Repository in the SDK Manager .

On macOs I manage to fix this by adding:
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
to ~/.zsh_profile file.
and than type to your terminal
source $HOME/.zsh_profile
The issue was caused by using iTerm2 shell so it's required to edit its own config instead of default $HOME/.bash_profile as described in the official documentation https://reactnative.dev/docs/environment-setup

React Native (On Mac OS Big SUR)
i was stuck here. But updating the environment settings for Android studio did the trick.
nano ~/.zshrc
and paste
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator:$PATH
export PATH=$PATH:$ANDROID_HOME/tools:$PATH
export PATH=$PATH:$ANDROID_HOME/tools/bin:$PATH
export PATH=$PATH:$ANDROID_HOME/platform-tools:$PATH
export JAVA_HOME=$(/usr/libexec/java_home)
control + o to save
then enter
then control + x to exit
then do
source ~/.zshrc to compile
kill the runnig terminals and run
npx react-native run-android

You can also try use "doctor" command. It will fix most cases.
npx #react-native-community/cli doctor

I had similar issue running emulator from android studio everytime, or on a physical device. Instead, you can quickly run android emulator from command line,
android avd
Once the emulator is running, you can check with adb devices if the emulator shows up.
Then you can simply use
react-native run-android to run the app on the emulator.
Make sure you've platform tools installed to be able to use adb. Or you can use
brew install android-platform-tools

It happened to me that I had an instance of the packager running with an old project (I ran react-native start as usual). I was using Ubuntu 14.04. So what I did was to stop that instance and go to my project folder and in two different console tabs I ran these two commands separately:
npm start #here I used to run react-native start
react-native run-android
npm start is defined in my package.json as:
"start": "node_modules/react-native/packager/packager.sh"
I don't know if there is a sort of confusing stuff for react-native but that did the trick.

On Windows 10 and Android Studio you can go in Android Studio to "File"->"Settings" in Settings then to "Appearance & Behavior" -> "System Settings" -> "Android SDK".
In the Tab "SDK Tools" active:
"Android SDK Build-Tools .."
"Android Emulator"
"Android SDK Plattform-Tools"
"Android SDK Tools"
If all installed then you can start the Emulator in Android Studio with "Tools" -> "Android" -> "AVD Manager".
If the Emulator run you can try "react-native run-android"

If emulator not installed then try this command, (if homebrew installed)
brew install android-platform-tools
might be it will help.

Had a similar problem. I updated my Genymotion and my android SDK's/libraries/dependencies and all seemed to work. To update my SDK's I used android sdk manager {ANDROID_SDK_FOLDER}/tools/android sdk

In my case, there was an issue with the android/gradlew file. I think this happens when we move the code from Windows to Mac OS.
Reference:- https://stackoverflow.com/a/62216646/4786087
I was able to clean the android/gradlew file by running the following commands -
Step 1. On android folder cmd run
chmod +x gradlew
Step 2. After that run
./gradlew clean
Step 3. Next in the root of the project, run
react-native run-android
This should start building the app and launch it in the simulator if everything else is fine.

Try
brew cask install android-platform-tools
adb reverse tcp:9090 tcp:9090
run the app

In my case, this was happening because the android/gradlew file did not have execute permission. Once granted, this worked fine

You probably haven't run the Android SDK in forever.
So you probably just have to update it.
If you open the Android Studio Software it'll probably let you know that and ask to update it for you. Otherwise refer to following link: Update Android SDK

Related

Flutter doctor can't find Android SDK, but everything is set

I'm on Ubuntu 20.04 LTE
My Android SDK Location (shown in Android studio) is /home/myuser/Android/Sdk
The error goes as follows:
✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
`flutter config --android-sdk` to update to that location.
What I did to try to fix it:
Fresh installs of both Flutter (via snap) and Android studio (via apt, because when I install it also via snap, Flutter can't find even Android studio then).
Set configs:
flutter config --android-sdk="/home/myuser/Android/Sdk"
flutter config --android-studio-dir="/opt/android-studio-2021.1.1/android-studio"
Set paths in .bashrc:
export ANDROID_HOME=$HOME/Android/Sdk/
export PATH=$PATH:$ANDROID_HOME/tools/
export PATH=$PATH:$ANDROID_HOME/platform-tools/
In Android studio, I installed:
Dart and Flutter plugins.
SDK Platforms: 9.0(Pie), 10.0(Q), 11.0(R), 12.0(S), Android API 32
SDK Tools:
Android SDK Build-Tools 33-rc2
Android SDK Command-line Tools (latest)
Android Emulator 31.2.9
Android SDK PLatform-Tools 33.0.1
Trying to do flutter doctor --android-licenses doesn't do anything as it can't find Android SDK.
And I also can't run flutter doctor without adding sudo, because it stops after the first result and then runs for infinity.
Go to SDK tools and install all Support Repositories. Also check if there are any empty folders inside your SDK folder, if there are any empty folders, please delete them.Then follow the usual steps you mentioned,
Setting the config,
flutter config --android-sdk "/home/myuser/Android/Sdk"
Then finally run the flutter doctor again.
I use ubuntu too and the below is my environment.
Please try something like this in your vim ~./bashrc or vim ~/.zshrc
Change the paths as it is in your environment:
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH
export PATH=$PATH:~/development/flutter/bin
if it doesn't work try installing Flutter manually:
https://docs.flutter.dev/get-started/install/linux#install-flutter-manually
As the error message says, ANDROID_SDK_ROOT or previously known as ANDROID_HOME are not set in your environment variables.
To fix that, you will need to:
export ANDROID_SDK_ROOT=/path/to/android/studio/installation
export ANDROID_HOME=/path/to/android/studio/installation
export PATH=$PATH:/path/to/android/studio/installation
Due to some legacy reasons, there are a few variables pointing to the same thing. To make sure your Flutter SDK is getting it, you can set all of them.
Note: if you don't want to set them every time your laptop reboots, feel free to add them into ~/.bashrc.
Theoretically, during the installation of Android Studio, the variables above should be set for you, but, in reality, it doesn't always happen which is the reason you are seeing the error message.
Not sure but maybe the problem is caused by snap, since it was sandboxing the applications you install. I remember having a problem like this on something different. You can try installing flutter manually (downloading the zip and so on...) rather than using snap.

Issue when I use ionic cordova run android

I am getting an issue when I try to run with command line
ionic cordova run android
The error that it diplays is this one:
ERR_NO_TARGET: No targets devices/emulators available. Cannot create AVD because there is no suitable API installation. Use --sdk-info to reveal missing packages and other issues.
But the thing is that I created a device in the Android Studio:
so I wonder what could the problem be? Thanks
You need to launch the emulator and keep it running before executing the command ionic cordova run android
Click on the Play icon in the Virtual Devices list to launch the emulator.
Might not be the answer you're looking for but generally, I use:ionic cordova build android
Then open the platform/android directory in Android Studio.
Maybe you should try this :
for see avaliables devices this:
ionic cordova run android --list
for run android app on device this:
ionic cordova run android --device --verbose
i hope help you.
Make sure you have the following variables set in your environment.
export ANDROID_HOME=$HOME/Library/Android/sdk
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export ANDROID_AVD_HOME=$HOME/.android/avd

Flutter SDK Is Not Found In The Specified Location

I'm extremely frustrated right now after I updated Android Studio to have the latest Flutter and Dart Plugins. Now it tells me "No FLutter SDK configured" and when I give it the SKD path it just says, "Flutter SDK Is Not Found In The Specified Location." The Dart plugin works fine.
I have looked for an answer for hours and nothing works. I've downloaded the NDK, flutter doctor works perfectly, and I've tried set the SDK path to pretty much every file inside my flutter folder (inside /Documents).
Any tips?
Go to - Configure -> Tools > SDK Manager > Android SDK > SDK Tools, and search for flutter. You will get flutter SDK for Android.
If you are using Visual studio, also install plugins for flutter in Visual Studio.
» Steps:
Download Flutter SDK: Here
Extract Flutter:
tar xf ~/Downloads/flutter_linux_v1.7.8+hotfix.4-stable.tar.xz
Path export for particular terminal:
export PATH="$PATH:`pwd`/flutter/bin"
Permanent Path export:
Open bashrc file: Go to home directory terminal -> nano ~/.bashrc
Write at end of file:
export PATH=" [PATH_Where_Flutter SDK Extracted] /flutter/bin:$PATH"
example: export PATH="/home/sid/0_aaa_iauro/Flutter/s/flutter/bin:$PATH"
Run the following command to see if there are any dependencies you need to
install to complete setup:
flutter doctor -v
Add Flutter extension to vs-code.
Locate Flutter SDK.
Make New project in flutter:
flutter create Project_name
» Important Links:
Linux Install
Getting Started with Flutter on Linux for Android [Beginner Tutorial]
How To Install And Setup Flutter On Ubuntu 18.04.1 LTS (Bionic Beaver)
Part 2-A: Install Flutter in Windows – Step by Step Guide
Check for path variable (bashrc file):
Flutter – Step by Step Installation on Linux – Ubuntu
If you are using a fresh new Android Studio install as me, try installing missing packages for SDK support in Android Studio as described here: https://ladwhocodes.blogspot.com/2019/02/fix-flutter-sdk-not-found-in-specified-location.html
Go to Menu > Tools > SDK Manager > Android SDK (left side of the dialog) > SDK Tools (tab).
Select 'Support Repository' and 'NDK' checkboxes.
Click OK.
It will prompt you to install some dependencies. Install them.
What happen to me was because there is a space in my android sdk path (which is my username). I copy to C:\android\sdk and problem gone. Probably the space cause issue to NDK thus affect to Flutter sdk.
in my case, it was caused by local changes to the flutter git repo. On command line, everything worked, but in Android Studio it failed to detected the flutter sdk which caused all flutter commands to fail (even though flutter bin dir is in my path). The local changes were probably caused by trying out the beta version of flutter and returning to stable afterwards.
solution: delete flutter dir and redownload (I actually reverted all changes using the git clean command)

No valid Android SDK platforms

When I write flutter doctor command in cmd I get this error.
No valid Android SDK platforms found in G:\SdkManager\platforms. Candidates were:
- android-21
- android-27
- android-28
- android-8.0.0
flutter doctor
env
path
flutter sdk
platforms
plugins
It appears as though this message shows up when you don't have any build-tools packages installed. At the time of writing, to install the minimum required versions, you can fix this issue with:
sdkmanager "platform-tools" "platforms;android-30" "build-tools;30.0.3"
I've set up my Android SDK manually on Windows 10 with the command line and I was able to solve this kind of errors while I tried to set up my development environment, if you want to solve it as I did, just follow the next steps that I posted in a GitHub Comment in a related issue:
https://github.com/flutter/flutter/issues/19805#issuecomment-478306166
You should download and install Android build tools for the respective platform versions. This can be done via the Android SDK Manager.
In AndroidStudio go to menu Tool > Android > SDK Manager
On the tab "SDK Platforms" select one or more platforms and click the OK button.
Wait until the download completed and try again.
Try to download all sdk from file-> settings -> sdkmanager.
And do not download manually.
Find your sdk path and execute the code.
$ flutter config --android-sdk <path-to-your-android-sdk-path>
see here
I think your path is incorrect in environment variable.
You should change it to G:/Sdkmanager/platforms

ubuntu: can't run ionic app on emulator because android SDK doesn't exist

I'm using ionic2 and when I run app as ionic cordova run android. I got this
error: ERROR running one or more of the platforms: Android SDK not
found. Make sure that it is installed. If it is not at the default
location, set the ANDROID_HOME environment variable. You may not have
the required environment or OS to run this project
although I have android studio and SDK installed and set it in bashrc file as:
export ANDROID_HOME="/home/shimaa/Android/Sdk"
export PATH=${PATH}:/home/shimaa/Android/Sdk/platform-tools:/Development/android-sdk/tools
export PATH=${PATH}:/home/shimaa/android-studio/gradle/gradle-3.2/bin
but when I write android or sdkmanager in terminal I got this error:
No command 'android' found and sdkmanager: command not found
which means that android is not installed although it is installed and I run it.
anyone can tell me the solution ?