Mastodon

Building own executable in Android

 

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 ]

The real stuff

Crate your hello.c file in your working folder with below conetnts:

 #include <stdio.h>
 int main(int argc,char * argv[])
 {
   printf("Hello, Android!\n");
   exit(0);
 }

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:

 C:\helloworld>arm-none-linux-gnueabi-gcc -c hello.c -o hello.o
 hello.c: In function 'main':
 hello.c:37:2: warning: incompatible implicit declaration of built-in function 'exit'
 C:\helloworld>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
 C:\helloworld>adb push hellodynamic /data/temp
 1093 KB/s (4480 bytes in 0.004s)
 C:\helloworld>adb shell "chmod 777 /data/temp/hellodynamic"

You are done!! You app is built and installed on phone. You can launch the app using below command:

 C:\helloworld>adb shell "/data/temp/hellodynamic"
 Hello World!
 C:\helloworld>

Note: 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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.