Tuesday, January 17, 2012

cross-compiling binaries for Android device on Windows 7/Ubuntu

C language is most commonly used basic programming language. Here is a method to run a C program on an Android device with ARM processor. We cross compile the program on windows machine and generate binary files for ARM. Cross compiling is a method of compiling executable for other platform other than the one in which compiler is run. Here we are creating an executable for ARM device (running Android) platform by compiling on windows. The same method should work on LINUX platform too.

1. Download and CodeSourcery's toolchain installer for IA32 Windows host from https://sourcery.mentor.com/sgpp/lite/arm/portal/release2029 .

2. Install the setup.

3. The toolchain provides the cross compiler arm-none-linux-gnueabi-gcc. Add directory path in default path variables.

4. write a sample program as follows

#include<stdio.h>
int main(){
     printf("\n Hello World! \n");
     return 0;
}
save the program as hello.c

5. compile hello.c as follows from the cmd/terminal:
$ arm-none-linux-gnueabi-gcc -o hello -static hello.c
6. Copy the binary to phone using adb tool or just copy it to phone memory.
$ adb push hello /data
7. There are two methods to run the program
i) Running on linux shell using adb
- open linux shell of the Android device using
$ adb shell
$ cd /data
$ ./hello

//output must be:

 Hello World!
ii) running it on virtual terminal on the Android device.
- download a virtual terminal emulator from android market (https://github.com/jackpal/Android-Terminal-Emulator/wiki)

-open the virtual terminal and run the program.
$ cd /data
$ ./hello

output displayed on terminal:
Hello world!


Its interesting to see the the C programs running on the linux shell. :) :D

Monday, January 16, 2012

Taking kernel and platform logs of an Android device together

I wanted to take both kernel and platform logs of an Android device together. So here is a piece of code that does that.

1. connect the Android target to Windows.
2. start cmd and type
$ adb shell       
$ logcat -v time -f /dev/kmsg | cat /proc/kmsg > /data/klog_plog.txt
$ exit
$ adb pull /data/klog_plog.txt > myfile.txt 

$ adb shell : this command moves user to linux shell of android device. Make sure adb location has been added to path variables in windows.
$ logcat -v time -f /dev/kmsg | cat /proc/kmsg > /data/klog_plog.txt

$logcat -v time prints the platform logs with time stamps. /dev/kmsg is a local buffer.
cat /proc/kmsg gives the kernel logs. So both platform and kernel logs are written to /data/klog_plog.txt

$ adb pull /data/klog_plog.txt > myfile.txt
it pulls the file from the Android device to local drive.

Saturday, January 14, 2012

Changing the default view in Windows File Explorer

I like the "Tiles view" in Windows  explorer. But by default it comes with some other view. So every time I open a new window I had to switch to the tiles view, as I find it comfortable. To avoid this here is a method to chage the default settings.

1. Open Windows explorer (for example My Computer).
2. Change the view to Tiles.


3. Go to tools menu and click Folder Options

4. Go to view tab and click on Apply to folders.