Introducing Visual Studio ' s Emulator for Android

Source: Internet
Author: User

Original address

Microsoft released Visual Studio Preview this week and with the IT you now has options for Android development:c++, Cor Dova, and C # with Xamarin. When choosing one of those Android development options, Visual Studio would also install the brand new Visual Studio Emulat Or for Android to use as a target for debugging your app. You can also see it in action with this video.

To help us prioritize enhancements to the emulator and fill out our short survey.

Before I walk you through using this new emulator and let's talk on why we're building an emulator for Android–feel fre E to skip the next sections to go to the interesting part:-) The need for a emulator for Android

We know that emulators can play a key part in the Edit-compile-debug cycle (bigger part than devices) and we believe that You need a emulator like the one we is releasing today.

Have a great emulator to debug against doesn ' t mean you don ' t need a device, and have a device to debug against doesn ' T mean won ' t benefit from a good emulator. They is complementary.

You definitely need to test against a device for the following scenarios which is unsuitable for any emulator:

    1. Measuring the performance characteristics of your code. While a emulator can help you with correctness issues, it'll never perfectly emulate the performance of Your code running on the actual devices so you want to test against. You want to measure the performance as your users see it.
    2. Testing hardware-specific issues. If What's trying to test was the touch-responsiveness of your game, or the speaker quality for your media app, you WI ll want to does that type of testing on the target devices. Ditto If you is trying to work around an oem-specific bug.
    3. purely evaluating the actual user experience in real-world situations , e.g. do your designed Interactions work for a user walking around using your app one handed with just their thumb alone?

For all other testing, which as part of the your edit-compile-debug cycle normally takes at least 80% of your time, you ' d want To use the emulator (barring other blocking issues or limitations with your emulator of choice). Use a emulator for the following reasons:

  1. The majority of your testing is for correctness issues (not performance) and the majority of your code are probably not DEA Ling with hardware specific issues. So use an emulator!
  2. You don ' t want to spend a bunch of money buying a bunch of devices (and keep doing so every time a new device appears on t He market), just to test things like screen resolution, DPI settings for different screen sizes, different API levels/pl Atform versions, when you can configure it in the software (in an emulator).
  3. You don't want to any of the physical action with the your device to test some sensor, e.g. respond-movement or location Changes or simulating network/battery changes. Instead want to simulate the sensor values easily and quickly in an emulator, e.g. simulate a trips to another town WHI Le your app responds to the change of location.
  4. There is also the convenience element. Connecting to a device (typically dealing with cables), managing. Connection and its lifetime, using one of your USB p Orts, is isn't as simple as launching the emulator and treating it like every other desktop application running on your dev Machine.

So emulators am great and can be a key part, the Edit-compile-debug cycle and we want to make sure, we emulator is Best-in-class. You have told us on several pain points with existing emulators that we is starting to address with our Relea Se

  • Slow. This is the number one complaint we ' ve heard from Android developers. "The emulator is painfully slow, it hurts my productivity, and I'll use a device." Slow is not acceptable. If anything, using the emulator should is faster than using a device so can test your scenarios faster (remember, you is not using emulators to test the performance of our code, you just need them to is as fast as possible for your own using ).
  • Conflict with Hyper-V on Windows. Many emulators require you to disable Hyper-V or don ' t work as well with Hyper-V as they do without. Using Hyper-V is part of the development setup for many developer activities, so asking you to restart your machine (multi Ple times a day) to toggle Hyper-V is not acceptable.
  • O One specialized variant of this is using the Windows Phone emulator (which itself are based on Hyper-V). It is a real pain have to do changes and reboot every time you want to switch from an Android emulator to a Windows Ph One emulator to test your cross-platform code.
  • Additional Acquisition and installation step. If your main development environment is Visual Studio, you don't want to any acquire the emulator separately and Follo W a separate installation process.
  • separatecost. Have a great emulator that can cost you as much as your main development environment are not an option for most. The Visual Studio Emulator for Android comes with VS without additional charge.

In short, we'll address all of those pain points with the Visual Studio Emulator for Android. Now, let's recap Visual Studio ' s debugging Story for Android and what to choose the VS Emulator for Android. Debugging against the Visual Studio Emulator for Android

With Visual Studio-Preview you can target Android and edit-compile-debug regardless of your choice of programming mod Els:javascript (or TypeScript) with Cordova, C + +, or C # with Xamarin.

With all three of those choices, when you start debugging, you must first choose a target. That target can is a device, or it can be is one of many emulators that your may has running on your machine. Let's see how to choose a debug target for Cordova and C + + in Visual Studio-Preview, and for Xamarin in Visual Studio 2015.

With C + + projects, the Debug Target menu looks like this:

With Cordova projects, you'll want to pick, the last of the entries in the Debug Target menu as per the following screenshot:

(Definitely avoid picking the option "Android Emulator" as that's the slow one, comes with the SDK)

With Xamarin projects, the option looks like this:

For best results with Xamarin projects, disable/uncheck "use Fast Deployment" under the Android Options under the Xamarin Project Properties.

Note:if want to use the VS Emulator for Android from a different IDE, as a temporary workaround all can always LA Unch our emulator from Visual Studio-using one of the options above, then close that project and leave the emulator R Unning and available for your other IDE to target (over ADB).

Once You has chosen your debug target and hit F5, your app'll be deployed to the emulator, as per the regular VS Debugg ing flow you can hits breakpoints in your code, see the call stack, inspect variables, etc. So now that you know how to use the emulator for debugging, let's continue exploring its cool features! Sensor simulations and other capabilities of the Visual Studio Emulator for Android

Beyond using the emulator as a deployment target, you can also take advantage of sensor simulation and other capabilities –let ' s examine a few of those, in no particular order.

Zoom

You can change the size of the emulator as you see it on your development machine (the host). The dots per inch (dpi) for the emulator are based on the host monitor DPI, regardless of the zoom value. This allows-the-emulator in case it's taking too much space on your desktop.

To change the size, use the "Zoom" button on the emulator ' s vertical toolbar.

You can also use the ' Fit to Screen ' button above the ' Zoom ' button to Fit the emulator on your screen.

If you is going to take screenshots of your apps running in the emulator (e.g. with the Snipping Tool) for best results re Member to set the zoom level to the maximum of 100%-or even better, with our built-in screenshot tool support that I desc Ribe below. Orientation/rotation

Unless your app is supports a fixed orientation, you should test how your apps responds to orientation changes, and what It looks like in portrait, Left-landscape, and Right-landscape orientations. Simply rotate the emulator left or right with the both corresponding buttons on the vertical toolbar: "Rotate Left" and "Ro Tate right. " The size of the emulator remains the same when you rotate. Network Info

The emulator reuses the network connection of the host machine and so there are nothing for your to configure.

You can also review the emulator ' s current network settings. On the vertical toolbar click on the ' Tools ' button to show the ' Additional Tools ' fly out panel, and then click on the ' N Etwork "tab.

Location (GPS)

If your app does anything with navigation, geofencing, walking/biking/driving, then you'll love the location and driving Simulation in the emulator under the ' Location ' tab when you open the ' Additional Tools '.

You can navigate the map by dragging it around, by zooming/in and out, or even by searching for a location. You can place and remove pins on the map, thus creating map points. Those appear as latitude longitude coordinates in the list of bottom left. From the toolbar in the top you can even save those map points to a XML file and later load them from the file.

Instead of has each map point immediately change the GPS location ofthe The emulator ("Live" mode) and you have othe R Options Too! Want to place a few maps points and then simulate transitioning between those points. To does, at the toolbar on the top switch from ' Live ' mode to ' Pin ' mode. Then your can press the small play button at the end of the toolbar to transition between the map points. You can even enter a transition interval (in seconds).

Finally, you can choose a third mode, which is the similar to "Pin", the which is called "Route" mode. The This mode can also simulate transitions between the points, with some additional twists. The simulator would calculate an actual path between the points and generate invisible points at 1 second intervals between The points you choose. The overall speed at which it'll play those points is determined by a second setting and your options are: "Walking" (5 Kilometers per hour), "biking" (km/h), "Speed Limit" (variable dependent on the map point), and "Fast". Accelerometer

If your app tracks and responds to movement of the the phone, you can test them using the ' Accelerometer ' tab when you open th E "Additional Tools".

Simply Click and hold the red dot in the middle and drag it towards the directions of want to simulate, within the 3D PLA Ne. As you do the your app would receive movement events if it has registered for them.

You can also see the X, Y, Z values in the bottom left. Under those values can "Reset" to the starting position, and also pick the starting Orientation from these Values:por Trait standing, Landscape standing, Portrait Flat, and Landscape Flat.

Lastly you can simulate the phone shaking by clicking the ' Play ' button in the bottom right. The only visual indication, a shake is taking place is the values of the x, Y and Z and when they stop rapidly changing yo U ' ll know the shake is over. Power/battery Simulation (and Power button)

If you write your apps to respond to battery charge changes and then you'll like the emulator's ability to simulate this by Switching to the ' Battery ' tab when you open the ' Additional Tools '.

There is a slider this allows you to set the exact charge value of the battery. Notice as slide down/up how the battery icon in the top right changes to reflect the change. Your app can also respond accordingly.

If you change the Battery charging state to not being "charging", then the emulator ' s screen would go blank after a timeout PE Riod. You can configure the timeout though the built-in regular ' Settings ' app (look for the "Sleep" option under "Display"). If the emulator sleeps due to this and then your can wake it up through the ' Power ' button on the vertical toolbar.

Screenshot

To take a screenshot of your apps, open the "Additional Tools" and switch to the "Screenshot" tab. Then click on the "Capture" button, which'll take a screenshot and show a instant preview. If you want to keep the screenshot click on the "Save ..." button. If you don't like the screenshot took, ignore it or click "Capture" again.

The screenshot tool always takes screenshots at 100% (indicated by the resolution on the bottom left corner), regardless O F Zoom setting. They is also always portrait, regardless of rotation chosen. Install APKs through drag and drop

You install the apps on Android through a application package file which are known as an APK. If you have a APK that is want to install on the Visual Studio Emulator for Android, just drag it onto the Emulator from Windows Explorer. You'll see a message in the emulator indicating progress "file transfer in progress ..." followed by a message box "file fo o installed successfully in Android ". Remember to make sure your APKs has code built for x86!

You can also drag and drop other (non-apk) files to the emulator and they would be placed onto the SD Card, which brings us To the next topic. SD Card

If your app has a need to read or write to the SD card of the the target, the emulator simulates so by making available a fo Lder representing an SD card.

Note that the Android image uses a separate VHD for SD card support. So if you want to transfer files to/from the SD card on your development machine, you can mount the VHD to Windows:close The emulator (to shut-down the VM), then navigate-to-the VHD in Windows Explorer, and double-click the VHD to MOU NT it. By default, the VHD is located under the path:

C:\Users\%username%\AppData \local\microsoft\xde\android\vsemu.sdcard.vhd

At this point, the VHD is mounted as a additional drive to Windows and you can use it pretty much like any other drive. Before restarting the emulator you must un-mount the VHD, which you can do by right clicking on the drive and selecting Ej Ect.

have SD card support in the image also allows other built-in Android apps to function, such as the browser downloads and The camera App–which brings me to the next capability. Camera

Typically you ' d is using the camera from the Your app (using a appropriate API), and we support that. You can also use the built-in camera app directly. When you launch the camera on the emulator you'll see a fixed animated image so you can take a snapshot of, simulating Taking a picture. Audio Playback, Keyboard Text Input ...

There is capabilities that the emulator provides that is taken for granted, even though they require ' work ' from t He product team:-). I won ' t list them all this but the them is that:

    • You can use your computer ' s keyboard to enter text in the emulator
    • Any audio coming from the emulator can be heard through your computer ' s speakers
Configurations

With this Preview release you can pick between the the box configurations:

    • Typical Android phone:5 "screen, 295 PPI, 720x1280, 1024x768
    • Typical Android tablet:7 "screen, 315 PPI, 1080x1920, 2048 MB

With the Preview bits if you want to change the amount of memory, you can change the Startup RAM in the Settings dialog fr Om the Hyper-V Manager. Notice that there you can also change the number of cores allocated to each configuration (the default for Preview is 2 co RES). Caveat:we has not tested all possible configurations you could choose!

We are just getting started, there was a lot more to come in subsequent releases and you can help us prioritize new sensor Simulation and other capabilities by taking our survey. A Peek under the covers

If you were interested in how do we built the Visual Studio Emulator for Android, the short answer was that we reused the work of others. Conceptually, an emulator consists of 4 pieces:

  1. A virtual machine (represented as a VHD) of the "target" is emulating, in this case Android. We started with the source at the Android Open source Project (AOSP), evolved it, and configured a x86 virtual image for Fast Visual Studio Debugging.
  2. A small shell/chrome that as a user who see and interact with, which loads the virtual image and projects it through a ren Dering control. Think of this as remote desktop:you is essentially rdping to the image. We started with the desktop application so is the shell/chrome of the Windows Phone Emulator (internally known as XDE), Which is already rich in functionality. Then we made modifications for our android-specific needs.
  3. A virtualization technology that XDE needs to load the image before it can RDP to it. Windows has a great virtualization technology called Hyper-V and that's what we used.
  4. The connection pipeline between VS and XDE and also between the debug engine and the virtual image. Here we reused parts of what existed between XDE and Visual Studio, and also the Android Debug Bridge (ADB) channel.

Now let's look at some of the limitations we had today, and hopefully you can give us input on which ones we need to addr ESS first. Current limitations

Today we are sharing with early preview release, with issues/bugs that we look forward to us. We also has known limitations –please tell us which ones is most important to your so we can prioritize these O N Our backlog:

  • If your app makes direct or indirect use of the OpenGL 2 or higher, that won't render on our emulator yet. This are coming soon, and looking at a early internal-only build that I had it does make the image feel even snap pier!
  • There is many different versions of Android on the market. The one of you has with this release of the Visual Studio Emulator for Android is KitKat API (version android-4.4.4_r1). More versions coming later ...
  • If your app takes advantage of the Google Play Services layer then it won't work out of the box in our emulator. That's because when building our Android images we don't include the GMSpackage S (which require additional LIC Ensing that we don't have yet).
  • You need to recompile your code for x86. If you have parts of your code that can is compiled for ARM, or you depend on 3rd-party libraries for which You don't have an x86 version, your code would not run in our emulator at the this point.
  • You can only install the Visual Studio Emulator for Android in an operating system where Hyper-V is supported. Examples of where Hyper-V is not supported include Windows 7, non-windows machines, and inside another VMS.

If any of these limitations be an issue for an app you are developing and then the workaround be to use a device (or find a Other emulator () may not have the limitation). We'll be making this current list of limitations shorter with every release that we put out and so to take the survey T o Help us prioritize.

Introducing Visual Studio ' s Emulator for Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.