Nativescript project running with Visual Studio Emulator - android-emulator

I have a Nativescript application that I'm developing using VS Code and have no issues when I try to run it using the Nativescript launch configurations from the Nativescript extension, when I'm using a real device connected with USB or when I use one of the android-sdk emulators.
Now I need to run Hyper-V on the machine too and those emulators cannot run when hypervisor is on. So I downloaded and installed Visual Studio Android Emulator which runs fine when I launch it manually.
Problem is that the nativescript project doesn't recognize this device either with tns device or adb devices commands and if I try to launch the application from VS Code it tries to launch one of the other emulators, which obviously fails due to the hypervisor/Intel Haax incompatibility.
Did any of you had this problem before and have any solutions you can share?
Thanks.

Microsoft MSDN say :
If the emulator is running, but it does not appear to be connected to ADB or it does not appear in Android tools that make use of ADB (for example, Android Studio or Eclipse), you may need to adjust where the emulator looks for ADB.
The emulator uses a registry key to identify the base location of your Android SDK, and looks for the \platform-tools\adb.exe file under that directory.
Here We Go!! Step By Step ;)
Copy Your ANDROID SDK PATH for me it look like this :
To modify the Android SDK path used by the emulator:
Open Registry Editor by selecting Run from the Start buttons context menu, typing regedit in the dialog box, and choosing OK.
Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Android SDK Tools in the folder tree on the left.
Note : if Android SDK Tools folder doesn't exist, Create it under WOW6432Node, And open it, And Create a String Value name it Path:)
Modify the Path registry variable to match the path to your Android SDK.
Restart the emulator and you should now be able to see the emulator connected to ADB and associated Android tools.
Now! Open Your Terminal (CMD), and Run ADB command
adb devices -l
YES YES !! The Visual Studio Emulator is running, and connected to ADB!
HERE WE GOO !!
Now We Want To Create A Demo App (for example FIRSTZAKI) ZAKI is my nickname :p
On Terminal (CMD) :
tns create FIRSTZAKI
Choose Android Platform
cd FIRSTZAKI\
tns platform add android
Check if VS EMULATOR is ready!
tns devices
YES YES ^^
Finally Step (RUN/BUILD) :
tns run android
WOW ... Great :)
AND .. Good Luck ♥ — ZAKI

Related

setup nox (or genymotion )as android emulator for vscode flutter

for some reason, I don't want to install android studio(one of them is I don't have enough space for now) but instead, I want to work with vscode and nox(or genymotion). and my question is: Is it possible to connect vscode and an (android and ios) emulator to see the result? in other words, I want to connect the nox as an emulator to vscode and see the result inside of it.
Android studio take too much space and even my computer also become hot when open Android studio. But what I did I installed Android studio and Android emulator but I don't use Android studio rather I use VScode.
So as far as I know you need Android studio to install emulator then you can use VScode with it.
Finally, I found out how I can connect Genymotion to the VS Code(without Installing Android Studio).in total SDK manager wasn't installed on my laptop, so at first, I installed it. and then
Platform Tools (ADB & Fastboot)
Install Platform
Add System Image
Install Build Tools
but wait I just name the steps I've done. you can follow this article on this link to get more details.
and finally, instead of installing an emulator, I used Genymotion with Flutter in VS Code, which you can follow in this article to get more information. Click here

how to run flutter app in VSCode without android studio emulator

I want to run flutter app in VS.Code without android studio emulator.
I want run my app without install android studio.
How can I do this?
If you have Gradle properly installed globally (https://gradle.org/install/) and the Android SDK setup on your machine, then you should not need the IDE.
Try first checking for available devices:
flutter devices
Then using the device that you find (if there are any spaces in the name that represents the device then use "" to format the command), execute the following command:
flutter run -d "Device Name With Spaces" --release
Or:
flutter run -d DeviceNameWithoutSpaces --release
The first option is You can run your application on chrome or edge if you don't want to download an emulator. Follow the following steps:
Click on the no-device option to select the device.
Now select chrome or edge
And the second option is you can connect your mobile with your PC and use your phone to run the flutter apps. Follow the following steps:
For Android:
Enable developer options and USB Debugging on your device. This varies slightly
by android version. But the short version is you tap on the device build number
7 times.
Then a “Developer Options” option comes up. After that, you can click “enable
USB Debugging.”
Then plug your phone into your computer with a USB cable. You’ll see some popup
on your phone asking if you want to allow USB debugging with that computer.
Click on “yes”.
Run Flutter just like you would if you had a simulator running.

Flutter : No Devices available [duplicate]

This question already has answers here:
Android Studio, Suddenly got GPU Driver Issue when running emulator
(11 answers)
Closed 10 months ago.
Good night people !!!!
I am making settings in the Flutter Framework to use Android Studio, I already did a lot of the settings but when interpreting the flutter in the command line, do not find the device, so I went to look for the settings in Android Studio and gave a stop in the AVD Manager to Virtual Devices ... the error
GPU#1
Make: 8068.
Model: Mobile Intel (R) 4 Series Express Chipset Family (Microsoft Corporation-WDD 1.1)
Device ID: 2a42
I ask for help solving the problem. Here is the error screenshot.
Try to run the emulator via command line/terminal/cmd.
first, find the emulator list:
emulator -list-avds
then run one of it:
emulator -avd avd_name -gpu mode
If you cant find the emulator command, try to look at the executable in
c:\Users\username\AppData\Local\Android\Sdk then add the path to your environment.
try running emulator from terminal, forcing it to run using hardware graphics (instead of letting emulator decide on which) using command
emulator -avd avd_name -gpu mode
where mode is host so that it will run with hardware.
example:
Using Android Studio terminal move to folder where the emulator is located. Default on Win10 is: C:\Users\userName\AppData\Local\Android\sdk\emulator
Find emulator to run by listing available ones: emulator -list-avds
Run emulator with -gpu host option: emulator -avd avd_name -gpu host
Checkout the following path.
File > Project Structure > Project SDK
If there is NO SDK selected. Then Select Appropriate Android SDK by configuring it.
Otherwise,
In your terminal, add following command
adb kill-server
adb start-server
I hope this will definitely work for you.

How to upgrade the chrome browser version Android 7.0 emulator in android studio

I have created a Virtual Device with the Android flavor I want (Android 7.0) but it has a version of Chrome that I'd like to update to a specific version. How would I go about doing that?
For me it was simple steps:
Open Android emulator from AVD (Mine was Google Pixel 2 - v9.0),
Ensure Android emulator has opened successfully by $ adb devices(It will give you the Android emulator device name, e.g: emulator-5554)
Now download the Google Chrome apk from apkmirror, Mine was Version: 76.0.3809.111 (380911115) x86
Now use this command to install the downloaded Google chrome apk to the opened Android emulator: $ adb install /path/to/downloaded/chrome/apk
NOTE: Make sure no other emulator or real Android device is connected, $ adb devices should return you the single connected device
Above command must return Success
Open Chrome browser on Android device and check the version, it must match with the downloaded chrome version.
Done.
Having run into this and bashed thru a few useful sites, it turns out this is rather easy BUT you have to make sure you get the right APK. With thanks to https://www.inflectra.com/support/knowledgebase/kb276.aspx
First start your emulator in writable mode. Put your virtual device name after -avd parameter.
Step 1:
In Terminal execute this command:
$ $ANDROID_HOME/emulator/emulator -avd Samsung_Galaxy_S7_API_24 -writable-system
Your android emulator should now be open.
Step 2:
Download the apk you want from https://www.apkmirror.com/apk/google-inc/chrome/
Mine was https://www.apkmirror.com/apk/google-inc/chrome/chrome-64-0-3282-123-release/#downloads
Step 3:
Once it downloads, drag and drop that .apk file onto your emulator.
Wait a few minutes and then open Chrome on that device. It should be the new version.
You can confirm that by going to https://www.whatsmyua.info/

Message "flutter run: No connected devices"

I am trying to create a sample application with Flutter (fresh installation). Android Studio is also installed (fresh installation).
Here is the output of flutter run
flutter run
No connected devices.
The output of flutter doctor:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.1.5, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] Android Studio (version 3.0)
[!] VS Code (version 1.20.1)
[!] Connected devices
! No devices available
! Doctor found issues in 2 categories.
Is there a solution to this problem?
Flutter supports both iOS and Android device/simulators.
In the terminal, run the flutter devices command to verify that Flutter recognizes your connected Android device.
Here is a reference document on how you can set up a device/simulator to run your application.
For, Android (on a Mac system)
Set up your Android device
To prepare to run and test your Flutter app on an Android device, you’ll need an Android device running Android 4.1 (API level 16) or higher.
Enable Developer options and USB debugging on your device. Detailed instructions are available in the Android documentation.
Using a USB cable, plug your phone into your computer. If prompted on your device, authorize your computer to access your device.
In the terminal, run the flutter devices command to verify that Flutter recognizes your connected Android device.
Start your app by running flutter run.
By default, Flutter uses the version of the Android SDK where your ADB tool is based. If you want Flutter to use a different installation of the Android SDK, you must set the ANDROID_HOME environment variable to that installation directory.
Set up the Android emulator
To prepare to run and test your Flutter app on the Android emulator, follow these steps:
Enable VM acceleration on your machine.
Launch Android Studio → menu Tools → AVD Manager and select Create Virtual Device.
Choose a device definition and select Next.
Select one or more system images for the Android versions you want to emulate, and select Next. An x86 or x86_64 image is recommended.
Under Emulated Performance, select Hardware - GLES 2.0 to enable hardware acceleration.
Verify the AVD configuration is correct, and select
Finish.
For details on the above steps, see Managing AVDs.
In Android Virtual Device Manager, click Run in the toolbar. The emulator starts up and displays the default canvas for your selected OS version and device.
Start your app by running flutter run. The connected device name is Android SDK built for <platform>, where platform is the chip family, such as x86.
Here is another document, if you're using (Microsoft) Windows System: Get Started: Install on Windows
Open & Connect Device using Android Studio:
Here is an easier way to open and connect simulators/devices.
Android Studio shows a list of emulators/simulators (installed in your system) or devices (connected to your system). Just select a device you want to open from a list, and run the project.
Use:
flutter config --android-sdk ANDROID_SDK_PATH
Or
Device Not Found (when setting up Flutter in Android Studio)
Project structure -> select latest Android API in Project SDK
This was my solution:
My "Developer Options" was ON, but the "USB Debugging" was OFF.
So I turned ON the USB Debugging and the problem was solved.
None of the suggestions worked until I ran:
flutter config --android-sdk ANDROID_SDK_PATH
Use "ANDROID_SDK_PATH" = your path. For example:
flutter config --android-sdk C:\Users\%youruser%\AppData\Local\Android\Sdk
I solved the AVD problem with Flutter using the Flutter console.
Step 1:
C: \ Users \ valer> flutter emulators
6 available emulators:
3.2_QVGA_ADP2_API_22 _-_ Lollipop • 3.2in QVGA (ADP2) • Generic • 3.2 QVGA (ADP2) API 22 - Lollipop
Android_ARMv7a
Android_Accelerated_x86
Nexus S API Google Nexus S API 23
Nexus_S_API_25_1080x1920_Nougart_7.1.1_ • pixel • Google • Nexus S API 25 1080x1920 (Nougart 7.1.1)
Pixel_API_28 • pixel • Google • Pixel API 28
To run an emulator, run flutter emulators --launch <emulator id>.
Step 2:
C: \ Users \ valer> flutter emulators --launch Pixel_API_28
In my case
Menu File → Project Structure
Select the latest SDK:
I encountered the same problem as you did. It turns out that your device is not connected with your computer.
Note:
If you are using Xcode, if both your computer and the device are using the same Wi-Fi AP, you don't have to connect the device with the computer.
For Android, or iOS running under terminal command, if you are using command line to run this, you have to make sure they are connected via cables. Sharing the same Wi-Fi AP does not work. Make sure your device is really connected.
Make sure you allowed USB Debugging on your Android device.
If this still does not work, try to fire the below command, where you can get richer information and details:
flutter run --verbose
What I needed to do:
flutter emulators
It will list all available emulators. For iOS you will need to open the simulator first.
flutter emulators --launch EMULATOR NAME
This will launch the emulator.
And to build it:
flutter run -d "EMULATOR ID"
I ran mine with Genymotion, probably the best for Flutter.
Setting up is less painful, but make sure setting ADB under:
Your Andouird SDK path
Mine is C:\Users\user\AppData\Local\Android\Sdk.
I am using Linux and here are the steps that can help. First open Android Studio with root permissions, (Windows: Right-click the program icon → Choose Run As Administrator, Linux: sudo ./studio.sh in the terminal)
Create emulator with Hardware - GLES 2.0 in hardware acceleration as mentioned here. Open a terminal in Android Studio (Alt + F12).
Run command flutter devices and see the list devices:
root#abc-OptiPlex-3050:~/flutter_workspace/my_app/my_app# flutter devices
Woah! You appear to be trying to run flutter as root.
We strongly recommend running the flutter tool without superuser privileges.
1 connected device:
Android SDK built for x86 • emulator-5554 • android-x86 •
Android 8.1.0 (API 27)(emulator)
Finally run flutter run from the terminal:
root#abc-OptiPlex-3050:~/flutter_workspace/my_app/my_app# flutter run
Woah! You appear to be trying to run flutter as root.
We strongly recommend running the flutter tool without superuser privileges.
Using hardware rendering with device Android SDK built for x86.
If you get graphics artifacts, consider enabling software rendering
with "--enable-software-rendering".
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle... 0.7s
Resolving dependencies... 1.2s
Running 'gradlew assembleDebug'... 1.5s
Built build/app/outputs/apk/debug/app-debug.apk.
I/FlutterActivityDelegate(25096): onResume setting current activity to this
Syncing files to device Android SDK built for x86...
D/ (25096): HostConnection::get() New Host Connection established
0xe8487780, tid 25116
D/EGL_emulation(25096): eglMakeCurrent: 0xe5b3d8a0: ver 2 0 (tinfo 0xe84832f0)
🔥 To hot reload changes while running, press "r". To hot restart (and
rebuild state),press "R".An Observatory debugger and profiler on
Android SDK built for x86 is available at: http://127.0.0.1:8100/
For a more detailed help message, press "h". To quit, press "q".
And do check the flutter-sdk path in your project.Configure file from this answer.
Set Project SDK of project from Project Structure
File > Project Structure > Project SDK > "available sdk" > Apply
Sometimes you have everything perfect, but the device is no longer authorized on ADB. In such cases you have ADB, but it will not show you in connected devices.
Steps to fix this issue
1. Check if authorized:
Open terminal/cmd/PowerShell and write adb devices. It will show you all connected devices to the PC.
<ANDROID_SDK_HOME>\platform-tools>adb devices
List of devices attached
4df798d76f98cf6d unauthorized
2. Revoke USB debugging on the phone
If the device is shown as unauthorized, go to the developer options on the phone and click "Revoke USB debugging authorization" (tested with Android 4.1 (Jelly Bean) and Samsung Galaxy S III).
3. Restart ADB Server:
adb kill-server
adb start-server
4. Reconnect the Device and run following command again: adb devices
Now it should display authorized.
5. Ready to go.
Now, open your editor, Android Studio or Visual Studio Code, and check if your device is showing in connected devices or not.
You can simply check that with the flutter doctor command.
For Windows users,
Set the environment variable PATH for the Flutter SDK (...\flutter_windows_v0.2.8-beta.zip\flutter\bin)
No device connect
For more information, you can check blog post Flutter - How to install Flutter in Android Studio
Here is the information from the mentioned page:
Add Flutter to the Windows environment variable PATH:
Navigate in to the Flutter SDK folder.
Go inside the bin folder and copy the directory path (in your case C:\Flutter\bin)
Go to “Control Panel > User Accounts > User Accounts > Change my environment variables”
Under “User variables”, select the PATH variable and click Edit.
Put C:\Flutter\bin and apply.
Same as the Flutter environment, we have to set the Android SDK path if it is on custom location.
Navigate into the Android SDK folder.
Copy the directory path (in your case ..AndroidStudioSDK\sdk)
Go to Control Panel* → User Accounts → User Accounts → Change my environment variables
Under “User variables” select the PATH variable and click Edit.
Enter ..AndroidStudioSDK\sdk with ANDROID_HOME and apply.
Tips:
If you facing the following issue,
1.[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from https://developer.android.com/studio/index.html
On the first launch, it will assist you in installing the Android SDK components.
(or visit https://flutter.io/setup/#android-setup for detailed instructions).
If Android SDK has been installed to a custom location, set $ANDROID_HOME to that location.
You can resolve it with the following command.
flutter config --android-sdk <android-sdk-location>
OR
flutter config --android-sdk "android-sdk-location"
Error: Unknown argument --licenses
You can resolve it with the following command.
flutter -v doctor --android-licenses
Now, pick the emulator you want to use and click the green arrow to run the project. So, here default screen that is already designed.
I am facing the same issue with Flutter. But I found another way to work, i.e.,
First run Android Emulator
Then go to your Flutter Console
Run the command flutter doctor, anf check whether your emulator is showing under connected devices tag, e.g.,
Now move to your Flutter project path via the Flutter console. E.g., for me it is D:\FlutterWorkspace\flutter_demo
Then run the flutter run command. E.g.,
Wait for few moments. You will see your app running in the Android Emulator.
If you have
Downloaded the Flutter SDK
Connected your mobile device and enabled the developer option on the mobile and allowed USB debugging.
And if you are still getting "No device connected" then I think you should install the ADB driver.
It worked for me!!
Click here to download
There should be at least one device/simulator connected to run Flutter applications.
Also make sure the USB debugging is enabled in developer settings.
One option that I haven't see mentioned so far is that (for my setup) the Developer Option 'Select USB Configuration' must be set to MTP (Media Transfer Protocol).
The actual answer did not work for me.
But setting ANDROID_HOME in your ~/.bash_profile file, logging out, and then logging in, makes it work!
This may be an Android Studio issue since it is not setting this environment variable for the open projects.
Follow these step:
Menu File -> Project Structure -> Project SDK(Select the SDK Path in the Android SDK) -> OK
Make sure your device is connected to the PC.
Open Git Bash and type:
flutter devices
Then run your Flutter app. It will work.
Android Studio -> Preferences -> Languages & Frameworks -> Dart
Make sure you enabled Dart support for the module (should be checked in)
I had the same problems while I was debugging with a local Flutter engine. In such case, if you have set environment variable FLUTTER_ENGINE, you should unset it and restart you IDE.
Step 1: To check the connected devices, run: flutter devices
Step 2: If there aren't any connected devices to see in the list of available emulators, run: flutter emulators
Step 3: To run an emulator, run: flutter emulators --launch <emulator id>
Step 4: If there is no available emulator, run: flutter emulators --create [--name xyz]
==> For Android:
Step 1: To check the list of emulators, run: emulator -list-avds
Step 2: Now to launch the emulator, run: emulator -avd avd_name
==> For iOS:
Step 1: open -a simulator
Step 2: flutter run (in your app directory)
Flutter needs a device to run the app. There are two choices for this.
Run the app on your real phone.
Run the app on a virtual device in your computer.
I would recommend Option 1 because it doesn't use your device resources and is faster.
Option 1:
Unlock developer options on your phone, go to developer setting and turn on USB debugging and connect your phone to your computer. Now run flutter run and it will work.
Option 2:
Open Android Studio, go to AVD Manager, add a virtual device if you haven't done that yet and run the virtual device. Now run flutter run again and it should work.
Note that this way works with any virtual device and not just virtual device from Android Studio.
I solved the problem after changing "ANDROID_HOME" to the Environment variables and setting it to the location of your Android SDK...in my case C:\Android\Sdk.
None of the above solutions worked for me, but I was able to solve it by invalidating catch and restarting my Android Studio:
Menu File → Invalidate Catches / Restart...
EDIT:::
To clear Android Studio’s cache and bring it out of its state of confusion
select ‘File > Invalidate Caches / Restart’ and then click the ‘Invalidate and Restart’ button.
Clean and rebuild your project.
NOTE: I am using a Mi (Xiaomi) mobile (Redmi K20 Pro) which is running on Android 10
You need to do two things to show your device listing.
Go to your Android Studio, menu → File → Project Structure and choose the project SDK from the options. I chose the latest one from the menu.
When you connect your real device to your PC/laptop, make sure you choose Transfer photos (PTP) mode.
NOTE: Don't choose File transfer mode. It will not work.
After doing the above two things, you can check the status of your device availability by writing flutter devices on the command prompt.
I hope it shows your mobile device.
I had the same issue. Setting up the Android SDK is also a correct answer. But this is very simple -
Import an Android project to a new Android Studio window.
Close your current Flutter project Android Studio window.
Import that Flutter project to a new Android Studio window.
It basically needs a device "connected" to your development machine. If you're using a simulator/emulator running on the machine it should automatically be recognised as a connected device. Another way is to connect a physical device and the setup process varies slightly for Android and iOS devices.
This works for me:
Go to Settings > Developer options > Disable USB debugging > Re-enable USB debugging
For Windows users,
The solution for me was running Android Studio as administrator
For me it was
adding "ANDROID_HOME" to the Environment variables and setting it to D:\dev\android\ (for me)
adding "D:\dev\android\platform-tools" (for me) to environment variable PATH. I put flutter there before
OK, OK, OK. Restart Android Studio