Building My Product On Android Open Source Project Phi Innovations .

Transcription

BuildingMy Product onAndroid Open Source ProjectAndroid Builders Summit 2015Rafael Coutinho - Software EngineerPhi Innovations1

Agenda MotivationBuild System OverviewSimple BuildProduct Customization StructureCreate My Own ProductsSummaryQ&A2

Motivation At work we design hardware, customize the operatingsystem, develop high level applications SoCs based on Freescale (iMX53, iMX6)Texas Instruments (Beaglebones)AllWinner (A20)FriendlyARM (Tiny210) Android basic porting are provided by these vendors However usually not in a standard way3

Motivation Not in a standard way tricks we have found Shell scripts to define the Android variables during build. Shell scripts copied to the build that are executed on the init.rc andthen set the actual Android environment variables/configurations.Manually executed commands during build (like for compiling HALs) Provide a pre built tar file with the root file system to be copied overthe final build Hard time figuring out why our customizations do not gothru the build in each provided AOSP porting4

Motivation Looking for AOSP build process documentation wehave found it is scarce and what is available is old orcached versions build/core/build-system.html - Starts with “Status: Draft (as of May 18, 2006)”KAndroid website with cached old version of the Android buildEmbedded Android book from Karim YaghmourFree electrons training Some ABS previous presentations Usually deep and complete but also complex5

Motivation Describe how to customize an AOSP for a targetproduct using the standard AOSP build mechanisms Making easier to extend/develop ported AOSPs oncustomized boards6

Android Build SystemBuild systems are software tools designed to automate theprocess of program compilation.Google defined a GNU/Make based build system forAndroid Replacing Makefile files with Android.mk New imported modules must have it’s Makefiles “translated” No tool like menuconfig available by default7

Android Build System ArchitectureOriginals at: www.opersys.com/training/embedded-android8

Simple buildExecute the build once (to be fearless)Build combo aosp arm-engSimple build for development targeting emulator9

Simple build source build/envsetup.sh lunchYou're building on LinuxLunch menu. pick a combo:1. aosp arm-eng2. aosp arm64-eng3. aosp mips-engWhich would you like? [aosp arm-eng] make -j16Wait 10

Simple build envsetupenvsetup.shThis script is for setting up the build environment on thecurrent shell adding macros type hmm to list all macros created godir - move to the directory containing a file m, mm, mmm - macros to start a build with different argscgrep - alias to execute grep on c/c filesjgrep - alias to execute grep on java files11

Simple build lunchlunch It lists all the combos available in the currentenvironment to be built By following all vendor/* and device/* folders looking for thevendorsetup.sh files. vendorsetup.sh files actually executes the add lunch combo withparameters12

Simple build combos A build combo are combination of a product to build andthe variant to use. product (TARGET PRODUCT) A product defines how the final Android image is, selecting it’s services, initialization,applications to install etc. For example aosp - for emulators.build variant (TARGET BUILD VARIANT) select the purpose of thisbuild. The options are: user: Includes modules tagged user, usually used for final release.userdebug: Includes modules tagged user or debug. Usually for platform testing.eng: Includes modules tagged user, debug or eng. Usually for development phase.13

Simple build env variableslunch sets env variables used by the build.PATH ANDROID JAVA TOOLCHAIN: PATH: ANDROID BUILD PATHSANDROID EABI meabi-4.4.3/binANDROID TOOLCHAIN ANDROID EABI TOOLCHAINANDROID BUILD TOPaosp-rootANDROID PRODUCT OUTaosp-root/out/target/product/generic (has an alias OUT)TARGET BUILD VARIANTeng,user,userdebugTARGET BUILD TYPEdebug or release14

Simple build outputThe build output is generated in the folder defined by ANDROID PRODUCT OUT usually aosp/outThe output is composed by modules built for the hostsystem and target ones The system image is created in target folder under adirectory named with the target product name aosp/out/target/product/aosp/15

Simple build imagesThe following files (among others) are created: ramdisk.img Contains the root file system of Android, including init.* configuration filesdefault.prop containing the read only properties of this AOSP build/system mounting point system.img Contains the components generated by the AOSP build, including framework, applications, daemons16

Simple build images userdata.img Partition to hold the user data. Usually empty after the build recovery.img, ramdisk-recovery.img basic image partition used to recover user data or even the actualsystem if anything goes wrong.17

Simple build emulator Open emulator for testing Build has set up PATH var to point to anemulator executable.emulator -show-kernel -shell Model numberBuild number18

Product customization structure The aosp-root/device foldercontains the customizations Building procedures and extensions for thetargeted “Android based product” of thisbuild. Devices are grouped by vendor Each device have one or moreproducts and boards.19

Product customization structureProduct main makefiles: AndroidProducts.mk full product name .mk Android.mk AndroidBoard.mk BoardConfig.mk device board name .mk20

Android product makefile AndroidProducts.mk list the products of this vendorsetting the PRODUCT MAKEFILES build variable For instance the device/generic/qemu/AndroidProducts.mkAs reference check build/target/product/AndroidProducts.mk21

Android product makefile A product makefile (full product name .mk) containsthe product properties (name, version etc) and extras likemodules/programs or prebuilt files to be included in thebuild. It could include/inherit from other predefined mk filesfrom build/target/product/ It must define its boards makefile device board name .mkAs reference check build/target/product/22

Android product makefile Product properties PRODUCT NAME : aosp arm PRODUCT DEVICE : generic This is the name that will appear in the lunch combo option. This must match thisproduct folder under devices folder.This must match the device’s sub directory. TARGET DEVICE derives from thisvariable.PRODUCT MODEL : AOSP on ARM Emulator The end-user-visible name for the end product.23

Android product makefile Product files to copyPRODUCT COPY FILES : \ device/sample/etc/apns-conf br.xml:system/etc/apns-conf.xml \ device/ti/panda/media codecs.xml:system/etc/media codecs.xml \ device/ti/panda/init.rc:root/init.rc Forces the copy of those files on the final build24

Android product makefile Modules to be includedPRODUCT PACKAGES \my own service module \CustomGallery \lib4mywifi Defines which modules, besides any inherited (due to the ‘ ’ beforethe equals), we want to include on the build. It could include libs/apps that are only defined underdevice/ my company / my product .25

Android product makefile Overriding frameworks/packages config/layout filesPRODUCT PACKAGE OVERLAYS : device/ my company / my product /overlay Defines a directory that will override the AOSP sources.Avoid changing the frameworks folder directlyThe sub folders must have the same AOSP root structure.device/ my company / my product g.xml26

Android product makefile Common overlayed l config supportAutoRotation config longPressOnPowerBehavior defines if pressing power button show a global actions menu, only power off or donothing.config shortPressOnPowerBehavior Enables auto rotation supportSimilar to above but with other options“Documented” here: https://github.com/android/platform frameworks base/blob/master/core/res/res/values/config.xml27

Android product makefile Common overlayed fault wallpaper.jpg Replaces the default wallpaper with no Wallpaper servicecustomization28

Android product inheritance Inherit to reuse (call inherit-product, (SRC TARGET DIR)/product/full base.mk) Inheriting from full base.mk would define most of the needed baseconfigurations.full base inherits from AllAudio.mk Importing some audios for the systemlocales full.mk Get lists of supported languagesgeneric no telephony.mk Includes apps like Calendar, Music, SettingsBesides includes wpa supplicant29

Android product inheritance Makefile inheritance In order to have the minimal configuration you needembedded.mkbase.mkcore minimal.mkcore.mkgeneric no telephony.mktelephony.mk & aosp base.mkfull base telephony.mkfull base.mk30

Android product inheritance Other important make files emulator.mk Creates the emulator tools for this build.Must be included in the MKs in order to get it created. telephony.mk Includes Dialer and MMS appsInclude the rild (radio interface layer daemon)31

Android.mkIf there is any module is defined underdevices/ my company / my product folder to be built, an Android.mk file is needed to callrecursively the build on the sub folders.32

AndroidBoard.mk“Binds” the Android to the Board Defines the kernel build to use device/lge/mako/AndroidBoard.mk33

BoardConfig.mkConfigures the board (hardware) related parametersUsually in the same product folder, but could be separated:device/ my company / my board /Defined by the PRODUCT DEVICE Boot args for loading kernelTarget CPU, CPU variantPartitions sizesBuild compilation flags34

BoardConfig.mkSimple BoardConfig.mk35

device.mk A device makefile (device board name .mk) containsthe board properties Same variables used by the product makefile but nowmore attached to the board May define this boards overlays DEVICE PACKAGE OVERLAYS It may include any board specific makefilesAs reference check build/target/board/36

Android product makefilefull product .mkdevice board dConfig.mkvendorsetup.sh37

Creating my own product Organization “BossaNova” wants to create an Androidproduct called “Girl Of Ipanema” that runs on the “TomJobim” board. This product basically allows a customer to have a customizedAndroid that has info about Girl Of Ipanema song. Create the organization folder under device folder Create the device folder where the product and boardfiles are located Customize it38

Creating my own productFolders/files structure Create bossanova organization folder Under bossanova Create board mk files device tomjobim.mk mk Products.mkfull girlofipanema.mkCreate script to include this product combo into the lunch menu vendorsetup.sh39

Creating my own productFolders/files content AndroidProducts.mkPRODUCT MAKEFILES : (LOCAL DIR)/full girlofipanema.mk device tomjobim.mkIncludes Emulator’s make fileinclude (SRC TARGET DIR)/product/emulator.mkDefine this devices overlay directory (Just wallpaper replacement)DEVICE PACKAGE OVERLAYS : base/core/res/res/drawable-nodpi/default wallpaper.jpg40

Creating my own productFolders/files content BoardConfig.mk Pretty much the emulator’s oneReducing the size of userdata partition to 256MBOARD USERDATAIMAGE PARTITION SIZE : 268435456 vendorsetup.sh Added our combos41

Creating my own productFolders/files content full girlofipanema.mkDefine products info (model, name, device )Setting this product overlay defining the launchers wallpaperPRODUCT PACKAGE OVERLAYS : device/bossanova/tomjobim/goi overlaysCustomized config.xml overlayconfig toastDefaultGravity top center horizontalSet the languages to be included in the buildPRODUCT LOCALES : en US pt BR42

Creating my own product buildBuild Girl of Ipanema’s Android for Tom Jobim board source build/envsetup.sh lunchYou're building on LinuxLunch menu. pick a combo:[.]22. full girlofipanema-userdebug23. full girlofipanema-user24. full girlofipanema-engWhich would you like? [aosp arm-eng] 22make -j1643

Emulator44

Create a second product Organization “BossaNova” wants to create anotherAndroid product called “One Note Samba” that runs onthe “Tom Jobim” board. This product comes with a default prebuilt app to playOne Note Samba song repeatedly This is not a phone but a tablet Target market will be Brazil (so default language isportuguese) Change the custom boot animation45

Creating my own productFolders/files structure Under bossanova Create product mk files Update the following files full ate the custom app folder46

Creating my own productFolders/files content AndroidProducts.mkPRODUCT MAKEFILES : \ (LOCAL DIR)/full girlofipanema.mk \ (LOCAL DIR)/full onenotesamba.mk vendorsetup.shAdded our combosadd lunch combo full onenotesamba-userdebugadd lunch combo full onenotesamba-useradd lunch combo full onenotesamba-eng47

Creating my own productFolders/files content full onenotesamba.mkAdd a new package to be included into the build, set the overlay folder andthe tablet characteristicPRODUCT PACKAGES OneNoteSambaPlayerPRODUCT PACKAGE OVERLAYS : device/bossanova/tomjobim/ons overlaysPRODUCT CHARACTERISTICS : tabletPRODUCT COPY FILES /media/bootanimation.zip48

Creating my own productFolders/files content full onenotesamba.mkCustomized config.xml overlay (setting toast to be in the center)config toastDefaultGravity center vertical center horizontalSet portuguese to be the default languagePRODUCT LOCALES : pt BR en US49

Adding a prebuilt appCreate a directory under tomjobim pCopy the pre built apk file into itCreate the Android.mk for describing how to build it50

Adding a prebuilt appAndroid.mkLOCAL PATH : (call my-dir)include (CLEAR VARS)# Module name should match apk name to be installed.LOCAL MODULE : OneNoteSambaPlayerLOCAL SRC FILES : (LOCAL MODULE).apkLOCAL MODULE CLASS : APPSLOCAL MODULE SUFFIX : (COMMON ANDROID PACKAGE SUFFIX)LOCAL CERTIFICATE : PRESIGNEDinclude (BUILD PREBUILT)51

Summary AOSP build system has standards mechanisms to allowcustomizations Following them is important to allow others to expandand customize your device However its documentation is mostly by reading thecode52

ReferencesEmbedded Android, Karim J. Yaghmour - www.opersys.com/training/embedded-androidFree electrons training - free-electrons.com/training/androidJelly Bean Device Porting Walk through, Benjamin Zores, ABS 2013 lkthroughZip File with Device Folder - phiinnovations.com/files/bossanova.zipPhi Innovations - www.phiinnovations.com53

Q&A* Now Later rafael.coutinho@phiinnovations.com@rafaelcoutinho* possibly there will be an answer54

Shell scripts to define the Android variables during build. Shell scripts copied to the build that are executed on the init.rc and then set the actual Android environment variables/configurations. Manually executed commands during build (like for compiling HALs) Provide a pre built tar file with the root file system to be copied over