Slide 1

Slide 1 text

This should be easy ! ● Get the source code ● Build it ● Flash on device ● Enjoy !

Slide 2

Slide 2 text

Or more technically speaking. . . $ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo $ chmod a+x ~/bin/repo $ mkdir ~/android $ repo init -u https://android.googlesource.com/platform_manifest -b android- 6.0.0_r25 $ repo sync $ . build/envsetup.sh $ lunch full_hammerhead-eng $ make $ fastboot flash --all

Slide 3

Slide 3 text

This should be easy, mostly. ● Get the source code ● Build it ● Make some changes ● Rebuild it ● Flash on device ● Enjoy !

Slide 4

Slide 4 text

This should be easy, mostly, I guess . . . ● Get the source code ● Build it ● Make some changes ● Rebuild it ● Flash on device ● Test it works ● Commit changes ● Enjoy !

Slide 5

Slide 5 text

This should be easy, mostly, I guess. Or is it really??? ● Get the source code ● Build it ● Make some changes ● Rebuild it ● Flash on device ● Test it works ● Commit changes ● Review everyone’s changes ● Release your Android ROM ● Enjoy ! Now fix all the reported bugs.

Slide 6

Slide 6 text

Finally I can hack, build, deploy, and test ROMs with a wag of my tail ! Woof Woof !

Slide 7

Slide 7 text

Setting up an Android OS Project Source. Edit. Collaborate. Codereview. Build. Automate. Deploy. - Arnav Gupta

Slide 8

Slide 8 text

Before we begin, let me gloat about myself a bit . . . Undergraduate Student, Electrical and Electronics, Delhi Technological University Contributor to CyanogenMod, AOKP and other custom ROM projects. Developer Relations team, YU Televentures. Few contributions to AOSP - in Kitkat and Lollipop.

Slide 9

Slide 9 text

The important questions that come to mind ...

Slide 10

Slide 10 text

… when we start building ● What architecture can you build on? What architecture can you build for ? ● What packages are needed to build the Android source code ? ● What environmental variables are needed ? ● What are the minimum hardware requirements ? ● How much time does it take to build? How to reduce ? ● Any steps to improve incremental builds ? ● How to build partially, or only some modules ?

Slide 11

Slide 11 text

… when we start pushing and pulling ● How to pull updates from upstream ? ● How to collaborate as a team/community ? ● How to make source available over LAN ? ● How to reduce redundant data download when building multiple variant/version ? ● How to contribute to your own project? How to contribute back to Google? ● How to have a transparent, hierarchical, access-controlled code review ?

Slide 12

Slide 12 text

… when we start distributing the OS ● How to send updates ? OTA or not ? ● Can OTA updates be delta ? ● How to update system apps over the play store ? ● How to make sure 3rd parties cannot exploit SignatureOrSystem perms ? ● Rooted or not ? Debugging enabled or not ? ● How to handle dirty flashes ?

Slide 13

Slide 13 text

… when we use our own ROM

Slide 14

Slide 14 text

Managing the source It's 25 GB. So let's not download what we don’t want. Building non AOSP devices means conflicting source trees If you are a company, you’d like to have a local copy of source, instead of each employee downloading it. Contribs & Codereview Github PR’s are great for a single repo. But Android spans across 400+ repos, many interdependent. One single patch might have dependencies on other patches on other projects. Managing rights to merge, make branches, approve. Automated verification that a patch doesn’t break the build. Build and distribute For frequent, multi-device builds, a fairly powerful build machine needed Make builds automatically available over a download server. Generate deltas for updates. Maintain proper versioning of builds. Differentiate between nightlies, betas, stable builds and releases. Keep track of bugs, and fix blames on build numbers correctly. The three problems, and the solutions

Slide 15

Slide 15 text

Some numbers, before we begin

Slide 16

Slide 16 text

12 GB Checked out size of the inflated source tree

Slide 17

Slide 17 text

25 GB Android source code total git history size for Android 6.0

Slide 18

Slide 18 text

450 Roughly the number of total repos in the AOSP manifest

Slide 19

Slide 19 text

188,000 Patches up for review on android-review.googlesource.com

Slide 20

Slide 20 text

197,300 Number of issues opened on code.google.com/p/android

Slide 21

Slide 21 text

750,000 Total lines of C/C++ code (without comments) in Android system and bionic

Slide 22

Slide 22 text

2,100,000 Total lines of Java code (exculding blanks, comments) in Android frameworks

Slide 23

Slide 23 text

50,000,000 Number of people using Cyanogen OS and CyanogenMod ROMs

Slide 24

Slide 24 text

42 The answer to life, universe and everything

Slide 25

Slide 25 text

The Source There is just way too much of it.

Slide 26

Slide 26 text

‘repo’ A tool made by Google to help in managing the source of huge projects like Android, Chromium repo init -u http://url.of/manifest repo sync [-f] [-j 4] repo init -g a,b,-c,-d repo start newbranch . repo upload

Slide 27

Slide 27 text

‘repo’ A tool made by Google to help in managing the source of huge projects like Android, Chromium

Slide 28

Slide 28 text

manifest An xml file defining all the git repos needed in the project

Slide 29

Slide 29 text

The Build Compiled few million LoC, and takes an eternity

Slide 30

Slide 30 text

The basic steps . build/envsetup.sh lunch [device-buildtype] lunch aosp_hammerhead-eng make make Contacts.apk cd packages/apps/Contacts && mmm Sets up the build environment. Initialises all env vars. Defines functions to various build tasks. Defines a target device. Generates makefiles and changes env vars accordingly. Well this one’s obvious Two ways to make the Contacts package. First one builds all dependencies. Second one works only for incremental builds.

Slide 31

Slide 31 text

What can speed it up ?

Slide 32

Slide 32 text

ccache To speed up low level file compilations (drivers, system) ● Set USE_CCACHE=1 and CCACHE_DIR appropriately ● First build will become longer. Subsequent builds will be shorter ● Use separate ccache folders per device if you can afford. ● Set a comfortably large cache max size

Slide 33

Slide 33 text

prebuilt chromium * for versions prior to 6.0 (M) Instead of building inline, keep a prebuilt copy of webview.apk and libwebviewchromium.so Webview changes once every 2 months or so. Android 6.0 uses prebuilt Google- signed webview only.

Slide 34

Slide 34 text

shared lib cache Cache the dynamic libs review.cyanogenmod.org/92967/ Caches the built up libs, per device. If no changes in source of a lib (or it’s dependencies), it won’t be built. Reduces 30-40% build times for recurring aarch64 builds.

Slide 35

Slide 35 text

$$$ money $$$ So that you can ramp up your hardware 03:32:46 - Time taken for clean Nexus 5 build of AOSP 6.0 on Core i5 2.5 Ghz (2-core, hyperthreaded), 8 GB RAM, 5400rpm HDD. 00:24:03 - Time taken for clean Nexus 5 build of AOSP 6.0 on Core i7 3.0 Ghz (4-core hyperthreaded), 16 GB RAM, SSD.

Slide 36

Slide 36 text

Code Review Where all the drama happens

Slide 37

Slide 37 text

Let’s see some code reviews

Slide 38

Slide 38 text

Some things are alarming

Slide 39

Slide 39 text

Sometimes there is caution

Slide 40

Slide 40 text

Sometimes people don’t want their own patch submitted

Slide 41

Slide 41 text

And sometimes . . . well…

Slide 42

Slide 42 text

But on a serious note

Slide 43

Slide 43 text

Gerrit ● A code-review server written to work on top of Git ● Developed by Google to support large multi-repository projects like Chromium, Android etc. ● Supports comments, voting (+1, +2), approval and verification. ● Has REST API, can be accessed over SSH as well.

Slide 44

Slide 44 text

Install Gerrit Download latest from : https://gerrit-releases.storage.googleapis.com/index.html $ wget https://www.gerritcodereview.com/download/gerrit-2.11.5.war Recommended to create separate user gerrit which will run the gerrit daemon. $ sudo adduser gerrit $ sudo su gerrit $ mkdir ~/gerrit_site $ java -jar gerrit-2.11.5.war init -d ~/gerrit_site

Slide 45

Slide 45 text

Gerrit Install Wizard Create '/home/gerrit_test/gerrit' [Y/n]? Y Location of Git repositories [git]: Set anywhere, default $GERRIT/git Database server type [h2]: h2/mysql/postgres (default h2) Authentication method [OPENID/?]: OPENID/HTTPS/OAUTH Email Delivery : Use SMTP configs of Gmail/Hotmail etc, or use sendmail Listen on port [29418]: Port for SSH access to gerrit Http Daemon : Set up as per proxies and required port [8080]

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

Gerrit OAuth Plugin ● Google makes Gerrit ● Gerrit only supports OpenID ● Google has deprecated OpenID and uses Oauth via Google+ Signin ● Gerrit, by default, has OpenID, but no Oauth. So we need a plugin.

Slide 48

Slide 48 text

On a separate note . .

Slide 49

Slide 49 text

Google Search and Angular ● Google makes Angular.JS ● Angular is used to make single-page webapps ● Google search cannot index single-page webapps

Slide 50

Slide 50 text

. . . but let’s not digress

Slide 51

Slide 51 text

Add Oauth login/signup to Gerrit ● https://github.com/davido/gerrit-oauth-provider ● Get latest .jar from releases ● Add to $GERRIT/plugins/ ● Create an app on Google Dev Console. Get an “Other Application” auth token. ● Create an app on Github Dev Console. Get the auth tokens ● Re-run Gerrit init, the wizard will ask for above keys

Slide 52

Slide 52 text

The Buildbot First you build the bot, then the bot builds.

Slide 53

Slide 53 text

Installing Jenkins $ wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add - $ sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list' $ sudo apt-get update $ sudo apt-get install jenkins

Slide 54

Slide 54 text

Installing Jenkins

Slide 55

Slide 55 text

Distributed Jenkins builds ● We can use multiple slaves connected to a master Jenkins bot ● Best way is the use SSH based slaves. All slaved need to be running sshd. ● Add id_rsa.pub from master, and add to authorized_keys of slaves ● Set up the slave using - ○ Manage Jenkins -> Manage Nodes - > New Node

Slide 56

Slide 56 text

OTA Updates

Slide 57

Slide 57 text

Full size update AOSP ~ 350MB + Gapps ~150MB Enterprise OS can easily be 1 GB Cumbersome for end users to download Should be used only when a delta updates won’t work. OEM’s use full-size updates when updating via PC-suites. Hexdiff partition updates Smallest size updates. 5.0 > 6.0 can be as small as 100MB (for a 1 GB system image). Only safe for controlled environments. Won’t work on devices that are rooted and have a modified system partition. Ideally should check for partition integrity before getting applied. Filewise diff update An unconventional compromise between the two. Smaller than full-size update. Will work with modified system partitions too. http://gerrit.aokp.co/13262/ Different ways to do an OTA Update