{"id":84,"date":"2014-11-10T12:01:35","date_gmt":"2014-11-10T12:01:35","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=84"},"modified":"2014-11-10T12:01:35","modified_gmt":"2014-11-10T12:01:35","slug":"android-cmdline","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/android\/cmdline\/","title":{"rendered":"Creating a command-line Android tool with VisualGDB"},"content":{"rendered":"\n<p>This tutorial explains how to develop and debug a command-line Android executable with Visual Studio. <\/p>\n<p>Command-line Android tools are built using the <strong>&#8220;include $(BUILD_EXECUTABLE)&#8221;<\/strong> line and are supported by the Ultimate edition of VisualGDB 4.2 and later. Attaching to running tools is supported by VisualGDB 4.3+.<\/p>\n<ol>\n<li>Start Visual Studio. Begin creating a new project using VisualGDB Android Project wizard:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/01-toolprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/01-toolprj.png\" alt=\"01-toolprj\" width=\"700\" height=\"394\" \/><\/a><\/li>\n<li>Select &#8220;Create a command-line Android executable&#8221; in the wizard:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/02-exec.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/02-exec.png\" alt=\"02-exec\" width=\"649\" height=\"616\" \/><\/a><\/li>\n<li>Select the platform you are targeting on the second page of the wizard:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/03-platform.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/03-platform.png\" alt=\"03-platform\" width=\"649\" height=\"616\" \/><\/a><\/li>\n<li>Press Ctrl-Shift-B to build the tool:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/04-build.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/04-build.png\" alt=\"04-build\" width=\"700\" height=\"604\" \/><\/a><\/li>\n<li>Set a breakpoint on the printf() line, connect your Android device, install the drivers and press F5 to begin debugging. VisualGDB will deploy your tool on the device:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/05-deploy.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/05-deploy.png\" alt=\"05-deploy\" width=\"484\" height=\"262\" \/><\/a><\/li>\n<li>Once the tool is deployed and launched, your breakpoint will be triggered:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/06-breakpoint.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/06-breakpoint.png\" alt=\"06-breakpoint\" width=\"700\" height=\"604\" \/><\/a><\/li>\n<li>Press F5 to let the tool run to the end. Now we will show how to attach to the tool. Change the source code so that the tool asks for the user input before exiting and build your tool:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/07a-input.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/07a-input.png\" alt=\"07a-input\" width=\"700\" height=\"640\" \/><\/a><\/li>\n<li>Right-click on the project in Solution Explorer and select &#8220;VisualGDB Project Properties&#8221;. Go to the Debug Settings page:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/07-deploypath.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/07-deploypath.png\" alt=\"07-deploypath\" width=\"700\" height=\"584\" \/><\/a><\/li>\n<li>You can see that the tool is deployed to <strong> \/data\/local\/tmp<\/strong>. You can change the deployment location and other options from here. Close the properties window and press Ctrl-F5 to deploy and start the tool without debugging. Due to the limitations of the Android ADB tool you won&#8217;t be able to send the text to your tool in this mode, so simply press Ctrl-C to end it:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/07b-instance.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/07b-instance.png\" alt=\"07b-instance\" width=\"677\" height=\"342\" \/><\/a><\/li>\n<li>Now we will launch our tool in the interactive mode. Select Android-&gt;Open Android Shell:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/08-shell.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-10\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/08-shell.png\" alt=\"08-shell\" width=\"677\" height=\"342\" \/><\/a><\/li>\n<li>Go to the deployment directory and launch the tool. Enter some text once the tool is running, but do not press Enter:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/09-launchtool.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/09-launchtool.png\" alt=\"09-launchtool\" width=\"677\" height=\"342\" \/><\/a><\/li>\n<li>Go back to VisualGDB Project Properties and select &#8220;Automatically attach to existing instance&#8221; on the Debug Settings page:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/10-attach.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-12\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/10-attach.png\" alt=\"10-attach\" width=\"700\" height=\"584\" \/><\/a><\/li>\n<li>Press F5 to begin debugging. VisualGDB will attach to your tool. Select Debug-&gt;Break All and examine the call stack. You will see that the tool is running the gets() function:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/11-stack.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-13\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/11-stack.png\" alt=\"11-stack\" width=\"698\" height=\"640\" \/><\/a><\/li>\n<li>Set a breakpoint on the last printf() call, resume execution and press Enter in the ADB console. The breakpoint will be triggered and you will see the line you entered:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/12-breakpoint.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-14\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/tutorials\/android\/cmdline\/12-breakpoint.png\" alt=\"12-breakpoint\" width=\"699\" height=\"641\" \/><\/a><\/li>\n<\/ol>\n<p>If you want to create an app containing native code instead, follow our <a href=\"http:\/\/visualgdb.com\/tutorials\/android\/cmdline\/..\/\">Android App tutorial<\/a>.<\/p>\n<p><\/root><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial explains how to develop and debug a command-line Android executable with Visual Studio. Command-line Android tools are built<\/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,38],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/84"}],"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=84"}],"version-history":[{"count":0,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/84\/revisions"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}