Doc: Building Basics
Basic language info
Android is written in a combination of C, C++, and Java. Here's a bit of a breakdown:
- the very low-level stuff like the kernel, libc (or bionic as it's known in the android world), and many Linux-ish parts of Android are written in C.
- Slightly "higher"-up stuff, as well as external, 3rd-party open-source programs incorporated into Android may be written in C or C++. This includes everything from ART (the Android Runtime environment, which runs end-user programs), networking tools, sound processors, shell tools, graphics drivers, and that sort of thing.
- The user-facing Android "framework" stuff such as the UI elements, as well as most apps themselves, are written in Java. This is the stuff that most people think of when they think of "Android", because it deals with much of what they see and interact with.
You can learn more about any of these languages from the external online resources.
Makefiles, and the
There is a whole build system which is used to create a flashable
.zip file from source. The various
Makefile scripts used to control this process are primarily located in the
It may be useful to know the basics of how it works-- essentially, the various components/programs which together make up Android are each built independently through Android-specific
Android.mk generally exists for each sub-project (or "module") in its source-code directory. This file directs the build system on exactly how to build that module, and where to put it in Android's directory structure.
The files, once built, end up in the
/out/target/project/CODENAME directory (replace CODENAME with the code name of the device). From there, they are zipped up and the final flashable (by recovery)
.zip and flashable (by fastboot)
.img files are produced.
You can actually get a peek at what's been built there in
/out, as the directories that are turned into the
.zip files are still around.
The various source code directories
In addition to the
/build directory, the Android source code is organized into a hierarchy of folders. Take a look here at a brief description of what's where in the source code.
After you build, you can type
cd $OUT to automatically go to the
kernel This is the kernel, obviously.
/system -- this contains all the stuff that will become the
/system folder on Android.
/root -- these files contain the files that are turned into the ram disk loaded and run by the kernel. The first program to be run by the kernel is called
init, and it uses the
init.CODENAME.rc files to determine what happens next. See an discussion of that here.
/recovery/root The ramdisk that contains the recovery mode is here.
Shortcut commands every CM dev should know
These commands are really useful for developing w/CM. All these commands are meant to be typed from your computer, not the shell on your device (except where indicated).
$ . build/envsetup.sh-- Note the "
." at the beginning. This will load the environment variables to your shell as well as aliases needed for the rest of these shortcuts.
If you want to know more about what "
$ . build/envsetup.sh" does or simply want to know more about the
lunch commands, you can head over to the Envsetup_help page
croot-- this command will take you to the root of the source code.
mm -B-- this is the "make module" command and it is very useful if you are working on a particular module (that is, a section of the code to be built) and don't want to have to rebuild everything just to test it. To use it,
cdinto the directory that you want to test, then just type
mmto build just the module in the working directory. If you want to start the build from scratch, add the
-B. This is a good companion with
adb sync systembelow, which you can use to push the newly built files directly to your device for testing without having to reflash everything.
make modules-- this command will show all available targets. You can build a single one by
make showcommands-- this command will enable the verbose build mode.
adb shell-- assuming you have adb installed, this will give you a command line shell inside your device. See adb help for more.
adb reboot-- If you've got adb installed, this will quickly make your device reboot. Or try
adb reboot recoveryto reboot directly into recovery.
adb reboot bootloadersimilarly does just what you'd expect.
adb remount-- If you've gotten errors trying to push files to
/systemdue to it being in read-only mode,
adb remountwill remount
/systeminto read-write mode--- provided that the shell has the correct root permissions to do so. This replaces having to type a longer command by hand such as
mount -o rw,remount /system(as root) or something.
adb sync system-- assuming you have adb installed, this little-known, but powerful command will sync the contents of
/systemdirectory on your device. It does require that you have write access to
/system. This command is very useful for making and testing quick changes to your device. Note though that
adb sync systemsometimes has problems with permissions and symlinks.