{"id":283,"date":"2012-05-01T14:57:05","date_gmt":"2012-05-01T12:57:05","guid":{"rendered":"http:\/\/www.btrnaidu.com\/?p=283"},"modified":"2012-05-03T12:42:17","modified_gmt":"2012-05-03T10:42:17","slug":"building-own-executable-in-android","status":"publish","type":"post","link":"https:\/\/btrnaidu.com\/index.php\/building-own-executable-in-android\/","title":{"rendered":"Building own executable in Android"},"content":{"rendered":"<p>&nbsp;<\/p>\n<h2>Required tools<\/h2>\n<pre> Download and install <strong><a title=\"Sourcery G++ Lite Edition for ARM\" href=\"http:\/\/www.codesourcery.com\/gnu_toolchains\/arm\/portal\/package2548?@template=release\" target=\"_blank\">Sourcery G++ Lite Edition for ARM<\/a><\/strong>\r\n Pull the android libs for dynamic linking using the script [ <a href=\"http:\/\/www.btrnaidu.com\/wp-content\/uploads\/2012\/05\/PullAndroidSysLibs.bat\">PullAndroidSysLibs.bat<\/a> ]\r\n Download the build script and copy in your working folder [<a href=\"http:\/\/www.btrnaidu.com\/wp-content\/uploads\/2012\/05\/build_nd_push2.bat\">build_nd_push.bat<\/a>]\r\n Download the assembly [<a href=\"http:\/\/www.btrnaidu.com\/wp-content\/uploads\/2012\/05\/crt.s\">crt.S<\/a>] file for startup code and copy in your working folder.  Article from [ <a href=\"http:\/\/honeypod.blogspot.com\/2007\/12\/initialize-libc-for-android.html\" target=\"_blank\">1<\/a> ]<\/pre>\n<p><!--more--><\/p>\n<h2>The real stuff<\/h2>\n<p>Crate your hello.c file in your working folder with below conetnts:<\/p>\n<pre> #include &lt;stdio.h&gt;\r\n int main(int argc,char * argv[])\r\n {\r\n   printf(\"Hello, Android!\\n\");\r\n   exit(0);\r\n }<\/pre>\n<p>Make sure your phone is connected with usb and run the build_nd_push.bat. If all goes fine, you should see an output like this:<\/p>\n<pre> C:\\helloworld&gt;arm-none-linux-gnueabi-gcc -c hello.c -o hello.o\r\n hello.c: In function 'main':\r\n hello.c:37:2: warning: incompatible implicit declaration of built-in function 'exit'\r\n C:\\helloworld&gt;arm-none-linux-gnueabi-ld --entry=_start --dynamic-linker \/system\/bin\/linker -nostdlib -rpath \/system\/lib -rpath-link \\apps\\android\\system\\lib -L \\apps\\android\\system\\lib -l c -l android_runtime -l sqlite -o hellodynamic hello.o crt0.o\r\n C:\\helloworld&gt;adb push hellodynamic \/data\/temp\r\n 1093 KB\/s (4480 bytes in 0.004s)\r\n C:\\helloworld&gt;adb shell \"chmod 777 \/data\/temp\/hellodynamic\"<\/pre>\n<p>You are done!! You app is built and installed on phone. You can launch the app using below command:<\/p>\n<pre> C:\\helloworld&gt;adb shell \"\/data\/temp\/hellodynamic\"\r\n Hello World!\r\n C:\\helloworld&gt;<\/pre>\n<p><strong>N<\/strong>ote: The build script build_nd_push.bat hard codes the path to abd. If your ENV is set or has a different path then please update your build script to point to correct path.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Required tools Download and install Sourcery G++ Lite Edition for ARM Pull the android libs for dynamic linking using the script [ PullAndroidSysLibs.bat ] Download the build script and copy in your working folder [build_nd_push.bat] Download the assembly [crt.S] file for startup code and copy in your working folder. Article from [ 1 ]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[78],"tags":[112,114,113],"class_list":["post-283","post","type-post","status-publish","format-standard","hentry","category-android","tag-building-own-executable-in-android","tag-helloword-exe-in-android","tag-writing-own-executable-in-abdroid"],"_links":{"self":[{"href":"https:\/\/btrnaidu.com\/index.php\/wp-json\/wp\/v2\/posts\/283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/btrnaidu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/btrnaidu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/btrnaidu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/btrnaidu.com\/index.php\/wp-json\/wp\/v2\/comments?post=283"}],"version-history":[{"count":5,"href":"https:\/\/btrnaidu.com\/index.php\/wp-json\/wp\/v2\/posts\/283\/revisions"}],"predecessor-version":[{"id":293,"href":"https:\/\/btrnaidu.com\/index.php\/wp-json\/wp\/v2\/posts\/283\/revisions\/293"}],"wp:attachment":[{"href":"https:\/\/btrnaidu.com\/index.php\/wp-json\/wp\/v2\/media?parent=283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/btrnaidu.com\/index.php\/wp-json\/wp\/v2\/categories?post=283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/btrnaidu.com\/index.php\/wp-json\/wp\/v2\/tags?post=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}