Introduction to Visual Studio Android Simulators

Source: Internet
Author: User

Introduction to Visual Studio Android Simulators

Microsoft released Visual Studio 2015 preview this week, which includes Android development tools. during installation, if Android development is selected, Visual Studio also installs the Visual Studio simulator used to debug Android applications. you can also click here to view the video introduction.

To help us make the simulator better, enter this short questionnaire.

Before introducing this new simulator, let's talk about why we need a new Android simulator.-Of course, you can jump to the desired part and read it :-)

Necessity of Android Simulator

As we know, simulators play a very important role (or even more important than physical devices) in the programming-compilation-debugging development cycle ). therefore, we believe that the simulator released today is essential for development.

Having a good simulator doesn't mean we don't need physical devices, and vice versa, they are actually complementary.

In the following situations, the simulator can only be used for testing on physical devices:

  1. Test the code performance. although the simulator can help you correct errors in the code, it cannot be correctly given, and the code performance evaluation on the specified device. after all, we all want the test results to be as close as possible to the user's actual use.

  2. Test some hardware problems. For example, if you want to test the touch sensitivity, sound effects, or debugging OEM device bugs, these tests can only be performed on physical devices.

  3. Evaluate the real user experience. For example, the human-computer interaction interface you designed is not suitable for users to walk and operate with a single thumb?

Except for the scenario listed above, everyone should be happy to use the simulator. Because debugging code usually takes 80% of the development time, And the simulator greatly improves our work efficiency. (Unless your simulator has other obstructive problems or restrictions ). The following are the reasons for using the simulator:

  1. Most of the testing work is to verify the correctness of the program rather than the performance, and most of the Code is irrelevant to the underlying hardware. Therefore, it is excellent to use a simulator.

  2. Buying a large number of hardware devices for testing is a luxury (especially continuous purchase of new machines ). Most hardware differences can be configured using simulator software, such as screen resolution, DPI of different screens, API level/platform version number, and so on.

  3. It is also difficult to use physical actions to test the program's response to sensor input, such as action changes, geographic location changes, or network/battery changes. In this scenario, it is very convenient and efficient to select a simulator to simulate sensor input. For example, a simulator can simulate location changes during a journey and test the application's response to location changes.

  4. It is also convenient to use the simulator. Managing multiple USB devices with physical connections (a large number of connections and interfaces) is troublesome. In this case, it is much easier to use the simulator. The simulator is a general application-layer sequence running on the computer, which removes the trouble of physical connection and is very easy to manage.

Therefore, the simulator is a good companion for software development. We hope to make the VS simulator the first stream. We collected the pain points of existing simulators from developers and cracked them one by one in our versions:

  • Slow speed. This is the top complaint from Android Developers. "This simulator is very slow and seriously affects my productivity. I am not as good as using a real machine for testing ." Slow speed is unacceptable. It is faster to use a simulator than to use a real machine, so as to improve the test efficiency. Remember, we are not testing the code running performance. For function testing, we need to make the simulator run as fast as possible.

  • Conflict with Windows Hyper-V. Many simulators disable Hyper-V at run time, or worse performance when using Hyper-V. However, enabling Hyper-V is a common configuration for most developers. It is unacceptable to frequently restart your computer to switch Hyper-V.

  • Developers who want to use Windows Phone simulators (based on Hyper-V) are even more worried. It is impossible to constantly restart and configure computer settings because you need to test cross-platform code.

  • Additional purchase and installation steps. If you are already using Visual Studio, congratulations, you are not allowed to purchase or install another simulator software.

  • More expenses. Purchasing an excellent simulator also means higher overhead, which is one of the main reasons for rejecting the simulator. The Android simulator of Visual Studio is provided with no additional fees.

To put it simply, we solved the above pain points in the Andriod simulator of Visual Studio. Let's not talk about it. Next we will introduce how to debug the Android simulator using VS. We will start from how to select the Android simulator.

Debug Android program with Visual Studio Simulator

No matter which programming mode you use: Cordova, C ++ using JavaScript (or TypeScript), or Xamarin using C, you can write-compile-Debug Android code on Visual Studio 2015 preview.

When starting the debugging mode, select the debugging Target ). the debugging target can be a physical device or a simulator running on your computer. let's take a look at how to select a debugging target for Cordova, C ++, and Xamarin of Visual Studio 2015.

Shows the menu for selecting the debugging target of the C ++ project:

For the Cordova project, select the last two items in the menu. For details, refer to the following:

(Do not select "Android Emulator" because it runs too slowly)

Shows the options of the Xamarin project:

It is best to select "Use Fast Deployment" in "project properties-Android.

Note: if you wantAndroidIDETemporary UseVS SimulatorFirst, start the simulator according to the method described above. Then, turn off the project and keep the simulator running.ADBCall the simulator of.

After selecting the debugging target, press F5 to release your application to the simulator. just like debugging VS code at ordinary times, the program runs to the breakpoint and stops. Then you can view the stack, variables, and so on. now everyone knows how to debug it with a simulator? We will continue to provide other functions.

Sensor Simulation and other capabilities of Visual Studio Android Simulator

In addition to using simulators as the target board for deployment, you can also use the simulator's Sensor Simulation and other functions. The following sections describe some of these parts in different order.

Zoom

You can adjust the display size of the simulator on the development machine (host side. The DPI value of the simulator is determined by your host monitor and has nothing to do with the zoom size. So if you think the simulator occupies too much desktop space, narrow it down.

Use the Zoom button in the toolbar on the right of the simulator to adjust the size.

You can also use full Screen mode and click the "Fit to Screen" button above the "Zoom" button.

If you want to take screenshots of programs running in the simulator (for example, using the screenshot tool provided by windows, adjust the scale ratio of the simulator to the maximum (that is, 100% ). If you want better results, you need to use the screenshot tool that comes with the simulator. This tool will be mentioned later.

Orientation/rotation of the screen

Unless your application interface is fixed, you should test the effects after the application interface is flipped when the mobile phone is in different directions, such as vertical screen and left horizontal screen, right horizontal screen. the vertical toolbar has two buttons "Roate Left" and "Right Rotate" to Rotate the simulator to the Left and Right, respectively. the simulator size remains unchanged after rotation.

Network Information

Because the simulator uses the network connection on the host machine, you do not need to configure the network part.

You can click the "Tools" button on the vertical toolbar, and then click "Network" in the expanded "Additional Tools" panel) tab to view the network configuration information.

Positioning (GPS)

If your application is related to navigation, geofencing, walking, cycling, and driving. then, the positioning and simulation functions in the Location tab of the "Additional Tools" Panel will become very useful.

A map can be dragged, zoomed in or out, or even located at a specific position. you can place or remove a pin on a map to create a map point ). coordinates are displayed in the lower left corner. the Save button on the toolbar above stores the points on the map as XML files. reload the data when necessary.

In addition to the "Live" mode, the point on the map directly changes the GPS Position of the simulator. There are other modes to choose from! For example, you want to set several points on the map and simulate the moving effect between these points. select the "Pin" mode. click the Play button on the rightmost of the toolbar to simulate the moving effect from one point to another .. You can even set the moving speed (in seconds ).

Finally, there is a "Route" Mode similar to the "Pin" mode. This mode also simulates the moving effect from one point to another. However, there are more twists and turns ". The simulator automatically calculates the actual path between two points and creates an invisible point for this path at an interval of 1 second. The moving speed between these points depends on another setting. The options include "Walking" (5 km/hour), "Biking" (25 km/hour), and "Speed Limit) "(on the map, different locations, different speeds), and" Fast )".

Acceleration Sensor

If you want to test the app's response to the mobile phone, open "Accelerometer" in the "Additional Tools" panel )".

In the 3D panel, press the red dot in it and drag it in the direction you want to simulate. if your application has written code to process mobile events. then it can receive the mobile phone event.

You can click the "Reset" button to Reset the X, Y, and Z values in the lower left corner. you can also choose from Portrait, Landscape Standing, Portrait Flat, and Landscape Flat ), set the initial Orientation of the mobile phone ).

Finally, you can click "Play" in the lower-right corner to simulate the vibration effect. the vibration effect we can see is actually changing the values of X, Y, and Z. if these values do not change dramatically, the vibration has stopped.

Power Supply/battery simulation (and switch button)

Assume that your application needs to respond to changes in battery power. Then you will like the features provided in the Battery tab on the "Additional Tools" panel.

There is a slide in it to set the remaining battery power. When you adjust the power, the battery icon in the upper right corner will also change. Your application will also respond accordingly.

If you deselect the "Charging" check box, the simulator screen will become black after a while ). you can set this time in Settings-Display-Sleep. click the Power button on the vertical menu bar to wake up the simulator from sleep.

Screenshots

To take screenshots of an application, open "Other Tools" and switch to the "screenshot" tab. Click the "capture" button to capture the screenshot and let you preview the screenshot. If you want to save the screenshot, click "Save. If you do not like your screenshot, ignore it or click "capture" again.

The screenshot tool always implements the screenshot (according to the definition displayed in the lower left corner) 100%, regardless of the scaling settings. Always front, no matter which image rotation method you choose.

Install APKs by dragging

APK is the installation file for Android. To install the APK file on the Visual Studio simulator, drag the APK file to the simulator. During installation, the simulator prompts "copying files ...". After the installation is complete, a message box will prompt "xxx file has been successfully installed in Android ". Make sure that your APK file is generated in x86 mode!

Of course, you can also drag other types of files (non-APK files) to the simulator to save these files to the SD card. This is what we will talk about next.

SD card

If you want to read and write data to the SD card of the target device, the simulator can simulate the SD card using a folder on the hard disk.

Note that the Android image uses an independent VHD file to simulate the SD card. so if you want to transfer files on your development machine and the SD card, you can install this VHD on your Windows: Disable the simulator (to stop VM running ), then find the location of the VHD on Windows Explorer and double-click it to install it. by default, VHD is located in the following path:

C:\Users\%username%\AppData \Local\Microsoft\XDE\Android\vsemu.sdcard.vhd

In this way, the VHD is installed on your Windows as another drive, and you can use it like other drives. before restarting the simulator, you must uninstall the VHD. You can right-click the drive and select "pop-up Eject" to perform this step.

You can implement SD card support in the image so that other built-in Android applications and functions can be used, such as Browser Download and camera applications-It brings me the next capability.

Camera

Usually you may want to use the camera in the application (using a suitable API), and we support this function. you can also directly use the built-in camera application. when you start the camera in the simulator, you will see a fixed image. You can get a snapshot of this image to simulate the photo.

Audio Playback, keyboard text input...

Of course, the simulator will certainly provide some other functions, even though they need "effort" from the product team ":-). I won't list all the functions here. There are two of them worth noting:

  • You can input text on the keyboard of your machine in the simulator.

  • Any audio from the simulator can be listened to through your machine's audio

Configuration

In the preview version, two sets of default configurations are provided:

  • Typical Android phone configuration: 5-inch screen, 295 DDI, 720 x, MB

  • Typical Android tablet configuration: 7-inch screen, 315 DPI, 1080 x, MB

You can modify the memory allocation in the preview version. The "Startup RAM" option is provided in the configuration window of Hyper-V Manager. Note: You can also modify the number of CPU Cores Used in each configuration (the default value is 2 ). However, we have not tested all possible configurations.

Our work is just getting started. We will provide more functions in later versions. We also hope that you will give feedback in the following questionnaire, so that we can sort the requirements.

See internal implementation principles

If you are interested in the Implementation Principles of the Visual Studio Android simulator, I can simply answer this question, that is, we have reused the work of other products. A simulator can be divided into the following four parts:

  1. A Virtual Machine (expressed as a vhd) is used to simulate the target board you are using. Here the target machine is Android. We first get the code from the Android Open Source Project (AOSP), and make improvements to configure it as an x86 virtual image, so that you can use Visual StudioFastDebugging.

  2. Shell/Chrome provides a user interaction interface that can be used to load virtual images and render and display them. You can compare this process with Remote Desktop: in fact, you are remotely connected to a local image. Our job is to start from here and use the shell/chrome of the Windows Phone simulator (we internally call it XDE. Then, some necessary modifications are made based on the special requirements of Android.

  3. With virtualization technology, XDE uses the first virtualization technology to load images for remote connection and control. Windows has profound virtualization technology skills. We use Hyper-V to complete this task.

  4. Connect the MPs queue. VS and XDE need to communicate through the connection channel. The same debugging engine and virtual image are also required. Here we reuse the existing connection mechanism between XDE and Visual Studio, and also use Android Debug Bridge (ADB ).

Now, let's take a look at the restrictions on the use of this application. I hope that you will give us feedback on improvement suggestions. We will give priority to the feedback.

 

Current limits

Today we will share with you the early preview version, which contains many problems and bugs. I hope you can give us more feedback. At the same time, this version has many known restrictions for use-we will give you your most desired features and give them a priority:

  • Directly or indirectly using applications of OpenGL 2 and later versions, the simulator currently cannot render and display. This feature will be supported soon. We have already implemented it in the internal version and it will feel very smooth!

  • There are too many different Android versions on the market. Currently, only KitKat API 19 (android-4.4.4_r1) is supported ). More versions will be supported later...

  • If your APP uses the Google Play Services layer, these apps cannot run directly on the simulator. This is because the Android image we built does not contain the GMS package (we have not yet obtained the relevant license ).

  • You need to recompile your code under x86. If your code can only be run under ARM or a third-party library that cannot be run under x86, your code cannot be run on our simulator.

  • You can only install our simulator on an operating system that supports Hyper-V. Operating systems that do not support Hyper-V include Windows 7 and other non-Windows systems, or run on other virtual machines.

For example, the above restrictions are urgently needed. The current solution is to use a real machine for testing (or find another better simulator ). We will shorten the above restriction list in later versions, so please fill in the questionnaire to help us sort the priority.

Introducing Visual Studio's Emulator for Android

Visual Studio 2010 & Help Library Manager installation instructions

How to configure OpenCV 2.3.x/2.4.x in Visual Studio 2005/2008 and Visual Studio 2010

Use the opencv-2.4.0.exe file to compile the x86 or x64 platform Visual Studio 2005/2008/2010 target file

Visual Studio LightSwitch supports HTML5 and JavaScript

Visual Studio 11: use C ++ to develop a simplest Metro application

Visual Studio details: click here
Visual Studio: click here

This article permanently updates the link address:

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.