{"id":69,"date":"2015-04-30T21:01:52","date_gmt":"2015-04-30T21:01:52","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=69"},"modified":"2015-04-30T21:01:52","modified_gmt":"2015-04-30T21:01:52","slug":"android","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/android\/","title":{"rendered":"Using Visual Studio to Develop Native Android Code"},"content":{"rendered":"\n<p>This tutorial shows how to build and debug a simple Android App with a native library with Visual Studio.<\/p>\n<p>Before you begin, please install <a href=\"\/download\"> VisualGDB<\/a> (ensure that &#8220;Android Edition&#8221; is checked in the installer).<\/p>\n<p>You will also need to install Java JDK, Android SDK, NDK and Apache ANT. <\/p>\n<h2>Step-by-step tutorial<\/h2>\n<ol>\n<li>Start Visual Studio. Select File-&gt;New project-&gt;VisualGDB-&gt;Android App Wizard.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/01-newprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/01-newprj.png\" alt=\"01-newprj\" width=\"700\" height=\"394\" \/><\/a><\/li>\n<li>Specify your project name and location (please avoid spaces in file path). Press OK to start the wizard.<\/li>\n<li>If you are running VisualGDB Android wizard for the first time, please press the &#8220;Configure NDK\/SDK locations&#8221; button to tell VisualGDB the locations of your Android-related tools. If you don&#8217;t have any of the tools installed, simply press the &#8220;install&#8221; button.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/02-android-tools.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/02-android-tools.png\" alt=\"02-android-tools\" width=\"640\" height=\"229\" \/><\/a><span class=\"warning\">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&nbsp; 2.3.3).<\/span><\/li>\n<li>In this tutorial we&#8217;ll go the easiest way and simply create a new application from scratch. To do it, please select the first option in the wizard: <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/03-newprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/03-newprj.png\" alt=\"03-newprj\" width=\"679\" height=\"634\" \/><\/a><\/li>\n<li>On the next page you can customize the project name or leave the default names.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/04-projname.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/04-projname.png\" alt=\"04-projname\" width=\"679\" height=\"634\" \/><\/a><\/li>\n<li>Finally you can select the Android platform. If you see not platforms in the list, please press the &#8220;Manage installed platforms&#8221; button and install the required platforms. Please select &#8220;Android 1.5&#8221; as the app platform. <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/05-platform.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/05-platform.png\" alt=\"05-platform\" width=\"679\" height=\"634\" \/><\/a><\/li>\n<li> When you press &#8220;Finish&#8221;, 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 &#8220;Android-&gt;AVD Manager&#8221; in Visual Studio:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/06-avd.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/06-avd.png\" alt=\"06-avd\" width=\"700\" height=\"647\" \/><\/a><\/li>\n<li> 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:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/07-newdev.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/07-newdev.png\" alt=\"07-newdev\" width=\"404\" height=\"647\" \/><\/a><\/li>\n<li> 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-&gt;Build Solution.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/08-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/08-build.png\" alt=\"08-build\" width=\"700\" height=\"644\" \/><\/a><\/li>\n<li> Once the solution has been built, please ensure that the virtual Android device has been started.<\/li>\n<li> Once the device is ready, press F5 to start debugging. VisualGDB will deploy the APK file automatically and will start a debugging session.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/09-install.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/09-install.png\" alt=\"09-install\" width=\"484\" height=\"358\" \/><\/a><\/li>\n<li> Please go to the simulator and click on the huge full-screen button.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/10-sim.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-10\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/10-sim.png\" alt=\"10-sim\" width=\"478\" height=\"428\" \/><\/a><\/li>\n<li> Clicking the button will trigger the sprintf() breakpoint in Visual Studio:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/11-breakpoint.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/11-breakpoint.png\" alt=\"11-breakpoint\" width=\"700\" height=\"644\" \/><\/a><\/li>\n<li> Hover the mouse over <strong>s_ButtonPressCounter<\/strong>, click on &#8220;0&#8221;, change the value to &#8220;123&#8221; and press ENTER.<\/li>\n<li> Press F5 to continue running the app. Go back to the simulator and ensure that the label indicates 123 hits.<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/12-123times.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-12\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/12-123times.png\" alt=\"12-123times\" width=\"478\" height=\"428\" \/><\/a><\/li>\n<li> Have a look through the main debugging windows provided by VisualGDB using the Debug-&gt;Windows command:\n<ul>\n<li>The <strong>GDB Session <\/strong>window allows sending arbitrary commands to the GDB debugger<\/li>\n<li>The <strong>Android LogCat<\/strong> window shows additional logging information provided by Android<\/li>\n<li>The <strong>GDBServer Console<\/strong> window shows various NDK debugging information.<\/li>\n<\/ul>\n<\/li>\n<p>\n      <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/13-windows.png\"><br \/>\n        <img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-13\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/13-windows.png\" alt=\"13-windows\" width=\"700\" height=\"647\" \/><br \/>\n      <\/a>\n    <\/p>\n<li> Press Shift+F5 to stop debugging.<\/li>\n<li> As VisualGDB uses the Android NDK build system in the background, you can modify various build flags and settings by editing the <strong>Android.mk<\/strong> file. Note that VisualGDB will automatically update the LOCAL_SRC_FILES for you when you add\/remove source files in the solution:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/14-makefile.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-14\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/14-makefile.png\" alt=\"14-makefile\" width=\"700\" height=\"644\" \/><\/a><\/li>\n<\/ol>\n<p>Now that you have managed to debug a basic project, you can follow the tutorials below for more advanced examples:<\/p>\n<ul>\n<li>\n      <a href=\"http:\/\/visualgdb.com\/tutorials\/android\/vs-android\/intellisense\/\">Configuring IntelliSense for a vs-android project<\/a>\n    <\/li>\n<li>\n      <a href=\"http:\/\/visualgdb.com\/tutorials\/android\/vs-android\/codemap\/\">Using Code Map to understand complex C++ Android code<\/a>\n    <\/li>\n<\/ul>\n<p><\/root><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to build and debug a simple Android App with a native library with Visual Studio. Before<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[31,32],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/69"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":0,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}