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.

.mk files, Makefiles, and the /build directory

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 /build directory.

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 Makefiles called Android.mk. The 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 .img and .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.

The $OUT directory

Helpful Tip

After you build, you can type cd $OUT to automatically go to the /out/target/project/CODENAME directory.

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.rc and 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).

Commands

$ . 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.

Helpful Tip

If you want to know more about what "$ . build/envsetup.sh" does or simply want to know more about the breakfast, brunch and 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 and 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, cd into the directory that you want to test, then just type mm to 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 system below, which you can use to push the newly built files directly to your device for testing without having to reflash everything.

Note: In case of error try building the module with all the dependencies using mma . "mma ." command; and then try again with mm or mm -B

Make

make modules -- this command will show all available targets. You can build a single one by make my_target.

make showcommands -- this command will enable the verbose build mode.

ADB

adb shell -- assuming you have adb installed, this will give you a command line shell inside your device. See adb help for more.

adb remount -- If you've gotten errors trying to push files to /system due to it being in read-only mode, adb remount will remount /system into 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 $OUT/system with the /system directory 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 system sometimes has problems with permissions and symlinks.