You can help develop the most widely installed operating system in the history of Earth. Yes, you are here to embark upon the journey of becoming an Android platform engineer.
Although the path is challenging, we the Android team strive to simplify your journey every release. And we make improvements every day via direct work in the Android Open Source Project (AOSP).
So sit back, fire up a terminal, and let's make history.
The mission of this codelab is twofold:
- This codelab will give you a small taste of what the developer workflow is like for Android engineers working on the platform (operating system).
- This codelab is a forcing function for you to provide feedback around Android's tools, documentation and the developer workflow when starting from scratch.
Here is the complete list of requirements for this codelab, derived from those for general platform (AOSP) development.
To take this codelab, you will need to set up:
- Physical Linux workstation meeting all public requirements.
- Repo and the Git configuration required to edit the Android code base.
Typically, users build and develop on the workstation directly. Because you may be working in various terminals, and many of the commands used are terminal-specific, you will need to re-run them in each terminal session. Specifically, these include the
source build/envsetup.sh, and
Set up workstation
- Install the necessary packages on the workstation.
- While still in a terminal, install Repo and gain credentials to all Git repositories.
Initialize and sync the code
Navigate into your home directory:
Create a local working subdirectory within it:
Navigate into the directory:
Initialize the AOSP repository source code master branch (the default):
repo init -u https://android.googlesource.com/platform/manifest
Enter or accept your Git credentials (name, email address).
Sync the source code:
repo sync -j16
Initial syncs can take an hour or more. See the downloading instructions for related details while you wait.
Each repo checkout is represented by a manifest file. You may have more than one repo checkout at a time so long as they exist in distinct directories. But note each checkout and build amounts to roughly 300GB and growing, so limit yourself to two or augment your system with a secondary drive.
Tip: To free up space, delete a branch directory and start anew from directory creation:
rm -rf aosp2
Build the code
To build Android, you must select a target device type to build with the
lunch command. Targets are device permutations, such as a specific model or form factor.
The device target included below,
aosp_cf_x86_phone-userdebug, enables you to build the Cuttlefish virtual Android device for testing without a physical device.
To instead build and update a physical device, choose another target and follow the instructions for flashing devices.
Set up your environment for building Android devices by running the following command from the root of your source code checkout:
Pass the build target to the lunch command, like so:
Build the code from anywhere in your checkout with:
Expect the first build to take hours. Subsequent builds take significantly less time.
Create Acloud instance
Acloud is a command line tool in AOSP that assists users in creating virtual Android devices, in this case Cuttlefish.
If you are in the same terminal session used to build the code, proceed. Otherwise, re-run the
envsetup.sh script and same lunch command used there first. Then:
Create an Acloud local instance with:
acloud create --local-image --local-instance
Accept updates to required packages.
If prompted, restart your workstation for all changes to take effect.
Select the Cuttlefish device.
You should be greeted with a VNC session containing an Android device!
You can interact with the virtual device on your workstation using your mouse and keyboard. You may also follow the activity within the logs while you use your device with the Android Debug Bridge (adb)
Make a change
Update the source code following this example changelist.
From the root of your checkout (
aosp/directory), navigate to the
Start a temporary project with:
repo start <some-name> .
SurfaceFlinger.cppto include the updates from the changelist at the following location:
Build the code:
Update the build on the device:
adb root adb remount adb sync adb reboot acloud reconnect
You should see a color change on the device.
Test your code
During this portion of the codelab we will run through an example test that is in the source tree and is already failing. In order to run the test locally we will use Atest to test the code.
To use the test:
The test will fail; now let's fix it! Find the source code of the failing test:
atest --info android.test.example.devcodelab.DevCodelabTest#testHelloWorld
Then look within:
For the file to edit, take the name of the test and replace the
/, like so:
Run the test again to verify you fixed the test:
Upload your code for review
Repo simplifies use of Git by bundling commands such as
git clone to work across numerous Git repositories (or projects) at once.
See Source Control Tools for overviews of Git and Repo with links to full documentation on working with Android source code. See the AOSP repository for the full list of Git projects and the individual projects (paths) for branches associated with each project.
You will be using the Gerrit web-based code review system for projects in Git.
Assuming you made your changes in the
frameworks/nativeproject, run these commands to upload them:
cd frameworks/native repo start codelab . git add . git commit
For your commit message enter:
Android codelab change Test: manual atest
Upload your change:
If you are successful, you will see a message resembling:
Upload project frameworks/native/ to remote branch master: branch codelab ( 1 commit, Wed Aug 7 09:32:33 2019 -0700): ff46b36d android codelab change to https://android-review.googlesource.com/ (y/N)? y remote: Processing changes: refs: 1, new: 1, done remote: remote: SUCCESS remote: remote: https://android-review.googlesource.com/c/platform/frameworks/native/+/1098432 android codelab change [NEW] remote: To https://android-review.googlesource.com/platform/frameworks/native * [new branch] codelab -> refs/for/master
View your change in Gerrit
Go to the link printed in the terminal resembling:
This completes the starter codelab for Android platform development. See Submitting Patches for next steps and the rest of this site for full details on developing Android.
Revert your change
Normally, post testing and review/approval, you would submit your change in Gerrit and merge it into the repository.
Instead, for the purposes of the codelab, revert your changelist by clicking Abandon in Gerrit.
Then abandon the associated temporary branch in the frameworks/native project directory (or its subs):
repo abandon codelab .
Remember also to revert the changes to the test file. Since we did not
git commit, and
repo upload the change, we can merely reset the file itself, like so (assuming you are in the
git reset HEAD tests/example/devcodelab/src/android/test/example/devcodelab/DevCodelabTest.java git checkout .
At this point, you are done! Nice work!