Visual studio android


Android and iOS development with C++ in Visual Studio

When it comes to building mobile applications, many developers write most or a part of the apps in C++. Why? Those who are building computationally intensive apps such as games and physics simulations choose C++ for its unparalleled performance, and the others choose C++ for its cross-platform nature and the ability to leverage existing C/C++ libraries in their mobile applications. Whether you’re targeting Universal Windows Platform (UWP), Android, or iOS, Visual Studio enables building cross-platform C++ mobile applications with full editing and debugging capabilities all in one single IDE.

In this blog post, we will focus on how to build Android and iOS apps with C++ in Visual Studio. First we will talk a look at how to acquire the tools for Android and iOS development, then we will create a few C++ mobile apps using the built-in templates. Next we will use the Visual Studio IDE to write C++ and Java code, then we will use the world-class Visual Studio debugger to catch issues in C++ and Java code. Finally, we will talk about how the C++ mobile solution can be used in conjunction with Xamarin.

Install Visual Studio for Android and iOS development

First, download Visual Studio 2017 and launch the Visual Studio installer.

To build Android or iOS applications, choose the “Mobile development with C++” workload under the “Mobile & Gaming” category.

Android development: By default, this workload includes the core Visual Studio editor, the C++ debugger, GCC and Clang compilers, Android SDKs and NDKs, Android build tools, Java SDK, and C++ Android development tools. You could choose to install the Google Android Emulator in the Optional Component list if you don’t have an Android device for testing. This should give you everything you need to start building Android applications.

iOS development: if you’re also targeting iOS, check “C++ iOS development tools” in the Optional Component list and you would be good to go.

Create a new Android application using project templates

If you plan to start with targeting Android first and worry about other platforms later, the VS built-in Android project templates including Native-Activity Application, Static Library, Dynamic Shared Library, could be a great starting point. If you’d rather start with a cross-platform solution to target multiple mobile platforms, jump to the next section Build an OpenGLES Application on Android and iOS where we’ll talk about building an app that targets both platforms with shared C++ code.

You can find the Android templates under Visual C++ -> Cross Platform -> Android node.

Here we’re going to create a new Native Activity Application (Android), which is popular for creating games and graphical-intensive apps. Once the project is created, in the Solution Platforms dropdown, choose the right architecture that matches the Android emulator or device that you’re using, and then press F5 to run the app.

By default, Visual Studio uses the Clang toolchain to compile for Android. The app should build and run successfully, and you should see the app changing colors in the background. This article Create an Android Native Activity App discusses the Native Activity project in more details.

Build an OpenGLES Application on Android and iOS

The OpenGL ES Application project template under Visual C++->Cross Platform node is a good starting point for a mobile app targeting both Android and iOS. OpenGL ES (OpenGL for Embedded Systems or GLES) is a 2D and 3D graphics API that is supported on many mobile devices. This template creates a simple iOS app and an Android Native Activity app which has C++ code in common that uses OpenGL ES to display the same animated rotating cube on each platform.

The created OpenGL ES Application solution includes three library projects in the Libraries folder, one for each platform and the other one for shared C++ code, and two application projects for Android and iOS respectively.

Now let’s run this app on both Android and iOS.

Build and run the app on Android

The solution created by the template sets the Android app as the default project. Just like run the Android Native Activity app we discussed earlier, in the Solution Platforms dropdown, select the right architecture that matches the Android emulator or device that you’re using, and then press F5 to run the app. The OpenGL ES app should build and run successfully and you will see a colored 3D spinning cube.

Build and run the app on iOS

The iOS project created in the solution can be edited in Visual Studio, but because of licensing restrictions, it must be built and deployed from a Mac. Visual Studio communicates with a remote agent running on the Mac to transfer project files and execute build, deployment, and debugging commands. You can setup your Mac by following instructions Install And Configure Tools to Build using iOS.

Once the remote agent is running on the Mac and Visual Studio is paired to it, we can build and run the iOS app. In the Solution Platforms dropdown in Visual Studio, choose the right architecture for the iOS simulator (x86) or the iOS device. In Solution Explorer, open the context menu for the OpenGLESApp1.iOS.Application project and choose Build. Then choose iOS Simulator on the toolbar to run the app in the iOS Simulator on your Mac. You should see the same colored 3D spinning cube in the iOS Simulator.

This article Build an OpenGL ES Application on Android and iOS includes more details about the OpenGLES project.

Visual Studio to target all mobile platforms

If you’re building an app to target multiple mobile platforms (Android, iOS, UWP) and wish to share the common code in C++, you can achieve this by having one single Visual Studio solution and leverage the same code-authoring and debugging experience all in the same IDE. With Visual Studio, you can easily share and re-use your existing C++ libraries through the shared project component to target multiple platforms. The following screenshot shows a single solution with 4 projects, one for each mobile platform and one shared project for common C++ code.

To learn more, please refer to how Half Brick makers of popular mobile games Fruit Ninja and Jetpack Joyride use Visual Studio for a C++ cross-platform mobile development experience.

Write cross-platform C++ code with the full power of Visual Studio IDE

With Visual Studio, you can write cross-platform C++ code using the same powerful IntelliSense and code navigation features, making code writing much more efficient. These editing capabilities not only light up in the common code, but are context-aware of the target platform when you write platform-specific code.

Member list and Quick Info, as shown in the following screenshot, are just two examples of the IntelliSense features Visual Studio offers. Member list shows you a list of valid members from a type or namespace. Typing in “->” following an object instance in the C++ code will display a list of members, and you can insert the selected member into your code by pressing TAB, or by typing a space or a period. Quick Info displays the complete declaration for any identifier in your code. IntelliSense is implemented based on the Clang toolchain when targeting the Android platform. In the following screenshot, Visual Studio is showing a list of the available Android-specific functions when the Android Native Activity project is active.

Auto-complete, squiggles, reference highlighting, syntax colorization, code snippets are some of the other useful productivity features to be of great assistance in code writing and editing.

Navigating in large codebases and jumping between multiple code files can be a tiring task. Visual Studio offers many great code navigation features, including Go To Definition, Go To Line/Symbols/Members/Types, Find All References, View Call Hierarchy, Object Browser, and many more, to boost your productivity.

The Peek Definition feature, as shown in the following screenshot, brings the definition to the current code file, allows viewing and editing code without switching away from the code that you’re writing. You can find Peek Definition by opening the context menu on right click or shortcut Alt+F12 for a method that you want to explore. In the example in the screenshot, Visual Studio brings in the definition of __android_log_print method that is defined in the Android SDK log.h file as an embedded window into the current cpp file, making reading and writing Android code more efficiently.

Debug C++ code with the world-class Visual Studio debugger

Troubleshooting issues in the code can be time-consuming. Use the Visual Studio debugger to help find and fix issues faster. Set breakpoints in your Android C++ code and press F5 to launch the debugger. When the breakpoint is hit, you can watch the value of variables and complex expressions in the Autos and Watch windows as well as in the data tips on mouse hover, view the call stack in the Call Stack window, and step in and step out of the functions easily. In the example in the screenshot below, the Autos window is showing value changed in the Android sensorManager and accelerometerSensor types.

The Android debugging experience in Visual Studio also supports for debugging pre-built Android application via other IDE(s), other basic debugger capabilities (tracepoints, conditional breakpoints) and advanced features such as debugger visualizations (Natvis Support) and attaching to a running Android application as well.

You can find more information about the C++ debugger in this blog post C++ Debugging and Diagnostics.

Java debugging and language support for Android

Whether you’re writing Java or C++ code in your Android apps, Visual Studio has it covered. Visual Studio includes a Java Debugger that enables debugging Java source files in your Android projects, and with the Visual Studio Java Language Service for Android extension, you can also take advantage of the  IntelliSense and browsing capabilities for Java files in the Visual Studio IDE.

Editing Java code

First, install the Visual Studio Java Language Service for Android extension. It provides colorization (both syntactic and semantic), error and warning squiggles as well as code outlining and semantic highlighting in your Java files. You will also get IntelliSense assistance, such as Member List, Parameter Help, Quick Info, making writing Java code more efficient. In the following screenshot, Visual Studio provides a member list for the android.util.Log class.

Another handy feature for larger codebases or for navigating 3rd party libraries for which you have the source code available is Go to definition (F12) which will take you to the symbol definition location if available.

Debugging Java code

To turn on Java debugging for your Android projects in your next debugging session, in the Debug Target toolbar, change Debug Type dropdown to “Java Only” as shown in the following screenshot.

Now you can set line breakpoints, including conditions or hit counts for the breakpoints, anywhere in the Java code. When a breakpoint is hit, you can view variables in the Locals and Autos window, see call stack in the Call Stack window, and check log output in the Logcat window.

Blog post Java debugging and language support in Visual Studio for Android has more details on this topic.

Build Xamarin Android Native Applications

Xamarin is a popular cross-platform solution for creating rich native apps using C# across mobile platforms while maximizing code reuse. With Xamarin, you could create apps with native user interfaces and get native performance on each mobile platform. If you want to leverage Xamarin for writing user interfaces in C# while re-using your existing C/C++ libraries, Visual Studio fully supports building and debugging Xamarin Android apps that reference C++ code. This blog post Developing Xamarin Android Native Applications describes this scenario in more details.

Referencing C++ libraries in Xamarin iOS apps can be achieved by following this blog post Calling C/C++ libraries from Xamarin code.

Try out Visual Studio 2017 for mobile development with C++

Download Visual Studio 2017, try it out and share your feedback. For problems, let us know via the Report a Problem option in the upper right corner of the VS title bar. Track your feedback on the developer community portal. For suggestions, let us know through UserVoice.

blogs.msdn.microsoft.com

Top 10 reasons to use Visual Studio for C++ Android Development!

Visual Studio: C++ cross-platform mobile solution

Visual Studio (download here) is fast becoming a cross-platform C++ IDE. Our vision is for Visual Studio to become the IDE of choice for your cross-platform C++ code whether you are targeting, Windows (UWP), Android, iOS, Linux, Xbox, PlayStation, Marmalade or more. In the past year or so, we have enabled support for Android, iOS (in preview) targeting, improved integration with the popular cross-platform game engine Marmalade, introduced a new compiler toolset (Clang/C2) for improving code portability between Windows and non-Windows platforms. If you talk about the Android platform specifically which is what this post is really about, typically the use of C++ is common for applications which are computationally intensive such as games and physics simulations but many applications today are using C++ for its cross-platform nature to author a part or entirety of their application.

There are many examples of this phenomenon which is especially common for more sophisticated development shops out there.  Platform defining, cross-platform, new trendy applications such as Facebook Moments, Dropbox, Office, Skype, popular games (e.g. Fruit Ninja, Clash of Clans, EA Sports titles) are all written in cross-platform C++.  Talking more numbers if you take a look at the top 50 android applications a vast chunk of them (~75%) of them leverage C++. In today’s cross-platform world, if you want to optimize for fast iteration, app performance, and native look and feel. After weighing the alternatives out there most of these top development firms choose to write their UI in platform-specific code and the business logic in shared code using C++. 

With this in mind the native Visual Studio Android experience was released in early 2015 last year, and we have had pretty good reception and feedback from our customers. To provide you some highlights, our customers include Halfbrick Studios (makers of popular games such as Fruit Ninja, Jet Pack Joyride), Electronic Arts, Synergex, Autodesk and almost all internal Microsoft products such as Office, Bing, Minecraft, Hyperlapse and more. 

          Popular game Fruit Ninja building with Visual Studio Android development experience

 So here are top ten reasons (in no particular order) on why Visual Studio is the right choice for your C++ Android development:

  1.  Easily acquire all your Android platform needs  2.  Jump start your Android development with  C++ cross-platform templates and samples  3.  One C++ IDE to target all mobile platforms  (iOS, Android, Windows and more)  4.  Leverage powerful cross-platform coding tools   5.  Share your cross-platform C++ code easily  6.  Fastest C++ builds with Incredibuild support   7.  The fastest and most robust debugging experience for your Android application  8.  Leverage the best in Breed, free Android Emulator   9.  Gather your application insights easily using HockeyApp 10.  Visual Studio is the cross-platform mobile solution (Xamarin, Apache Cordova) and just not limited to cross-platform C++

Now that you have a rough overview, Let’s learn more about them in detail.Top 10 reasons to use Visual Studio for C++ Android Development

#1. Easily acquire all your Android platform needsVisual Studio acts as your one-stop shop for all your C++ Android development needs. This includes Android Development Kits (SDK, NDK), Apache Ant, Oracle Java JDK, Microsoft Android Emulator and the templates, samples we provide for providing you a quick start. In addition to this with the new live update mechanism in Visual Studio allows us to update your Android development environment on the fly as Google provides updates or we introduce new features for an improved development experience. 

    

#2. Jump start your Android development with  C++ cross-platform templates and samplesVisual Studio gives you a head start by providing you a variety of templates and samples out-of-the-box. The templates provided today demonstrate how to build an Android Native Activity application, Android Java Native Interface (JNI) application, an Android application with C++ shared code also building an iOS and Windows application and more. 

The Visual Studio Android samples today provide the NDK samples ported over to build and operate in Visual Studio. In the future we plan to also introduce other templates and samples for popular cross-platform C++ technologies and game-engines as well.

 #3. One C++ IDE to target all mobile platformsIn addition to Android, Visual Studio also provides support for writing Windows and iOS applications. Developers can build for all these platforms using a single solution file, leverage the same world class code-authoring and debugging experience all within Visual Studio.

 

#4. Leverage powerful cross-platform coding tools Visual Studio offers a rich coding experience for Android developers, whether they are authoring Java or C++ code. Yes! Visual Studio 2015 recently also introduced support for Java primarily to support Android developers who have a lot of C++ code but also have some Java code and had to use other editors for this portion of the code-base.

While the Java language service experience is still in it’s preview it provides a basic code-navigation and intellisense experience, here is a short video which provides an overview on how this experience plays out today. The C++ coding experience is complete and offers services for code-navigation, intellisense and even advanced refactoring features. All in all Visual Studio is a one-stop shop for a complete Android coding experience.

    

   

#5. Share your cross-platform C++ code easilyVisual Studio is a platform and in addition to Android development also allows for developing applications for iOS, Linux, Windows, Xbox, PlayStation and more. If you are currently working on a cross-platform application with a major chunk of code in C++ and frustrated with the use of multiple IDE’s, toolchains, debuggers, build systems using Visual Studio is worth a shot. With using Visual Studio you can easily share and re-use your existing C++ source through our shared project component and ability to target multiple platforms.

To learn more, please refer how Half Brick makers of popular mobile games Fruit Ninja and Jetpack Joyride use Visual Studio for a C++ cross-platform mobile development experience. 

 #6. World Class Android Native Application debugging experienceWe started working on developing an Android development experience primarily to support internal Microsoft teams such as Office, Bing, Skype, Minecraft and others as at the time the Android development experience for C++ application was pretty tribal. Working with these large scale applications provided us the opportunity to fine tune for scalability, correctness and speed when debugging C++ code, we performed multiple optimizations to the GDB back-end debugger to make this possible. Furthermore the Android debugging experience in Visual Studio, is not limited to C++ and also supports Java debugging (here’s a short video which illustrates the newly enabled Java debugging experience).

The debugging experience today in Visual Studio also supports for debugging pre-built Android application via other IDE(s), other basic debugger capabilities (Breakpoints, stepping, watch, tracepoints, conditional breakpoints) and advanced features such as debugger visualizations (Natvis Support) and attaching to a running Android application as well! 

 #7. Fastest C/C++ Android Application buildsMicrosoft Visual Studio partners with Xoreax Incredibuild to provide the fastest build experience out-of-the-box when you are building on your local machine by building parallelized build plans, performing dynamic resource management and providing a slew of diagnostic tools to understand and trouble shoot bottlenecks (Yes! All this is free). In addition to this by leveraging Incredibuild paid SKU developers can also set-up other accelerator agents to achieve multi-x build improvements over a distributed network. Here is an example below, of building the popular open-source ACE benchmark (Incredibuild enabled).

Natively the Visual Studio solution today supports Ant, Gradle and CMake. Support for Gradle was recently introduced in our latest offering.   

#8. Deploy, test and debug Android Applications with fast, free and best-of-breed Android emulatorThe Visual Studio Android development experience comes boxed with Microsoft’s very own emulator for Android for a fast edit-build-debug cycle. The Visual Studio Microsoft Android  emulator is Fast, x86, Hyper-V based  and provides support for simulating a range of sensors including accelerometer, screen orientation, SD card, battery, multi-touch, GPS, camera, audio and more!

#9.  Gather your application insights easily using HockeyApp Distribute your apps to testers through the web, allowing them to receive updates as they become available. Receive early feedback to make customer driven enhancements. Also gain insights from crashes to continuously improve the quality of your apps using HockeyApp.

#10. Visual Studio is the cross-platform mobile solution (Xamarin, Apache Cordova) and just not limited to cross-platform C++While C++ might be the right way to go for your current application, you might consider other popular cross-platform mobile technologies for your other offerings. Don’t worry Visual Studio cross-platform support is not limited to C++ but also extends to other popular cross-platform mobile development technologies such as Xamarin which allows development of rich native apps using C#, hybrid apps with JavaScript using Apache Cordova and build 2D, 3D games using Unity in Visual Studio.  

 

So download Visual Studio now and try out our C++ Android experience. We as a part of the Visual Studio development team believe this is the best solution for Android C++ applications and would love to know why would you choose any other solution out there. So reach out to us or leave us comments here to let us know what we are missing! For more news about Visual C++ please reach out to us at VCBlog.

blogs.msdn.microsoft.com

Using Visual Studio to Develop Native Android Code

This tutorial shows how to build and debug a simple Android App with a native library with Visual Studio.

Before you begin, please install VisualGDB (ensure that “Android Edition” is checked in the installer).

You will also need to install Java JDK, Android SDK, NDK and Apache ANT.

Step-by-step tutorial

  1. Start Visual Studio. Select File->New project->VisualGDB->Android App Wizard.
  2. Specify your project name and location (please avoid spaces in file path). Press OK to start the wizard.
  3. If you are running VisualGDB Android wizard for the first time, please press the “Configure NDK/SDK locations” button to tell VisualGDB the locations of your Android-related tools. If you don’t have any of the tools installed, simply press the “install” button.WARNING! After installing Android SDK please run the SDK manager as Administrator and install the Tools (SDK tools/Platform tools) and all required Android APIs (at least Android 1.5 and  2.3.3).
  4. In this tutorial we’ll go the easiest way and simply create a new application from scratch. To do it, please select the first option in the wizard:
  5. On the next page you can customize the project name or leave the default names.
  6. Finally you can select the Android platform. If you see not platforms in the list, please press the “Manage installed platforms” button and install the required platforms. Please select “Android 1.5″ as the app platform.
  7. When you press “Finish”, VisualGDB will create a new Android App project for you. If you have an Android phone or a tablet, you can enable USB debugging on it and connect it to your PC. If not, please start the Android simulator (AVD Manager) by selecting “Android->AVD Manager” in Visual Studio:
  8. If you have no virtual devices defined by now, please create one. It is recommended to specify at least Android 2.3.3 as the simulator platform:
  9. Start the virtual device. While it is booting, go to Visual Studio, set a breakpoint on the sprintf() line inside the main C file and and select Build->Build Solution.
  10. Once the solution has been built, please ensure that the virtual Android device has been started.
  11. Once the device is ready, press F5 to start debugging. VisualGDB will deploy the APK file automatically and will start a debugging session.
  12. Please go to the simulator and click on the huge full-screen button.
  13. Clicking the button will trigger the sprintf() breakpoint in Visual Studio:
  14. Hover the mouse over s_ButtonPressCounter, click on “0”, change the value to “123” and press ENTER.
  15. Press F5 to continue running the app. Go back to the simulator and ensure that the label indicates 123 hits.
  16. Have a look through the main debugging windows provided by VisualGDB using the Debug->Windows command:
    • The GDB Session window allows sending arbitrary commands to the GDB debugger
    • The Android LogCat window shows additional logging information provided by Android
    • The GDBServer Console window shows various NDK debugging information.
  17. Press Shift+F5 to stop debugging.
  18. As VisualGDB uses the Android NDK build system in the background, you can modify various build flags and settings by editing the Android.mk file. Note that VisualGDB will automatically update the LOCAL_SRC_FILES for you when you add/remove source files in the solution:

Now that you have managed to debug a basic project, you can follow the tutorials below for more advanced examples:

visualgdb.com

Visual Studio Emulator for Android

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

For the latest documentation on Visual Studio 2017, see Visual Studio Emulator for Android on docs.microsoft.com. The Visual Studio Emulator for Android is a desktop application that emulates an Android device. It provides a virtualized environment in which you can debug and test Android apps without a physical device. It also provides an isolated environment for your application prototypes.

The Visual Studio Emulator for Android is designed to provide comparable performance to an actual device. Before you publish your app, however, we recommend that you test your app on a physical device.

You can test your app on a unique device profile for each of the Android platforms, screen resolutions, and other hardware properties supported by Visual Studio Emulator for Android.

This topic contains the following sections.

Installing

Visual Studio Emulator for Android is a component of the cross-platform tools available in Visual Studio and will be installed during a custom Visual Studio setup when you select Cross-Platform Mobile Development, then Common Tools and Software Development Kits, and then Visual Studio Emulator for Android.

Uninstalling

You can uninstall the Visual Studio Emulator for Android using Add/Remove Programs in the Control Panel.

 Note

Uninstalling Visual Studio will not uninstall the emulator. You must uninstall the emulator separately.

When you uninstall the Visual Studio Emulator for Android, the Hyper-V Virtual Ethernet Adapters that were created for the emulator to use are not automatically removed. You can manually remove these virtual adapters (if not in use) by opening Hyper-V Manager, selecting one of the emulator VHD images, choosing the Networking tab, and choosing Remove for each of the switches that appears in this tab.

For important info about the hardware, software, and configuration requirements for Visual Studio Emulator for Android, see the following topic.

Visual Studio Emulator for Android requires Visual Studio 2015; it is not backward compatible with earlier versions of Visual Studio.

New versions of the emulator are installed on top of old versions (and may, in some cases, replace the old images, discarding the settings, apps, and files installed on those images).

The networking connection of the Visual Studio Emulator for Android behaves like the connection of a desktop computer with these characteristics:

  • The emulator appears on the network as a separate device with its own IP address.

  • It does not require any additional networking software that is not already installed with the emulator.

  • It is not joined to a Windows domain.

To understand the capabilities of the emulator's network connection, think of it as similar to a Wi-Fi connection from your Android phone to the same network. If an app running on your phone can access a network resource over its Wi-Fi connection, then an app running on the emulator can also access the same network resource.

For more info on network requirements, see System Requirements for the Visual Studio Emulator for Android

For info on troubleshooting networking issues, see Troubleshooting the Visual Studio Emulator for Android.

Testing your Android app for compatibility across the staggering variety of Android hardware can be a challenge. Android phones and tablets in the market span a wide range of versions and screen sizes and come in many different hardware configurations (RAM, CPUs, architecture, etc.). The Visual Studio Emulator for Android simplifies this using device profiles. Our set of device profiles represent the most popular hardware in the market, including devices from Samsung, Motorola, Sony, LG, and more.

In Visual Studio 2015, you can install, uninstall, and start device profiles using the Emulator Manager. Access the Emulator Manager by choosing Tools, then Visual Studio Emulator for Android.

By default, there are four pre-installed device profiles (KitKat and Lollipop phone/5" and tablet/7" configurations), as indicated by the white text and icons. Other profiles in the list will appear grayed out until you choose the Install Profile button and the installation completes. You can filter the list by API Level and click the details arrow on the bottom right-hand side of a profile to view its full configuration details.

Once you've installed the set of profiles that you'd like to target, you can start these new profiles directly from the manager by pressing the green Play button. They will also appear in the debug target dropdown menu in any Visual Studio cross-platform mobile project type.

For detailed information on features you can test in the emulator, see this documentation.

The following list describes features of the Android platform that you cannot test in the emulator. You have to test these features on a physical device.

If your host computer meets the system requirements and you encounter an issue not covered in this troubleshooting guide:

  • Ask a question on StackOverflow using the android-emulator and the visual-studio tag.

  • Report an issue using the Send a Smile tool in Visual Studio or in the Emulator Manager.

System Requirements for the Visual Studio Emulator for AndroidTroubleshooting the Visual Studio Emulator for Android

msdn.microsoft.com

Build your Android applications in Visual Studio using Gradle

This blog post is going to talk about how you can use Gradle to build Android libraries (.AAR) and APK’s and leverage Maven dependencies all in Visual Studio so let’s get started! If you are new to Gradle, then take a look at the gradle overview page and the User Guide.

Gradle has really been the default build system for Android for quite some time and Android developers have slowly but surely been moving to Gradle. Gradle provides flexibility as well as the ability to define common standards for Android builds. Gradle allows Android developers to use a simple, declarative DSL to configure Gradle builds supporting a wide variety of Android devices and App stores.

With a simple, declarative Domain specific language (DSL), Gradle developers can easily describe and manipulate the build logic (e.g. manifest entries – minSDKVersion, targetSDKVersion etc.), use the built-in dependency management via Maven or Ivy and essentially have access to a single, authoritative build that powers both the Android Studio IDE and builds from the command-line but this ability to use Gradle in Visual Studio has been missing until recently.

Getting Started With the latest Visual Studio release, if you take a look at the cross-platform C++ section in the File->New project template section, you will see a variety of templates as shown in the figure below. Notice two new Gradle templates that have been introduced.  

‘Basic Android Application (Android, Gradle)’, template as the name suggests will build an E2E android application (.APK) and the ‘Basic Library (Android, Gradle)’ template will build an AAR file also known as an Android artifact. For traditional Java users, AAR’s are similar to Jar files with the main difference being AAR files include resources such as layouts, drawables etc. This makes it a lot easier to create self-contained visual components.  For e.g. if you have multiple apps that use the same login screen, with jar’s you can share classes but not the layout itself. With AAR’s everything is bundled into one package. With that said, let us now take a look at structure of a basic Android application.

Understanding the Gradle artifacts  As you create a new project from template, you will notice the top-level build.gradle file, located in the root project directory, defines build configurations that apply to all modules in your project. By default, the top-level build file uses the buildscript {} block to define the Gradle repositories and dependencies that are common to all modules in the project. The following code sample describes the default settings and DSL elements you can find in the top-level build.gradle.template after creating a new project.For this project, the repositories section declares the jCenter and mavenCentral repositories, and we have also introduced a classpath dependency on a Maven artifact. This artifact is the library that contains the Android plugin for Gradle version specified in the property pages (figure below).

The module-level build.gradle.template file, located in the ‘app’ directory will allow you to configure build settings for the specific module it is located in. One thing special about this particular specific build.gradle.template file is the fact that it is based upon the experimental plugin (0.4.0) which allows for significant time reduction in configuration time. In addition to this, this experimental plugin also allows for integration with NDK and CMake build system which is important if your application contains C++ code.

A sample Android app module build.gradle.template file when using the experimental plugin outlines some of the basic DSL elements.

The apply plugin: ‘com.android.model.$(ConfigurationType)’ command specifies the kind of artifact being built. You can either set this to an application for building an .APK or a library for building an .AAR file. This configuration type can be controlled via the property pages ‘Configuration Type’ property .

The plugin name used by the experimental plugin is different than the standard plugin name ‘com.android.application’ for building an Android APK or ‘com.android.library’ in case you are building an Android aar library.

The next section in the module-specific ‘build.gradle.template’ file is the model section. The model section wraps the configuration. The Android closure is the standard way used for wrapping the SDK version used for compiling, minimum SDK version supported and more.

The next section ‘compileOptions’ allows for choosing the language level used by the compiler.

The android.buildTypes section creates a debug and release build type  for this application. Although the debug build type doesn’t appear in the build configuration file; it gets configured when the debuggable property is set to true. This allows for debugging the application on secure Android devices and configures APK signing with a default generic keystore.

The last section in the model enclosure is productFlavors. A product flavor defines a customized version of the application build by the project. A single project can have different flavors which change the generated application. Since this particular build.gradle is tailored for an NDK android application the abiFilters.add allows for building one APK per architecture easily.

The last section in this build.gradle.template file is the dependencies section. There are three kinds of dependencies, and you can find what each kind does here on the Android documentation site. This particular build.gradle.template only defines the compile.filetree dependency as shown below. The ${AarDependencies) is an addition by us which allows easy Visual Studio project referencing.

The compile fileTree(dir: ‘libs’, include: [‘*.jar’]) line tells the build system to include any JAR files inside the app/libs/ directory in the compilation classpath and in the final package of your application.

The other Gradle files that are included as the part of your project is the settings.gradle.template file. This file references all the modules that make up your project.

include ‘:app’ $(AarDependenciesSettings)

Using the NDK integration   Using the NDK integration with Gradle in Visual Studio is easy. Typically you would need to add the ndk {} section in your model section for your module specific build.gradle.template file and potentially also use the android.sources section to provide JNI source set as specified in the android documentation  but  in Visual Studio in order to incorporate a native C/C++ component all you need to do is create a new native component through the Cross-Platform – Android section  and then add it via the typical project reference from the Gradle project as shown below. Visual Studio will automatically take care of packaging your native library in the Android application you are building.

Alternatively you can also use the standard approach for including JNI sources using the experimental Gradle plugin as well if that works out better for you. Google provides a good list of samples for Android NDK and Gradle in this repository. With minor changes, mainly involving copying over contents from the ‘build.gradle’ -> ‘build.gradle.template’ files , those samples would work for you in Visual Studio. We are currently in the process of making this process happen automatically by providing you folks with an Android Studio -> Visual Studio Android project converter. If this converter really interests you please leave your contact information here or reach out to me.

Referencing Android libraries in your Android project    Generally, Android applications built in Visual Studio mainly use C++. Every now and then even for these C++ heavy applications there can be a need to include Android libraries such as AARs and JARs into your Android application. These could be homegrown Android artifacts built for the purposes of sharing common code, assets and utilities.

With this release of Visual Studio, we have made the process really easy for you to do that as well. In order to create and reference an AAR file you can simply do so by creating a new AAR from the File->New project menu (Basic Library (Android, Gradle)) and then include it in your Android application by adding it through a project reference as shown in the figure below.

An example: Incorporating the Facebook SDK in your Android appNow that we have a basic understanding of how the Gradle build system works, lets now go ahead and show off the real power of the build system. As mentioned earlier, Gradle makes it simple to integrate with external repositories. In order to leverage the Facebook SDK (instructions here) all one has to do is use the compile dependency command in the module specific build.gradle.template file and add the following line (given that we have already specified mavenCentral() and JCenter() repositories in the root build.gradle file).

compile ‘com.facebook.android:facebook-android-sdk:4.7.+’

This command declares a remote binary dependency on the version 4.7 and  above for the Facebook SDK. At build time Gradle will now automatically pull the dependency from the jCenter repository specified in the top-level build.gradle.template file.

This mechanism not only allows you to specify and incorporate the Facebook SDK as a build time artifact but also allows Visual Studio to power the Java language service experience with features like Intellisense extending their functionality for the Facebook SDK set of API(s) as well as shown  in the figure below!

Wrap Up   This summarizes the current support for building Android applications with Gradle for Visual Studio 2015 Update 3. We look forward to you trying out these new features and sharing your feedback either through Send-A-Smile/Frown (use #cpp2015), Connect, User Voice or down below in the comments.

blogs.msdn.microsoft.com

Android Studio

ON THIS PAGE we will show you how to clone your Visual Studio Team Services (VSTS) Git repository (repo) and create pull requests all from within Android Studio. ASSUMPTIONS

  • You have read the Create Git Repo Page and performed the steps on that page to create a VSTS project and Git repository for the DeepSpace sample code.
  • You have Android Studio installed on your machine (if not, download Android Studio).

Android Studio is the official IDE for Android app development, based on IntelliJ IDEA. You can find out more about it at http://developer.android.com/tools/studio/index.html. The Visual Studio Team Services Plugin for Android Studio allows you to connect to your Git repositories on Visual Studio Team Services (VSTS) and Team Foundation Server (TFS) in a seamless and intuitive way. You can also use this plugin to import your android development projects into VSTS or create pull requests in your VSTS/TFS Git repository.

Installing the Team Services Plugin for Android Studio

See the Android Studio Plugin download page for instructions on downloading and installing the plugin.

The plugin is compatible with Android Studio version 1.2 and higher.

Cloning your repo in Android Studio

To clone your VSTS repo in Android Studio is extremely simple. You don't even need to know the URL for the repo. Simply open Android Studio and select Check out from Version Control and then choose "Team Foundation Git".

Next just sign in to VSTS...

When you click "Sign in", you will be presented with the standard VSTS sign in UI. Once signed in, you should see the list of all repositories you have access to on VSTS. Simply choose the correct repo, DeepSpace, and click the Clone button. (You may also want to choose where on your hard drive the repo is cloned to by changing the Parent Directory.)

After the clone finishes, Android Studio will ask you if you want to open the project. Click "Yes" and you should end up with the DeepSpace project opened in Android Studio.

Making some changes in Android Studio

Start by making sure the project builds using Build->Make project. If you are prompted to add an SDK for the project, simply add the latest Java JDK installed on your machine. If you want to run the project now to see what it does, you can do the following:

  • from the DeepSpace root folder in your git repo, run the command "mvn jetty:run" (this requires maven to be installed)
  • from a browser, go to http://localhost:3030/ You should see stars and planets flying by! If you look closely, you may notice that Earth does not fly by.

In our DeepSpace example, there are some code sections that have been commented out. If you open the src/main/java/com.microsoft.tfs.demo/ImageService.java file in Android Studio, you can see one of the sections.

Let's fix this section of code locally. Typically, when working in a Git repo, you should create a branch for your work and commit to that branch. You can create a branch through Android Studio using the built-in VCS->Git->Branches window. When prompted, use the branch name "fixBugs".

Once we have a branch to make our changes in, we can uncomment the code and rebuild the project. If you follow the instructions above to run the program again, you should see the Earth fly by. Now that our changes are built and tested, we can commit them locally using the VCS->Commit Changes menu. In the commit dialog, you will see a Team Services button above the commit message text box. Click on that button to view your list of work items assigned to you. Select the "Add Missing Earth" work item and click OK. You will see the commit message text box populate with the work item's type, number, and title. This will associate the work item to this commit for traceability in the future.

This change is only done locally; it hasn't been changed in our Team Services repo yet.

Creating a Pull Request

You can push your local branch to the server and create a pull request for your team to review. Our plugin helps you create the pull request based on your current context within Android Studio. This saves you several steps and eliminates the need for you to switch to your browser to create the pull request.

To accomplish this, simply select VCS->Git->Create Pull Request or Version Control tool window -> Pull Requests tab -> + button. This will open up the "Create Pull Request" dialog. This dialog provides a lot of information including the files that have changed and the commits that will be pushed. You can give the pull request a title and a description.

After you click "Create Pull Request", you should receive a notification that the pull request was created. It also contains a link to the pull request in case you want to add specific reviewers or comments. Once the code reviews are done, you can merge the pull request into master.

Checking Build Status

After you have merged your changes into master, you can check if your CI build has succeeded from within Android Studio. In the bottom right corner, there is an icon that displays your build status to you. If you see a green checkmark, that means your build has succeeded. If you see a red X, then your build failed. If you see a gray question mark, your build was not found or your credentials may have expired.

You can click on the icon for more options such as viewing build details, queuing a new build, and updating the status manually.

View Pull Requests and Work Items

Under the Version Control menu, a Pull Request tab and Work Items tab exist to allow you to easily view the information you need without leaving the IDE. The Pull Request tab shows you the current pull requests created by you and assigned to you along with their status. The tab also gives you the ability to create and/or abandon pull requests.

Under the Work Items tab, you can view the work items based on queries that you have created or use the default query to see work items that are assigned to you. You can also create a branch based off of a work item so that you can associate a work item with branch for future traceability purposes.

TFVC Support

TFVC support is also available in the plugin. The current features supported are:

  • Checkout a TFVC repository from Team Services or Team Foundation Server 2015+.
  • Execute all basic version control actions such as add, delete, rename, move, etc.
  • View local changes, server changes, and history for your files.
  • Create, manage, and edit your workspaces.
  • Checkin and update local files.
  • Merge conflicts from updates.
  • Create and merge branches.
  • Create labels.
  • Lock and unlock files and directories.
  • Associate work items with checkins.
  • Supports using a TFS proxy.
  • Local workspace support only.

The TFVC functionality is available from the VCS dropdown menu in the toolbar or from right clicking in the Project window. A TFVC menu item will display the options available for you to use. A demo of the TFVC features can be found here.

TFVC Setup Requirements

You must have the TF command line tool installed to be able to use TFVC features. The minimum version supported by the plugin is 14.0.3. To install the tool, download the latest "TEE-CLC-14.*.*.zip" file and extract it to a known location. After extracting the files, you must accept the license agreement. To do so, open a Command Prompt/Terminal window, navigate to the extracted directory, and run tf eula. After reading the EULA, enter y to accept it. NOTE: If you forget to do this, the plugin may fail to load with a RuntimeException.

For the tool to be detected by the plugin, you must set the location of the executable in the Settings/Preferences menu by following these instructions:

  1. Go to File then Settings in the toolbar for Windows and Linux. For Mac, go to Android Studio then Preferences.
  2. Choose Version Control from the left menu then TFVC.
  3. In the Path to tf executable text field, navigate to the location of the tf executable.
  4. Click Test to test that the executable has been found and is working as expected.
  5. Click Apply then OK to save and exit.

If you intend to use the tf tools from the command line, you may want to add this folder to your PATH environment variable as well.

If you do not want to get prompted to enter your credentials for each tf command that you run, set the TF_AUTO_SAVE_CREDENTIALS environment variable to 1.

Setting TFVC as the Version Control System

If TFVC does not come up as your version control system (VCS) then it can be set manually. Go to the VCS dropdown menu in the toolbar and select Enable Version Control Integration. Select TFVC from the dropdown menu and click OK.

Using existing workspaces created by Visual Studio

Initially, Android Studio cannot detect workspaces created by Visual Studio. To get a workspace to be recognized, you must use the TF Command Line tool. Run tf workspaces -collection:<collection-url> where the collection URL is the one associated with the workspace you are using.

Next Steps

Watch our end-to-end tutorial on how to incorporate the various plugin features into your development routine to make working with Team Services even easier.

Frequently Asked Questions (FAQ)

Q: Where can I learn more about installing the Android Studio plugin?

A: Watch a how-to video on installing the plugin on our YouTube channel.

Q: How can I import my Android Studio project into Visual Studio Team Services?

A: Watch a how-to video on importing projects on our YouTube channel.

Q: How can I checkout a Visual Studio Team Services Git repo from within Android Studio?

A: Watch a how-to video on checking out projects on our YouTube channel.

Q: How can I create a pull request using the Android Studio plugin?

A: Watch a how-to video on pull requests on our YouTube channel.

Q: Where can I learn more about the Team Services Pull Request feature?

A: This Conduct a Git pull request article provides more details.

Q: What if I can't see any repositories after signing in?

A: In some rare cases, the list of repositories is empty after signing in with your Visual Studio Team Services account. If that happens, you can click the Team Foundation Server tab and enter the URL to your Team Services account in the Server URL textbox and then click Connect. If you don't know the URL to your Team Services account, the Team Services accounts you have access to will be listed at https://app.vssps.visualstudio.com.

Q: When I test the tf executable, I get a warning that the version detected is 0.0.0. How can I make it detect the actual version?

A: This has been seen in version 14.0.3 and below of the TF Comand Line Tool when it defaults to not use English for the output. This has been fixed in the newer versions of the tool which can be downloaded from GitHub.

Q: How do I collect logs to help troubleshoot an issue?

A: First enable logging for com.microsoft.alm, reproduce the issue and send us the idea.log file:

  1. Help->Configure Debug Log Settings...
  2. In the Custom Debug Log Configuration textbox, add the following on its own line: com.microsoft.alm
  3. Click OK
  4. Try to reproduce the issue you encountered.
  5. Help->Show Log in Finder/Explorer/File Manager
  6. The file idea.log should be highlighted. You can open it with a text editor to review its contents for sensitive information and to make sure there are entries containing microsoft.
  7. Compress the file.
  8. Create a GitHub issue and attach the file to it.

Last updated on 03/07/2017

java.visualstudio.com

System Requirements for the Visual Studio Emulator for Android

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

For the latest documentation on Visual Studio 2017, see System Requirements for the Visual Studio Emulator for Android on docs.microsoft.com. Visual Studio Emulator for Android runs as a virtual machine on Hyper-V, the virtualization technology for Windows 8 and later versions. To run the emulator, your computer must meet the requirements to run Hyper-V as described in this topic.

The setup program tries to configure these prerequisites for you silently when you install the emulator. When setup successfully configures the prerequisites, the emulator simply works as expected. Otherwise you may have to enable these prerequisites manually. If you have to configure the prerequisites manually, the steps and tools are the same steps described here for the Windows Phone Emulator.

 Important

The setup program for the emulator checks the prerequisites for running Visual Studio Emulator for Android. It displays warnings if the prerequisites are not present, but it does not require them.

This topic contains the following sections.

Here is a quick checklist of the requirements for running the Visual Studio Emulator for Android. For more detailed info, see the subsequent sections in this topic.

System requirements

  • Hyper-V support (see Hyper-V requirements below)

  • 6 GB or more of RAM.

  • 64-bit version of the Pro edition of Windows 8, Windows 8.1, Windows10 or higher

  • A processor that supports SSSE3 or later.

Network requirements

Hyper-V requirements

  • In the BIOS, the following features must be supported:

    • Hardware-assisted virtualization

    • Second Level Address Translation (SLAT)

    • Hardware-based Data Execution Prevention (DEP)

  • In Windows, Hyper-V must be enabled and running.

  • You have to be a member of the local Hyper-V Administrators group.

Your computer must meet the following requirements:

  • Hyper-V support (see Hyper-V requirements)

  • 6 GB or more of RAM.

  • 64-bit version of the Pro edition of Windows 8, Windows 8.1, Windows10 or higher.

To check requirements for RAM and Windows, in Control Panel, choose System and Security, and then choose System.

Your network must meet the following requirements:

  • DHCP

    The emulator requires DHCP because it configures itself as a separate device on the network with its own IP address.

  • Automatically configured DNS and gateway settings

    It’s not possible to configure DNS and gateway settings manually for the emulator.

To troubleshoot networking issues in the emulator, see the following topics:

Hyper-V requirements in the BIOS

Your computer’s BIOS must support the following requirements, and they must be enabled:

  • Hardware-assisted virtualization

  • Second Level Address Translation (SLAT)

  • Hardware-based Data Execution Prevention (DEP)

Hyper-V requirements in Windows

When your computer and BIOS settings are already configured to support Hyper-V, the setup program enables and starts Hyper-V. Otherwise you may have to enable these requirements manually.

You have to be a member of the local Hyper-V Administrators group.

To run the Visual Studio Emulator for Android without a recurring prompt to elevate your rights, you have to be a member of the local Hyper-V Administrators group. If you are already a local administrator on the computer when you install the SDK, the setup program for the SDK adds you to the Hyper-V Administrators group. Otherwise you may have to enable this requirement manually.

When you run the emulator, if you are not already a member of the Hyper-V Administrators group, you are prompted to join the group (the dialog box refers to the Windows Phone emulator). Joining the group requires administrator rights.

 Important

After you join the group, log off or reboot to make the change take effect.

To add yourself to a group manually, open the Local Users and Groups snap-in. For more information, see Add a user account to a group. (This Windows 7 topic is also applicable to Windows 8.)

If you try to run an app on the Visual Studio Emulator for Android while you are running Windows from a bootable VHD, the emulator typically takes several minutes to start or fails to start. When the emulator fails to start, you see the following message: App deployment failed. Please try again.

This configuration is not supported. For information about related issues, see Troubleshooting the Visual Studio Emulator for Android.

On a hard drive configured with the NTFS file system, the virtual hard disk files used by Hyper-V must be uncompressed and unencrypted. Make sure that the following directories are not compressed or encrypted:

  • %localappdata%\Microsoft\XDE

  • C:\Program Files (x86)\Microsoft Emulator Manager

  • C:\Program Files (x86)\Microsoft Visual Studio Emulator for Android

  • %localappdata%\Microsoft\VisualStudioEmulator

On the ReFS file system, the virtual hard disk files must not have the integrity bit set.

In order for the emulator to emulate calls to the GPU, such as those used by OpenGL ES, your machine must have a DirectX compatible GPU with appropriate DirectX drivers installed.

Troubleshooting the Visual Studio Emulator for Android

msdn.microsoft.com


Смотрите также