Automated building systems:
Another method is to use automated building system; such systems include Buildroot. Buildroot can automate the procedure we performed in the Building BusyBox-based embedded system (Intermediate) recipe. It facilitates the generation of a complete embedded Linux system. It not only includes a root filesystem and a kernel image, but also a cross-compilation toolchain and a bootloader image. The root filesystem integrates BusyBox and other powerful utilities, and even programming environments.
To build ramdisk.img automatically with Buildroot, create a configuration file, android_emulator_ramdisk_defconfig, first:
This configuration file allows us to build a BusyBox-based embedded system in the gzipped cpio archive with GCC and Bash support for the ARM target with Cortex A8 CPU.
Now download, configure, and compile it as follows:
The default major number of ttyS device is not the same as the Android ttyS device.
The default tty console is not ttyS0, but ttyS2. So, we need to fix them and repackage ramdisk.img.
After compiling, a target ramdisk image, output/images/rootfs.cpio.gz, should be ready for the Android emulator.
After booting, log in as a root user. We can use the native GCC compiler directly without any extra configuration. The -no-window option disables window output for this simple root filesystem, and it doesn't include window support.
If you want to avoid some of the pitfalls of cross-compilation and want to build C applications directly on the Android device as an exercise, a native C programming environment can be built for Android system by creating another configuration file, android_emulator_defconfig.
This configuration file tells us to compile the native compiler, GCC, for our ARM target device without BusyBox support and without packaging the target root filesystem.
Now, configure and compile it as follows:
Then prepare a configuration, native-gcc.rc, for the setting of environment variables as follows:
This file mainly configures the PATH, LD_LIBRARY_PATH, LIBRARY_PATH, and C_LINCLUDE_PATH environment variables to let GCC works as is.
At last, let's push the target directory and configuration to the Android system, and use the native GCC to compile a simple program as follows: