{"id":443,"date":"2015-08-05T12:21:19","date_gmt":"2015-08-05T19:21:19","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=443"},"modified":"2015-12-24T18:58:11","modified_gmt":"2015-12-25T02:58:11","slug":"co-developing-android-projects-with-gradle-flavors-with-visual-studio","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/android\/astudio\/flavors\/","title":{"rendered":"Co-developing Android projects with Gradle Flavors with Visual Studio"},"content":{"rendered":"<p>This tutorial shows how to develop C\/C++ code in an Android Studio project using Visual Studio and VisualGDB. We will show how to use the Gradle flavors and translate them into Visual Studio configurations for better usability.<\/p>\n<p>Before you begin, install VisualGDB 5.0 or later and Android Studio 1.3 or later.<\/p>\n<ol>\n<li>Start Android Studio and click &#8220;Start a new Android Studio project&#8221;:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/01-newprj3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-444\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/01-newprj3.png\" alt=\"01-newprj\" width=\"679\" height=\"589\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/01-newprj3.png 679w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/01-newprj3-300x260.png 300w\" sizes=\"(max-width: 679px) 100vw, 679px\" \/><\/a><\/li>\n<li>Specify your app name and domain:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/02-appname.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-445\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/02-appname.png\" alt=\"02-appname\" width=\"488\" height=\"720\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/02-appname.png 488w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/02-appname-203x300.png 203w\" sizes=\"(max-width: 488px) 100vw, 488px\" \/><\/a><\/li>\n<li>Select the SDK you want to use with your app:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/03-formfactor.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-446\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/03-formfactor.png\" alt=\"03-formfactor\" width=\"488\" height=\"768\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/03-formfactor.png 488w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/03-formfactor-191x300.png 191w\" sizes=\"(max-width: 488px) 100vw, 488px\" \/><\/a><\/li>\n<li>Select the template for the first activity. In this tutorial we will use the Fullscreen Activity:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/04-fullscreen.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-447\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/04-fullscreen.png\" alt=\"04-fullscreen\" width=\"488\" height=\"768\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/04-fullscreen.png 488w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/04-fullscreen-191x300.png 191w\" sizes=\"(max-width: 488px) 100vw, 488px\" \/><\/a><\/li>\n<li>On the next page you can customize the activity names or proceed with the default ones:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/05-activity-detail.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-448\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/05-activity-detail.png\" alt=\"05-activity-detail\" width=\"502\" height=\"768\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/05-activity-detail.png 502w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/05-activity-detail-196x300.png 196w\" sizes=\"(max-width: 502px) 100vw, 502px\" \/><\/a><\/li>\n<li>Click Finish and wait until Android Studio finishes parsing your project:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/06-project.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-449\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/06-project.png\" alt=\"06-project\" width=\"990\" height=\"769\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/06-project.png 990w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/06-project-300x233.png 300w\" sizes=\"(max-width: 990px) 100vw, 990px\" \/><\/a><\/li>\n<li>Now we will add a native C file to our project. As of August 2015, Android Studio (v1.3) cannot build native code with debug support unless you use the experimental Gradle plugin. The experimental plugin, however, is not stable and is not backward compatible with the stable plugin, so in this tutorial we will use the Android NDK build system to build the native code with proper debug support. To do that, the jni directory with the native files should be located under the &#8220;app&#8221; directory and not in the location used by Gradle. To add the jni directory, first switch the project to the &#8220;Project&#8221; view:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/07-projectview.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-450\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/07-projectview.png\" alt=\"07-projectview\" width=\"990\" height=\"769\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/07-projectview.png 990w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/07-projectview-300x233.png 300w\" sizes=\"(max-width: 990px) 100vw, 990px\" \/><\/a><\/li>\n<li>Then click on the &#8220;app&#8221; folder and select &#8220;New-&gt;Directory&#8221; and enter the &#8220;jni&#8221; name:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/08-jni.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-451\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/08-jni.png\" alt=\"08-jni\" width=\"990\" height=\"769\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/08-jni.png 990w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/08-jni-300x233.png 300w\" sizes=\"(max-width: 990px) 100vw, 990px\" \/><\/a><\/li>\n<li>Add a new .c file called &#8220;hello&#8221; to the jni directory:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/09-helloc.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-452\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/09-helloc.png\" alt=\"09-helloc\" width=\"356\" height=\"184\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/09-helloc.png 356w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/09-helloc-300x155.png 300w\" sizes=\"(max-width: 356px) 100vw, 356px\" \/><\/a><\/li>\n<li>Add the following contents to the hello.c file:\n<pre class=\"\"><span class=\"auto-style4\"> <span class=\"keyword\">#include<\/span> <span class=\"string\">&lt;string.h&gt;<\/span>\r\n <span class=\"auto-style2\">#include <\/span> <span class=\"auto-style3\">&lt;jni.h&gt;\r\n <\/span><span class=\"auto-style2\">#include<\/span> <span class=\"auto-style3\">&lt;stdio.h&gt;\r\n <\/span> \r\n <span class=\"auto-style2\">int<\/span><\/span> <span class=\"auto-style4\">s_ButtonPressCounter = 0;\r\n \r\n jstring Java_com_example_virtual_myapplication_FullscreenActivity_stringFromJNI(JNIEnv* env, jobject thiz)\r\n {\r\n \u00a0\u00a0\u00a0 <span class=\"auto-style2\">char<\/span> szBuf[512];\r\n \u00a0\u00a0\u00a0 sprintf(szBuf, <span class=\"auto-style3\">\"%d\"<\/span>, s_ButtonPressCounter++);\r\n \r\n \u00a0\u00a0\u00a0 jstring str = (*env)-&gt;NewStringUTF(env, szBuf);\r\n \u00a0\u00a0\u00a0 <span class=\"auto-style2\">return<\/span> str;\r\n <\/span>}<\/pre>\n<p>Note that if your activity is named differently, the function will need to be renamed accordingly.<\/li>\n<li>Add a file called Android.mk to the jni directory and paste the following text in it:\n<pre class=\"\">LOCAL_PATH := $(call my-dir)\r\n \r\n include $(CLEAR_VARS)\r\n LOCAL_MODULE := HelloLibrary\r\n #VisualGDBAndroid: AutoUpdateSourcesInNextLine\r\n LOCAL_SRC_FILES := hello.c\r\n include $(BUILD_SHARED_LIBRARY)<\/pre>\n<\/li>\n<li>Double-check that the jni folder is located under the app folder at the same level as the src folder:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/10-files.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-453\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/10-files.png\" alt=\"10-files\" width=\"990\" height=\"769\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/10-files.png 990w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/10-files-300x233.png 300w\" sizes=\"(max-width: 990px) 100vw, 990px\" \/><\/a><\/li>\n<li>Open the FullScreenActivity.java file and add the following code inside the activity class:\n<pre class=\"\"><span class=\"keyword\">public native<\/span> String stringFromJNI();\r\n \r\n <span class=\"keyword\">static<\/span> {\r\n\u00a0\u00a0\u00a0 System.loadLibrary(<span class=\"string\">\"HelloLibrary\"<\/span>);\r\n}<\/pre>\n<\/li>\n<li>Then add code that will create a new button and update it based on a call to the native function inside the onCreate() method:\n<pre class=\"\"><span class=\"auto-style2\">final<\/span> Button button = (Button)findViewById(R.id.dummy_button);\r\nbutton.setOnClickListener(new View.OnClickListener() {\r\n\u00a0\u00a0\u00a0 <span class=\"auto-style2\">public<\/span> <span class=\"auto-style2\">void<\/span> onClick(View v) {\r\n\u00a0\u00a0\u00a0 String str = stringFromJNI();\r\n\u00a0\u00a0\u00a0 button.setText( str);\r\n\u00a0\u00a0\u00a0 }\r\n});<\/pre>\n<\/li>\n<li>You will need to import the &#8220;button&#8221; class to compile the newly added code. Android Studio can do it automatically via a smart tag:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/11-importbutton.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-454\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/11-importbutton.png\" alt=\"11-importbutton\" width=\"990\" height=\"769\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/11-importbutton.png 990w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/11-importbutton-300x233.png 300w\" sizes=\"(max-width: 990px) 100vw, 990px\" \/><\/a><\/li>\n<li>Now we will import the Android Studio project into Visual Studio to be able to develop and debug the C\/C++ part from it. Start Visual Studio and launch the VisualGDB Android Project Wizard:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/12-prjwiz.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-455\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/12-prjwiz.png\" alt=\"12-prjwiz\" width=\"800\" height=\"473\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/12-prjwiz.png 800w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/12-prjwiz-300x177.png 300w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/li>\n<li>On the first page select &#8220;Import existing project from Eclipse or Android Studio&#8221;:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/13-import.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-456\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/13-import.png\" alt=\"13-import\" width=\"649\" height=\"616\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/13-import.png 649w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/13-import-300x285.png 300w\" sizes=\"(max-width: 649px) 100vw, 649px\" \/><\/a><\/li>\n<li>Then specify the folder containing your project:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/14-srcpath.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-457\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/14-srcpath.png\" alt=\"14-srcpath\" width=\"649\" height=\"616\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/14-srcpath.png 649w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/14-srcpath-300x285.png 300w\" sizes=\"(max-width: 649px) 100vw, 649px\" \/><\/a><\/li>\n<li>Finally choose a platform you want to target:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/15-platform.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-458\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/15-platform.png\" alt=\"15-platform\" width=\"649\" height=\"616\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/15-platform.png 649w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/15-platform-300x285.png 300w\" sizes=\"(max-width: 649px) 100vw, 649px\" \/><\/a><\/li>\n<li>Press &#8220;Finish&#8221; to create the Visual Studio project. Build it with Ctrl-Shift-B:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/16-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-459\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/16-build.png\" alt=\"16-build\" width=\"695\" height=\"606\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/16-build.png 695w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/16-build-300x262.png 300w\" sizes=\"(max-width: 695px) 100vw, 695px\" \/><\/a><\/li>\n<li>Verify that the .apk file built by Gradle contains the lib\\&lt;eabi&gt;\\gdbserver file. You can check this by copying the .apk file to a .zip file and opening it in Windows Explorer:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/17-gdbserver.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-460\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/17-gdbserver.png\" alt=\"17-gdbserver\" width=\"610\" height=\"268\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/17-gdbserver.png 610w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/17-gdbserver-300x132.png 300w\" sizes=\"(max-width: 610px) 100vw, 610px\" \/><\/a><\/li>\n<li>Some versions of Gradle may have troubles placing the gdbserver inside the APK file. If that happens, add the following lines to your Android.mk file to work around this by renaming <strong>gdbserver<\/strong> to <strong>libgdbserver.so<\/strong>. VisualGDB will recognize this and use <strong>libgdbserver.so<\/strong> to debug:\n<pre class=\"\">installed_modules: $(dir $(NDK_APP_GDBSERVER))\/libgdbserver.so\r\n$(dir $(NDK_APP_GDBSERVER))\/libgdbserver.so: $(NDK_APP_GDBSERVER)\r\n    copy \/y $(subst \/,\\,$(NDK_APP_GDBSERVER) $(dir $(NDK_APP_GDBSERVER))\/libgdbserver.so)\r\n    del $(subst \/,\\,$(NDK_APP_GDBSERVER))<\/pre>\n<\/li>\n<li>Connect your Android device or launch the emulator via AVD Manager:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/18-avdmgr.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-461\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/18-avdmgr.png\" alt=\"18-avdmgr\" width=\"695\" height=\"606\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/18-avdmgr.png 695w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/18-avdmgr-300x262.png 300w\" sizes=\"(max-width: 695px) 100vw, 695px\" \/><\/a><\/li>\n<li>Go back to Android Studio and start debugging your project. Put a breakpoint on the call to stringFromJNI() and click the button on your device to trigger the call:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/19-button.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-462\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/19-button.png\" alt=\"19-button\" width=\"956\" height=\"882\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/19-button.png 956w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/19-button-300x277.png 300w\" sizes=\"(max-width: 956px) 100vw, 956px\" \/><\/a><\/li>\n<li>The Java breakpoint will now trigger. You can step over the method, however the Java debugger won&#8217;t be able to step into it:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/20-bkpt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-463\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/20-bkpt.png\" alt=\"20-bkpt\" width=\"781\" height=\"606\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/20-bkpt.png 781w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/20-bkpt-300x233.png 300w\" sizes=\"(max-width: 781px) 100vw, 781px\" \/><\/a><\/li>\n<li>That&#8217;s where Visual Studio comes into play. Go back to the VisualGDB project and start debugging. When VisualGDB asks you whether to restart the app, select &#8220;Attach to the running instance&#8221;:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/21-attach.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-464\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/21-attach.png\" alt=\"21-attach\" width=\"694\" height=\"605\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/21-attach.png 694w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/21-attach-300x262.png 300w\" sizes=\"(max-width: 694px) 100vw, 694px\" \/><\/a><\/li>\n<li>If you debugging this device for the first time, VisualGDB will suggest testing the debugging functionality on it. On many Android devices the debugging won&#8217;t work out of the box, so VisualGDB will try several known workarounds and select the one that works with your device automatically:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/22-test.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-465\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/22-test.png\" alt=\"22-test\" width=\"684\" height=\"382\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/22-test.png 684w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/22-test-300x168.png 300w\" sizes=\"(max-width: 684px) 100vw, 684px\" \/><\/a><\/li>\n<li>Now you can set a breakpoint on the native function in Visual Studio and step into it in Android Studio. The Visual Studio breakpoint will trigger and once the control returns to the Java code, you can continue debugging in Android studio: <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/23-codebug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-466\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/23-codebug.png\" alt=\"23-codebug\" width=\"955\" height=\"881\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/23-codebug.png 955w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/23-codebug-300x277.png 300w\" sizes=\"(max-width: 955px) 100vw, 955px\" \/><\/a><\/li>\n<li>Now we will add a different flavor to the app. Add the following text to the build.gradle file in your app directory:\n<pre class=\"\">\u00a0\u00a0\u00a0 productFlavors {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 normal {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 advanced {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 applicationId = \"com.example.virtual.myapplication.advanced\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 }<\/pre>\n<\/li>\n<li>Then add a Java source set folder that will only build for the Advanced flavor. Right-click on &#8220;src&#8221; and add a Java folder:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/24-javafolder.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-468\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/24-javafolder.png\" alt=\"24-javafolder\" width=\"830\" height=\"652\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/24-javafolder.png 830w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/24-javafolder-300x236.png 300w\" sizes=\"(max-width: 830px) 100vw, 830px\" \/><\/a><\/li>\n<li>Select the &#8220;advanced&#8221; source set:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/25-newfolder.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-469\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/25-newfolder.png\" alt=\"25-newfolder\" width=\"882\" height=\"789\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/25-newfolder.png 882w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/25-newfolder-300x268.png 300w\" sizes=\"(max-width: 882px) 100vw, 882px\" \/><\/a><\/li>\n<li>Add a package to the folder (specify the normal package name such as &#8220;com.example.virtual.myapplication&#8221;, not the app ID introduced by the flavor):<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/26-pkg.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-470\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/26-pkg.png\" alt=\"26-pkg\" width=\"916\" height=\"767\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/26-pkg.png 916w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/26-pkg-300x251.png 300w\" sizes=\"(max-width: 916px) 100vw, 916px\" \/><\/a><\/li>\n<li>Finally add a new Java class called &#8220;Constants&#8221;:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/27-constants.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-471\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/27-constants.png\" alt=\"27-constants\" width=\"916\" height=\"767\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/27-constants.png 916w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/27-constants-300x251.png 300w\" sizes=\"(max-width: 916px) 100vw, 916px\" \/><\/a><\/li>\n<li>Put the following contents to the Constants class:\n<pre class=\"\">package com.example.virtual.myapplication;\r\npublic class Constants {\r\n\u00a0\u00a0\u00a0 public static final String ButtonLabel = \"Advanced Button\";\r\n}<\/pre>\n<\/li>\n<li>Similarly create a normal source set and a &#8220;normal&#8221; constants file:\n<pre class=\"\">package com.example.virtual.myapplication;\r\npublic class Constants {\r\n\u00a0\u00a0\u00a0 public static final String ButtonLabel = \"Normal Button\";\r\n}<\/pre>\n<\/li>\n<li>Now you can set the initial button text to a flavor-dependent value:\n<pre class=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 button.setText(Constants.ButtonLabel);<\/pre>\n<p><a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/28-settext.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-472\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/28-settext.png\" alt=\"28-settext\" width=\"916\" height=\"767\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/28-settext.png 916w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/28-settext-300x251.png 300w\" sizes=\"(max-width: 916px) 100vw, 916px\" \/><\/a><\/li>\n<li>Go back to Visual Studio and open VisualGDB Project Properties. Enable the &#8220;Custom Flavor&#8221; checkbox and specify the &#8220;normal&#8221; flavor:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/29-normalflv.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-473\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/29-normalflv.png\" alt=\"29-normalflv\" width=\"662\" height=\"659\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/29-normalflv.png 662w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/29-normalflv-150x150.png 150w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/29-normalflv-300x300.png 300w\" sizes=\"(max-width: 662px) 100vw, 662px\" \/><\/a><\/li>\n<li>Click the &#8220;Add&#8221; button and create a copy of the current configuration: <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/30-advanced.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-474\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/30-advanced.png\" alt=\"30-advanced\" width=\"662\" height=\"659\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/30-advanced.png 662w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/30-advanced-150x150.png 150w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/30-advanced-300x300.png 300w\" sizes=\"(max-width: 662px) 100vw, 662px\" \/><\/a><\/li>\n<li>Specify the &#8220;Advanced&#8221; flavor for the new configuration:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/31-advancedflv.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-475\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/31-advancedflv.png\" alt=\"31-advancedflv\" width=\"662\" height=\"659\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/31-advancedflv.png 662w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/31-advancedflv-150x150.png 150w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/31-advancedflv-300x300.png 300w\" sizes=\"(max-width: 662px) 100vw, 662px\" \/><\/a><\/li>\n<li>Now you can build any of the configurations and see that VisualGDB will build the selected flavor:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/32-build1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-478\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/32-build1.png\" alt=\"32-build\" width=\"695\" height=\"607\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/32-build1.png 695w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/32-build1-300x262.png 300w\" sizes=\"(max-width: 695px) 100vw, 695px\" \/><\/a><\/li>\n<li>When you start debugging with F5, VisualGDB will launch the correct flavor based on the selected configuration:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/33-advancedbtn.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-479\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/33-advancedbtn.png\" alt=\"33-advancedbtn\" width=\"956\" height=\"882\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/33-advancedbtn.png 956w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/33-advancedbtn-300x277.png 300w\" sizes=\"(max-width: 956px) 100vw, 956px\" \/><\/a><\/li>\n<li>Click the button to verify that the breakpoints are working as usual:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/button.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-481\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/button.png\" alt=\"button\" width=\"711\" height=\"613\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/button.png 711w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/button-300x259.png 300w\" sizes=\"(max-width: 711px) 100vw, 711px\" \/><\/a><\/li>\n<li>If you now select the normal Debug configuration instead of &#8220;Debug (Advanced)&#8221;, VisualGDB will launch the &#8220;normal&#8221; flavor as specified in the configuration settings:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/34-normalbtn.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-480\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/34-normalbtn.png\" alt=\"34-normalbtn\" width=\"956\" height=\"882\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/34-normalbtn.png 956w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/34-normalbtn-300x277.png 300w\" sizes=\"(max-width: 956px) 100vw, 956px\" \/><\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to develop C\/C++ code in an Android Studio project using Visual Studio and VisualGDB. We will<\/p>\n","protected":false},"author":1,"featured_media":467,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[31,44,98],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/443"}],"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=443"}],"version-history":[{"count":6,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/443\/revisions"}],"predecessor-version":[{"id":1268,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/443\/revisions\/1268"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media\/467"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}