AOSP Building Blocks (Droidcon London 2014)

D4be3ad792b57408b3ab6fe98caef08e?s=47 danybony
October 30, 2014

AOSP Building Blocks (Droidcon London 2014)

Most of the Android developers are able to build awesome apps, but do we really know how the Android OS works? In some cases, as when developing a new product, adding customised apps is not enough, and OS modifications are required.
To be able to modify Android at its core, this talk will guide you through the complete process, from setting the correct environment, configuring the different Google’s repositories and downloading the source code, to understand the structure of the source code and how to modify it.

D4be3ad792b57408b3ab6fe98caef08e?s=128

danybony

October 30, 2014
Tweet

Transcript

  1. AOSP building blocks

  2. Daniele Bonaldo @danybony_ +DanieleBonaldo danybony Android Software Craftsman

  3. None
  4. Repo and manifest Usually a single project = single repository

  5. Repo and manifest AOSP = more than 450 repositories

  6. Repo and manifest Enter repo

  7. Repo and manifest repo init -u http://your.company.repo/manifest -b working_branch -m

    manifest_name.xml
  8. Repo and manifest <?xml version="1.0" encoding="UTF-8"?> <manifest> <remote name="aosp" fetch="https://android.googlesource.com/"

    /> <remote name="company" fetch="ssh://git@github.com/third_party/" /> <default revision="refs/tags/android-4.4.2_r1" remote="aosp" sync-j="4" /> <project path="build" name="platform/build" groups="pdk" /> <project path="abi/cpp" name="platform/abi/cpp" groups="pdk" /> <project path="art" name="platform/art" /> <project path="bionic" name="platform/bionic" groups="pdk" /> <project path="bootable/bootloader/legacy" name="platform/bootable/bootloader/legacy" /> <project path="bootable/diskinstaller" name="platform/bootable/diskinstaller" /> <project path="packages/apps/Settings" name="firmware-settings" remote="company" revision="other_branch" /> [...] <manifest/>
  9. Repo and manifest <project path="packages/apps/Settings" remote="company" name="firmware-settings" revision="other_branch" />

  10. Repo and manifest <project path="packages/apps/Settings" remote="company" name="firmware-settings" revision="other_branch" /> <remote

    name="company" fetch="ssh://git@github.com/third_party/" />
  11. Repo and manifest <project path="packages/apps/Settings" remote="company" name="firmware-settings" revision="other_branch" />

  12. Repo and manifest <project path="packages/apps/Settings" remote="company" name="firmware-settings" revision="other_branch" />

  13. Repo and manifest repo sync -j (--jobs)

  14. AOSP Source Code http://elinux.org/Master-android

  15. AOSP Source Code Some examples: • development • frameworks •

    packages • vendors
  16. Edit the source Jack M. on Flickr

  17. IDE ./development/tools/idegen/idegen.sh Project definition files generated in the root of

    the working dir
  18. Search the source

  19. @hide Context.sendBroadcastAsUser(Intent, UserHandle); Context.startActivityAsUser(Intent, UserHandle); Context.startServiceAsUser(Intent, UserHandle); @hide public UserHandle(int

    userId)
  20. @hide public UserHandle(int userId) @hide

  21. @hide public static UserHandle getUserHandleForUser(int userId) { try { Class<UserHandle>

    userHandleClass = UserHandle.class; Constructor<UserHandle> constructor = userHandleClass.getDeclaredConstructor(int.class); constructor.setAccessible(true); return constructor.newInstance(userId); } catch (InvocationTargetException e) { logUnableToFetchUserHandleForUser(userId, e); } catch (NoSuchMethodException e) { logUnableToFetchUserHandleForUser(userId, e); } catch (InstantiationException e) { logUnableToFetchUserHandleForUser(userId, e); } catch (IllegalAccessException e) { logUnableToFetchUserHandleForUser(userId, e); } return null; } REFLECTION
  22. Build environment https://source.android.com/ source/initializing.html

  23. . build/envsetup.sh Setting up the build environment Check for missing

    dependencies
  24. lunch Choose the target product and build variant • eng

    • usrdebug • release
  25. make make -jX X = # of working thread export

    USE_CCACHE=1
  26. mm make alias for single projects m = make from

    the top of the tree mm = make from the current directory mmm = make from the given directory mmma = make from the given directory WITH dependencies
  27. Build for devices Additional proprietary libraries required Placed under vendor/

  28. Install In out/target/product/DEVICE_NAME/ • recovery.img • boot.img • system.img •

    userdata.img
  29. Install adb reboot bootloader fastboot flashall -w

  30. Questions? Daniele Bonaldo on G+

  31. We’re hiring! join@novoda.com