Debugging C++ Code on Android With Visual Studio 2015

Introduction

The Microsoft Visual Studio 2015 Preview has introduced some new features. One of them is the cross-platform application development. Cross-platform application development means we can write code in any language and run this code on our Visual Studio 2015. Cross-platform interoprability means to make a platform where we can run the code of any language on a single platform. Visual Studio 2015 introduces a cross-platform capability for C++ applications. In it we can make a C++ language based application in Visual Studio 2015 and run it on the Android Emulator. So here are the three things. One is C++, the second is Visual Studio and the third is the Android Emulator. All three of these work on a single platform. That platform is called cross-platform. So using all of these we can make a C++ application in Visual Studio 2015 Preview and run the application in the Android Emulator. A cross-platform application development environment is a very powerful tool provided by Microsoft for the Visual Studio 2015 Preview. Visual Studio 2015 has many new templates in the template field by which you can make a cross-platform application depending on your needs.

About C++

C++ is an object-oriented programming language designed by Bjarne Stroustrup in 1979. it was the first language introduced as an Object Oriented Programming language. In an Object Oriented Programming language programs get many new features. It provides code reuseability that is very important for the user. In the C++ there are many new features. These features are now known as Object-Oriented Programming. The features are:

  • Object
  • Class
  • Inheritance
  • Polymorphism
  • Abstraction
  • Encapsulation
  • Data Hiding
  • Message Passing
The following describes how to make an application using C++ in Visual Studio 2015 and debug it in the Android Emulator.

Step 1

Open Visual Studio 2015, create a new project, select the template field, select the template Visual C++, go to cross-platform and select it. Now you can see the five templates as in the following picture:



Step 2

Select the Native-Activity Application (Android ) Visual C++ that is present in the second row of your template field.



Step 3

When you click on the OK button then there are two main files generated in the Solution Explorer.




The first one is for Android 4. Native Activity Android 19 ) that contains the four files and folders.

The second one is for Android 4. The packaging that contains the five files and folders.

Step 4

Now first create an emulator for the Android application. To do that first go to the Visual Studio tools, select Android and select the Open Android Emulator Manager.

Now create the Android Virtual device like this.



Now start your emulator. When it is used the first time it takes time, so wait a while for this process.
Now your Android Emulator will start and it will look as in the following figure.



Step 5

After this in your Visual Studio menu option you can see something like this. The emulator comes automatically at the start up point, but it remembers that *86 was selected, not ARM from the drop down list.



Step 6

Then go to the Solution Explorer, select the Android 5.Native activity file. Right-click on it, go to its properties and save the properties like this.


Step 7

Now explore the Android 5.Native activity file so there you see some files.




Step 8

Now open the main.cpp file. In this file you will see the different function that are compiler generated/auto generated.
We insert some breakpoints in this code to debug this application. In this file we also write our code in C++.



Step 9

Now we go to the build solution, click on the build solution. If there is no error then in the output window we will see that the build was successful as in the following image.


Step 10

Go to debug, click the debug during this. The solution was built for the emulator so you will see a progress bar like this.



Step 11

On the breakpoints you will see some output like this.



Step 12

On every breakpoint you will see the information about the method or variable that you made on your project.



Step 13

Now go to the menu bar and click on continue, so you see your application in the emulator like this.



Now run this application so you will see the output. That has changed the color during a duration of some time. Sometimes it is Green and sometimes it is dark Green.



Summary: In this article we learn how Visual Studio works for cross-platform application. So this is an overall view of Debugging a C++ code in the Visual Studio 2015 by Android emulator. This is a very easy task because Visual Studio 2015 Preview already provides all the tools for it. That is very important to make a cross-platform application in Visual Studio. So I think. All of us do thank Microsoft for providing such a good platform to develop cross-platform applications and run them in the Android Emulator.


Similar Articles