您的位置:首页 > 移动开发 > Android开发

android 系统编译要求,官方资料

2016-06-30 11:31 369 查看


Requirements


INTHISDOCUMENT

Hardwarerequirements
Softwarerequirements

Operatingsystem
JavaDevelopmentKit(JDK)
Keypackages
Devicebinaries

BeforeyoudownloadandbuildtheAndroidsource,ensureyoursystemmeetsthefollowingrequirements.ThenseeEstablishing
aBuildEnvironmentforinstallationinstructionsbyoperatingsystem.


Hardwarerequirements

Yourdevelopmentworkstationshouldmeetorexceedthesehardwarerequirements:

A64-bitenvironmentisrequiredforGingerbread(2.3.x)andnewerversions,includingthemasterbranch.Youcancompileolderversionson32-bitsystems.
Atleast100GBoffreediskspaceforacheckout,150GBforasinglebuild,and200GBormoreformultiplebuilds.Ifyouemployccache,youwillneedevenmorespace.

IfyouarerunningLinuxinavirtualmachine,youneedatleast16GBofRAM/swap.


Softwarerequirements

TheAndroidOpenSourceProject(AOSP)
master
branch
istraditionallydevelopedandtestedonUbuntuLongTermSupport(LTS)releases,butotherdistributionsmaybeused.Seethelistbelowforrecommendedversions.
Youworkstationmusthavethesoftwarelistedbelow.SeeEstablishing
aBuildEnvironmentforadditionalrequiredpackagesandthecommandstoinstallthem.


Operatingsystem

AndroidistypicallybuiltwithaGNU/LinuxorMacOSoperatingsystem.ItisalsopossibletobuildAndroidinavirtualmachineonunsupportedsystemssuchasWindows.


GNU/Linux

Android6.0(Marshmallow)-AOSPmaster:Ubuntu14.04(Trusty)
Android2.3.x(Gingerbread)-Android5.x(Lollipop):Ubuntu12.04(Precise)
Android1.5(Cupcake)-Android2.2.x(Froyo):Ubuntu10.04(Lucid)


MacOS(Intel/x86)

Android6.0(Marshmallow)-AOSPmaster:MacOSv10.10(Yosemite)orlaterwithXcode4.5.2andCommandLineTools
Android5.x(Lollipop):MacOSv10.8(MountainLion)withXcode4.5.2andCommandLineTools
Android4.1.x-4.3.x(JellyBean)-Android4.4.x(KitKat):MacOSv10.6(SnowLeopard)orMacOSXv10.7(Lion)andXcode4.2(Apple'sDeveloperTools)
Android1.5(Cupcake)-Android4.0.x(IceCreamSandwich):MacOSv10.5(Leopard)orMacOSXv10.6(SnowLeopard)andtheMacOSXv10.5SDK


JavaDevelopmentKit(JDK)

Pleasenote,sincetherearenoavailablesupportedOpenJDK8packagesforUbuntu14.04,theUbuntu15.04packagesmustbeinstalledmanually.SeeJDK
forUbuntuLTS14.04forpreciseinstructions.

ThemasterbranchofAndroidinAOSP:Ubuntu-OpenJDK8,MacOS-jdk
8u45ornewer
Android5.x(Lollipop)-Android6.0(Marshmallow):Ubuntu-OpenJDK7,MacOS-jdk-7u71-macosx-x64.dmg
Android2.3.x(Gingerbread)-Android4.4.x(KitKat):Ubuntu-Java
JDK6,MacOS-JavaJDK6
Android1.5(Cupcake)-Android2.2.x(Froyo):Ubuntu-JavaJDK5


Keypackages

Python2.6--2.7frompython.org
GNUMake3.81--3.82fromgnu.org;Android3.2.x(Honeycomb)andearlierwillneedtorevert
frommake3.82toavoidbuilderrors
Git1.7ornewerfromgit-scm.com


Devicebinaries

Downloadpreviews,factoryimages,drivers,over-the-air(OTA)updates,andotherblobsbelow.SeeObtaining
proprietarybinariesforadditionaldetails.

Previewbinaries(blobs)-forAOSP
master
branch
development
Factoryimages-forthesupporteddevicesrunningtaggedAOSPreleasebranches
Binaryhardwaresupportfiles-fordevicesrunningtaggedAOSPreleasebranches
OTAimages-formanuallyupdatingNexusdevicesovertheair


EstablishingaBuildEnvironment


INTHISDOCUMENT

ChoosingaBranch
Setting
upaLinuxbuildenvironment

InstallingtheJDK
Installing
requiredpackages(Ubuntu14.04)
Installing
requiredpackages(Ubuntu12.04)
Installing
requiredpackages(Ubuntu10.04--11.10)
ConfiguringUSB
Access
Using
aseparateoutputdirectory

Setting
upaMacOSbuildenvironment

Creating
acase-sensitivediskimage
Installingthe
JDK

Optimizing
abuildenvironment(optional)

Settingupccache

Next:Download
thesource

ThissectiondescribeshowtosetupyourlocalworkenvironmenttobuildtheAndroidsourcefiles.YouwillneedtouseLinuxorMacOS.BuildingunderWindowsisnotcurrentlysupported.
Foranoverviewoftheentirecode-reviewandcode-updateprocess,seeLife
ofaPatch.


ChoosingaBranch

Someoftherequirementsforyourbuildenvironmentaredeterminedbywhichversionofthesourcecodeyouplantocompile.SeeBuild
Numbersforafulllistingofbranchesyoumaychoosefrom.Youmayalsochoosetodownloadandbuildthelatestsourcecode(called
master
),inwhichcaseyouwillsimplyomitthe
branchspecificationwhenyouinitializetherepository.
Onceyouhaveselectedabranch,followtheappropriateinstructionsbelowtosetupyourbuildenvironment.


SettingupaLinuxbuildenvironment

Theseinstructionsapplytoallbranches,including
master
.
TheAndroidbuildisroutinelytestedinhouseonrecentversionsofUbuntuLTS(14.04),butmostdistributionsshouldhavetherequiredbuildtoolsavailable.Reportsofsuccessesorfailuresonotherdistributions
arewelcome.
ForGingerbread(2.3.x)andnewerversions,includingthe
master
branch,a64-bitenvironmentisrequired.Olderversionscanbecompiled
on32-bitsystems.

Note:SeetheRequirementsforthecompletelistofhardwareandsoftwarerequirements.Then
followthedetailedinstructionsforUbuntuandMacOSbelow.


InstallingtheJDK

The
master
branchofAndroidintheAndroid
OpenSourceProject(AOSP)requiresJava8.OnUbuntu,useOpenJDK.
SeeJDKRequirementsforolderversions.


ForUbuntu>=15.04

Runthefollowing:
$sudoapt-getupdate
$sudoapt-getinstallopenjdk-8-jdk


ForUbuntuLTS14.04

TherearenoavailablesupportedOpenJDK8packagesforUbuntu14.04.TheUbuntu15.04OpenJDK8packageshavebeenusedsuccessfullywithUbuntu14.04.Newerpackageversions(e.g.thosefor
15.10,16.04)werefoundnottoworkon14.04usingtheinstructionsbelow.

Downloadthe
.deb
packagesfor64-bitarchitecturefromarchive.ubuntu.com:

openjdk-8-jre-headless_8u45-b14-1_amd64.debwith
SHA256
0f5aba8db39088283b51e00054813063173a4d8809f70033976f83e214ab56c0

openjdk-8-jre_8u45-b14-1_amd64.debwith
SHA256
9ef76c4562d39432b69baf6c18f199707c5c56a5b4566847df908b7d74e15849

openjdk-8-jdk_8u45-b14-1_amd64.debwith
SHA256
6e47215cf6205aa829e6a0a64985075bd29d1f428a4006a80c9db371c2fc3c4c


Optionally,confirmthechecksumsofthedownloadedfilesagainsttheSHA256stringlistedwitheachpackageabove.
Forexample,withthe
sha256sum
tool:
$sha256sum{downloaded.debfile}


Installthepackages:
$sudoapt-getupdate

Run
dpkg
foreachofthe.debfilesyoudownloaded.Itmayproduceerrorsduetomissingdependencies:
$sudodpkg-i{downloaded.debfile}

Tofixmissingdependencies:
$sudoapt-get-finstall



UpdatethedefaultJavaversion-optional

Optionally,fortheUbuntuversionsaboveupdatethedefaultJavaversionbyrunning:
$sudoupdate-alternatives--configjava
$sudoupdate-alternatives--configjavac

If,duringabuild,youencounterversionerrorsforJava,setitspathasdescribedintheWrong
JavaVersionsection.


Installingrequiredpackages(Ubuntu14.04)

Youwillneeda64-bitversionofUbuntu.Ubuntu14.04isrecommended.
$sudoapt-getinstallgit-coregnupgflexbisongperfbuild-essential\
zipcurlzlib1g-devgcc-multilibg++-multiliblibc6-dev-i386\
lib32ncurses5-devx11proto-core-devlibx11-devlib32z-devccache\
libgl1-mesa-devlibxml2-utilsxsltprocunzip


Note:TouseSELinuxtoolsforpolicyanalysis,alsoinstallthe
python-networkx
package.


Installingrequiredpackages(Ubuntu12.04)

YoumayuseUbuntu12.04tobuildolderversionsofAndroid.Version12.04isnotsupportedonmasterorrecentreleases.
$sudoapt-getinstallgitgnupgflexbisongperfbuild-essential\
zipcurllibc6-devlibncurses5-dev:i386x11proto-core-dev\
libx11-dev:i386libreadline6-dev:i386libgl1-mesa-glx:i386\
libgl1-mesa-devg++-multilibmingw32tofrodos\
python-markdownlibxml2-utilsxsltproczlib1g-dev:i386
$sudoln-s/usr/lib/i386-linux-gnu/mesa/libGL.so.1/usr/lib/i386-linux-gnu/libGL.so


Installingrequiredpackages(Ubuntu10.04--11.10)

BuildingonUbuntu10.04-11.10isnolongersupported,butmaybeusefulforbuildingolderreleasesofAOSP.
$sudoapt-getinstallgitgnupgflexbisongperfbuild-essential\
zipcurlzlib1g-devlibc6-devlib32ncurses5-devia32-libs\
x11proto-core-devlibx11-devlib32readline5-devlib32z-dev\
libgl1-mesa-devg++-multilibmingw32tofrodospython-markdown\
libxml2-utilsxsltproc

OnUbuntu10.10:
$sudoln-s/usr/lib32/mesa/libGL.so.1/usr/lib32/mesa/libGL.so

OnUbuntu11.10:
$sudoapt-getinstalllibx11-dev:i386


ConfiguringUSBAccess

UnderGNU/Linuxsystems(andspecificallyunderUbuntusystems),regularuserscan'tdirectlyaccessUSBdevicesbydefault.Thesystemneedstobeconfiguredtoallowsuchaccess.
Therecommendedapproachistocreateafileat
/etc/udev/rules.d/51-android.rules
(astherootuser).
Todothis,runthefollowingcommandtodownloadthe51-android.rulesfile
attachedtothissite,modifyittoincludeyourusername,andplaceitinthecorrectlocation:
$wget-S-O-http://source.android.com/source/51-android.rules|sed"s/<username>/$USER/"|sudotee>/dev/null/etc/udev/rules.d/51-android.rules;sudoudevadmcontrol--reload-rules

Thosenewrulestakeeffectthenexttimeadeviceispluggedin.Itmightthereforebenecessarytounplugthedeviceandplugitbackintothecomputer.


Usingaseparateoutputdirectory

Bydefault,theoutputofeachbuildisstoredinthe
out/
subdirectoryofthematchingsourcetree.
Onsomemachineswithmultiplestoragedevices,buildsarefasterwhenstoringthesourcefilesandtheoutputonseparatevolumes.Foradditionalperformance,theoutputcanbestoredonafilesystemoptimized
forspeedinsteadofcrashrobustness,sinceallfilescanbere-generatedincaseoffilesystemcorruption.
Tosetthisup,exportthe
OUT_DIR_COMMON_BASE
variabletopointtothelocationwhereyouroutputdirectorieswillbestored.
exportOUT_DIR_COMMON_BASE=<path-to-your-out-directory>

Theoutputdirectoryforeachseparatesourcetreewillbenamedafterthedirectoryholdingthesourcetree.
Forinstance,ifyouhavesourcetreesas
/source/master1
and
/source/master2
and
OUT_DIR_COMMON_BASE
is
setto
/output
,theoutputdirectorieswillbe
/output/master1
and
/output/master2
.
It'simportantinthatcasetonothavemultiplesourcetreesstoredindirectoriesthathavethesamename,asthosewouldendupsharinganoutputdirectory,withunpredictableresults.
ThisisonlysupportedonJellyBean(4.1)andnewer,includingthe
master
branch.


SettingupaMacOSbuildenvironment

Inadefaultinstallation,MacOSrunsonacase-preservingbutcase-insensitivefilesystem.Thistypeoffilesystemisnotsupportedbygitandwillcausesomegitcommands(suchas
git
status
)tobehaveabnormally.Becauseofthis,werecommendthatyoualwaysworkwiththeAOSPsourcefilesonacase-sensitivefilesystem.Thiscanbedonefairlyeasilyusingadiskimage,discussedbelow.
Oncetheproperfilesystemisavailable,buildingthe
master
branchinamodernMacOSenvironmentisverystraightforward.Earlierbranches,
includingICS,requiresomeadditionaltoolsandSDKs.


Creatingacase-sensitivediskimage

Youcancreateacase-sensitivefilesystemwithinyourexistingMacOSenvironmentusingadiskimage.Tocreatetheimage,launchDiskUtilityandselect"NewImage".Asizeof25GBistheminimumtocompletethe
build;largernumbersaremorefuture-proof.Usingsparseimagessavesspacewhileallowingtogrowlaterastheneedarises.Besuretoselect"casesensitive,journaled"asthevolumeformat.
Youcanalsocreateitfromashellwiththefollowingcommand:
#hdiutilcreate-typeSPARSE-fs'Case-sensitiveJournaledHFS+'-size40g~/android.dmg

Thiswillcreatea
.dmg
(orpossiblya
.dmg.sparseimage
)filewhich,
oncemounted,actsasadrivewiththerequiredformattingforAndroiddevelopment.
Ifyouneedalargervolumelater,youcanalsoresizethesparseimagewiththefollowingcommand:
#hdiutilresize-size<new-size-you-want>g~/android.dmg.sparseimage

Foradiskimagenamed
android.dmg
storedinyourhomedirectory,youcanaddhelperfunctionstoyour
~/.bash_profile
:

Tomounttheimagewhenyouexecute
mountAndroid
:

#mounttheandroidfileimage
functionmountAndroid{hdiutilattach~/android.dmg-mountpoint/Volumes/android;}


Note:Ifyoursystemcreateda
.dmg.sparseimage
file,replace
~/android.dmg
with
~/android.dmg.sparseimage
.

Tounmountitwhenyouexecute
umountAndroid
:
#unmounttheandroidfileimage
functionumountAndroid(){hdiutildetach/Volumes/android;}


Onceyou'vemountedthe
android
volume,you'lldoallyourworkthere.Youcanejectit(unmountit)justlikeyouwouldwithanexternal
drive.


InstallingtheJDK

SeeRequirementsfortheversionofJavatousewhendeveloping
variousversionsofAndroid.


Installingrequiredpackages

InstallXcodefromtheAppledevelopersite.IfyouarenotalreadyregisteredasanApple
developer,youwillhavetocreateanAppleIDinordertodownload.

InstallMacPortsfrommacports.org.

Note:Makesurethat
/opt/local/bin
appearsinyourpathbefore
/usr/bin
.If
not,pleaseaddthefollowingtoyour
~/.bash_profile
file:
exportPATH=/opt/local/bin:$PATH


Note:Ifyoudonothavea
.bash_profile
fileinyourhomedirectory,createone.

Getmake,git,andGPGpackagesfromMacPorts:
$POSIXLY_CORRECT=1sudoportinstallgmakelibsdlgitgnupg

IfusingMacOSXv10.4,alsoinstallbison:
$POSIXLY_CORRECT=1sudoportinstallbison



Revertingfrommake3.82

InAndroid4.0.x(IceCreamSandwich)andearlier,abugexistsingmake3.82thatpreventsandroidfrombuilding.Youcaninstallversion3.81usingMacPortswiththesesteps:

Edit
/opt/local/etc/macports/sources.conf
andaddalinethatsays
file:///Users/Shared/dports

abovethersyncline.Thencreatethisdirectory:
$mkdir/Users/Shared/dports


Inthenew
dports
directory,run
$svnco--revision50980http://svn.macports.org/repository/macports/trunk/dports/devel/gmake/devel/gmake/


Createaportindexforyournewlocalrepository:
$portindex/Users/Shared/dports


Finally,installtheoldversionofgmakewith
$sudoportinstallgmake@3.81



Settingafiledescriptorlimit

OnMacOS,thedefaultlimitonthenumberofsimultaneousfiledescriptorsopenistoolowandahighlyparallelbuildprocessmayexceedthislimit.

Toincreasethecap,addthefollowinglinestoyour
~/.bash_profile
:
#setthenumberofopenfilestobe1024
ulimit-S-n1024


Optimizingabuildenvironment(optional)


Settingupccache

Youcanoptionallytellthebuildtousetheccachecompilationtool,whichisacompilercacheforCandC++thatcanhelpmakebuildsfaster.Itisespeciallyusefulforbuildserversandotherhigh-volumeproduction
environments.Ccacheactsasacompilercachethatcanbeusedtospeeduprebuilds.Thisworksverywellifyouuse
makeclean
often,orifyoufrequentlyswitchbetweendifferentbuild
products.

Note:Ifyou'reinsteadconductingincrementalbuilds(suchasanindividualdeveloperratherthanabuildserver),ccachemayslowyourbuildsdownbymakingyoupayforcachemisses.
Touseccache,issuethesecommandsintherootofthesourcetree:
$exportUSE_CCACHE=1
$exportCCACHE_DIR=/<path_of_your_choice>/.ccache
$prebuilts/misc/linux-x86/ccache/ccache-M50G

Thesuggestedcachesizeis50-100G.
Putthefollowinginyour
.bashrc
(orequivalent):
exportUSE_CCACHE=1

Bydefaultthecachewillbestoredin
~/.ccache
.IfyourhomedirectoryisonNFSorsomeothernon-localfilesystem,youwillwanttospecify
thedirectoryinyour
.bashrc
filetoo.
OnMacOS,youshouldreplace
linux-x86
with
darwin-x86
:
$prebuilts/misc/darwin-x86/ccache/ccache-M50G

WhenbuildingIceCreamSandwich(4.0.x)orolder,ccacheisinadifferentlocation:
prebuilt/linux-x86/ccache/ccache-M50G

ThissettingisstoredintheCCACHE_DIRandispersistent.
OnLinux,youcanwatchccachebeingusedbydoingthefollowing:
$watch-n1-dprebuilts/misc/linux-x86/ccache/ccache-s


Next:Downloadthesource

Yourbuildenvironmentisgoodtogo!Proceedtodownloadingthesource.

downloadcode


PreparingtoBuild


INTHISDOCUMENT

Obtainproprietary
binaries

Download
proprietarybinaries
Extractproprietary
binaries
Cleanup

Setupenvironment
Chooseatarget
Buildthecode
Runit!

Flashwithfastboot
EmulateanAndroid
Device

Troubleshooting
CommonBuildErrors

WrongJavaVersion
PythonVersion3
CaseInsensitive
Filesystem
NoUSBPermission

ThefollowinginstructionstobuildtheAndroidsourcetreeapplytoallbranches,including
master
.Thebasicsequenceofbuildcommands
isasfollows:

Note:Ifyou'rebuildingAndroid6.0orlater,pleaseseeCompilingwithJackforinformationonthis
newdefaulttoolchain.


Obtainproprietarybinaries

AOSPcannotbeusedfrompuresourcecodeonlyandrequiresadditionalhardware-relatedproprietarylibrariestorun,suchasforhardwaregraphicsacceleration.SeethesectionsbelowfordownloadlinksandDevice
binariesrequirementsforadditionalresources.


Downloadproprietarybinaries

YoucandownloadofficialbinariesforthesupporteddevicesrunningtaggedAOSPreleasebranchesfromGoogle's
Nexusdriverpage.Thesebinariesaddaccesstoadditionalhardwarecapabilitieswithnon-opensourcecode.ToinsteadbuildtheAOSPmasterbranch,usetheBinaries
PreviewforNexusDevices.Whenbuildingthemasterbranchforadevice,usethebinariesforthemostrecent
numberedreleaseorwiththemostrecentdate.


Extractproprietarybinaries

Eachsetofbinariescomesasaself-extractingscriptinacompressedarchive.Uncompresseacharchive,runtheincludedself-extractingscriptfromtherootofthesourcetree,thenconfirmthatyouagreetothe
termsoftheenclosedlicenseagreement.Thebinariesandtheirmatchingmakefileswillbeinstalledinthe
vendor/
hierarchyofthesourcetree.


Cleanup

Toensurethenewlyinstalledbinariesareproperlytakenintoaccountafterbeingextracted,deletetheexistingoutputofanypreviousbuildusing:
$makeclobber


Setupenvironment

Initializetheenvironmentwiththe
envsetup.sh
script.Notethatreplacing
source
with
.
(a
singledot)savesafewcharacters,andtheshortformismorecommonlyusedindocumentation.
$sourcebuild/envsetup.sh

or
$.build/envsetup.sh


Chooseatarget

Choosewhichtargettobuildwith
lunch
.Theexactconfigurationcanbepassedasanargument.Forexample,thefollowingcommand:
$lunchaosp_arm-eng

referstoacompletebuildfortheemulator,withalldebuggingenabled.
Ifrunwithnoarguments
lunch
willpromptyoutochooseatargetfromthemenu.
Allbuildtargetstaketheform
BUILD-BUILDTYPE
,wherethe
BUILD
is
acodenamereferringtotheparticularfeaturecombination.
TheBUILDTYPEisoneofthefollowing:
BuildtypeUse
userlimitedaccess;suitedforproduction
userdebuglike"user"butwithrootaccessanddebuggability;preferredfordebugging
engdevelopmentconfigurationwithadditionaldebuggingtools
Formoreinformationaboutbuildingforandrunningonactualhardware,seeRunning
Builds.


Buildthecode

Pleasenote,thissectionismerelyasummarytoensuresetupiscomplete.SeeRunning
BuildsfordetailedinstructionsonbuildingAndroid.
Buildeverythingwith
make
.GNUmakecanhandleparalleltaskswitha
-jN
argument,
andit'scommontouseanumberoftasksNthat'sbetween1and2timesthenumberofhardwarethreadsonthecomputerbeingusedforthebuild.Forexample,onadual-E5520machine(2CPUs,4coresperCPU,2threadspercore),thefastestbuildsaremade
withcommandsbetween
make-j16
and
make-j32
.
$make-j4


Runit!

Youcaneitherrunyourbuildonanemulatororflashitonadevice.Pleasenotethatyouhavealreadyselectedyourbuildtargetwith
lunch
,
anditisunlikelyatbesttorunonadifferenttargetthanitwasbuiltfor.

Note:Remembertoobtainproprietarybinariesoryourbuildwill
notbootsuccessfullyonyourtargethardware.Ifyouobtainbinaryblobsatthispointyouwillneedtounpackthem,
makeclobber
andrebuild.


Flashwithfastboot

Toflashadevice,youwillneedtouse
fastboot
,whichshouldbeincludedinyourpathafterasuccessfulbuild.SeeFlashing
adeviceforinstructions.


EmulateanAndroidDevice

Theemulatorisaddedtoyourpathautomaticallybythebuildprocess.Toruntheemulator,type:
$emulator


TroubleshootingCommonBuildErrors


WrongJavaVersion

IfyouareattemptingtobuildaversionofAndroidinconsistentwithyourversionofJava,
make
willabortwithamessagesuchas
************************************************************
Youareattemptingtobuildwiththeincorrectversion
ofjava.

Yourversionis:WRONG_VERSION.
Thecorrectversionis:RIGHT_VERSION.

Pleasefollowthemachinesetupinstructionsathttps://source.android.com/source/initializing.html************************************************************

Thismaybecausedby:

FailingtoinstallthecorrectJDKasspecifiedinJDKRequirements.
AnotherJDKpreviouslyinstalledappearinginyourpath.PrependthecorrectJDKtothebeginningofyourPATHorremovetheproblematicJDK.


PythonVersion3

RepoisbuiltonparticularfunctionalityfromPython2.xandisunfortunatelyincompatiblewithPython3.Inordertouserepo,pleaseinstallPython2.x:
$apt-getinstallpython


CaseInsensitiveFilesystem

IfyouarebuildingonanHFSfilesystemonMacOS,youmayencounteranerrorsuchas
************************************************************
Youarebuildingonacase-insensitivefilesystem.
Pleasemoveyoursourcetreetoacase-sensitivefilesystem.
************************************************************

PleasefollowtheinstructionsinInitializingtheBuildEnvironmentfor
creatingacase-sensitivediskimage.


NoUSBPermission

OnmostLinuxsystems,unprivilegeduserscannotaccessUSBportsbydefault.Ifyouseeapermissiondeniederror,followtheinstructionsInitializing
theBuildEnvironmentforconfiguringUSBaccess.
Ifadbwasalreadyrunningandcannotconnecttothedeviceaftergettingthoserulessetup,itcanbekilledwith
adbkill-server
.That
willcauseadbtorestartwiththenewconfiguration.


CompilingwithJack


INTHISDOCUMENT

TheJacktoolchain
The.jacklibraryformat
Jill
UsingJackin
yourAndroidbuild

$HOME/.jackfile
Jacktroubleshooting
Jacklimitations

UsingJackfeatures

Predexing
Incrementalcompilation
ShrinkingandObfuscation
Repackaging
Multidexsupport


TheJacktoolchain

JackisanewAndroidtoolchainthatcompilesJavasourceintoAndroiddexbytecode.ItreplacesthepreviousAndroidtoolchain,whichconsistsofmultipletools,suchasjavac,ProGuard,jarjar,anddx.
TheJacktoolchainprovidesthefollowingadvantages:

Completelyopensource

AvailableinAOSP;partnersarewelcometocontribute.
Speedscompilationtime

Jackhasspecificsupportstoreducecompilationtime:pre-dexing,incrementalcompilationandaJackcompilationserver.
Handlesshrinking,obfuscation,repackagingandmultidex

UsingaseparatepackagesuchasProGuardisnolongernecessary.



Figure1.Jackoverview


The.jacklibraryformat

Jackhasitsown.jackfileformat,whichcontainsthepre-compileddexcodeforthelibrary,allowingforfastercompilation(pre-dex).



Figure2.Jacklibraryfilecontents


Jill

TheJilltooltranslatestheexisting.jarlibrariesintothenewlibraryformat,asshownbelow.



Figure3.Workflowtoimportanexisting.jarlibrary


UsingJackinyourAndroidbuild

Youdon’thavetodoanythingdifferentlytouseJack—justuseyourstandardmakefilecommandstocompilethetreeoryourproject.JackisthedefaultAndroidbuildtoolchainforM.
ThefirsttimeJackisused,itlaunchesalocalJackcompilationserveronyourcomputer:

Thisserverbringsanintrinsicspeedup,becauseitavoidslaunchinganewhostJREJVM,loadingJackcode,initializingJackandwarminguptheJITateachcompilation.Italsoprovidesverygoodcompilationtimesduringsmall
compilations(e.g.inincrementalmode).
Theserverisalsoashort-termsolutiontocontrolthenumberofparallelJackcompilations,andsotoavoidoverloadingyourcomputer(memoryordiskissue),becauseitlimitsthenumberofparallelcompilations.

TheJackservershutsitselfdownafteranidletimewithoutanycompilation.ItusestwoTCPportsonthelocalhostinterface,andsoisnotavailableexternally.Alltheseparameters(numberofparallelcompilations,
timeout,portsnumber,etc)canbemodifiedbyeditingthe
$HOME/.jack
file.


$HOME/.jackfile

The
$HOME/.jack
filecontainssettingsforJackservervariables,inafullbashsyntax.
Herearetheavailablesettings,withtheirdefinitionsanddefaultvalues:

SERVER=true
Enabletheserverfeatureof
Jack.
SERVER_PORT_SERVICE=8072
SettheTCPportnumberoftheserverforcompilationpurposes.
SERVER_PORT_ADMIN=8073
SettheTCPportnumberoftheserverforadminpurposes.
SERVER_COUNT=1
Unusedatpresent.
SERVER_NB_COMPILE=4
Maximumnumberofparallelcompilationsallowed.
SERVER_TIMEOUT=60
Numberofidlesecondstheserverhastowaitwithoutanycompilationbeforeshuttingitselfdown.
SERVER_LOG=${SERVER_LOG:=$SERVER_DIR/jack-$SERVER_PORT_SERVICE.log}
Filewhereserverlogsarewritten.Bydefault,
thisvariablecanbeoverloadedbyanenvironmentvariable.
JACK_VM_COMMAND=${JACK_VM_COMMAND:=java}
ThedefaultcommandusedtolaunchaJVMonthehost.Bydefault,thisvariable
canbeoverloadedbyenvironmentvariable.


Jacktroubleshooting

IfyourcomputerbecomesunresponsiveduringcompilationorifyouexperienceJackcompilationsfailingon“Outofmemoryerror”
YoucanimprovethesituationbyreducingthenumberofJacksimultaneouscompilationsbyeditingyour
$HOME/.jack
andchanging
SERVER_NB_COMPILE
to
alowervalue.
Ifyourcompilationsarefailingon“Cannotlaunchbackgroundserver”
ThemostlikelycauseisTCPportsarealreadyusedonyourcomputer.Trytochangeitbyeditingyour
$HOME/.jack
(
SERVER_PORT_SERVICE
and
SERVER_PORT_ADMIN
variables).
Ifitdoesn’tsolvetheproblem,pleasereportandattachyourcompilationlogandtheJackserverlog(see‘FindingtheJacklog’belowtoknowwheretofindtheserverlogfile).Tounblockthesituation,disable
jackcompilationserverbyeditingyour
$HOME/.jack
andchanging
SERVER
tofalse.Unfortunatelythiswillsignificantly
slowdownyourcompilationandmayforceyoutolaunch
make-j
withloadcontrol(option"
-l
"of
make
).
Ifyourcompilationgetsstuckwithoutanyprogress
Pleasereportthisandgiveusthefollowingadditionalinformation(wherepossible):

Thecommandlineatwhichyouarestuck.
Theoutputofthiscommandline.
Theresultofexecuting
jack-adminserver-stat
.
The
$HOME/.jack
file.
Thecontentoftheserverlogwiththeserverstatedumped.Togetthis—

FindtheJackbackgroundserverprocessbyrunning
jack-adminlist-server
.
Senda
kill-3
commandtothisservertodumpitsstateintothelogfile.
Tolocatetheserverlogfile,see‘FindingtheJacklog’below.

Theresultofexecuting
ls-lR$TMPDIR/jack-$USER.

Theresultofrunning
psj-U$USER.


YoushouldbeabletounblockyourselfbykillingtheJackbackgroundserver(use
jack-adminkill-server
),andthenbyremovingitstemporary
directoriescontainedin
jack-$USER
ofyourtemporarydirectory(
/tmp
or
$TMPDIR
).
Ifyouhaveanyotherissues
Toreportbugsorrequestfeatures,pleaseuseourpublicissuetracker,availableathttp://b.android.com,
withtheJacktoolbugreportorJack
toolfeaturerequesttemplates.PleaseattachtheJacklogtothebugreport.
FindingtheJacklog

Ifyouranamakecommandwithadisttarget,theJacklogislocatedat
$ANDROID_BUILD_TOP/out/dist/logs/jack-server.log

Otherwiseyoucanfinditinbyrunning
jack-adminserver-log


IncaseofreproducibleJackfailures,youcangetamoredetailedlogbysettingonevariable,asfollows:
$exportANDROID_JACK_EXTRA_ARGS="--verbosedebug--sanity-checkson-D
sched.runner=single-threaded"

Thenuseyourstandardmakefilecommandstocompilethetreeoryourprojectandattachitsstandardoutputanderror.
Toremovedetailedbuildlogsuse:
$unsetANDROID_JACK_EXTRA_ARGS


Jacklimitations

TheJackserverismono-userbydefault,socanbeonlyusedbyoneuseronacomputer.Ifitisnotthecase,please,choosedifferentportnumbersforeachuserandadjustSERVER_NB_COMPILEaccordingly.Youcanalsodisable
theJackserverbysettingSERVER=falseinyour$HOME/.jack.
CTScompilationisslowduetocurrentvm-tests-tfintegration.
Bytecodemanipulationtools,likeJaCoCo,arenotsupported.


UsingJackfeatures

JacksupportsJavaprogramminglanguage1.7andintegratesadditionalfeaturesdescribedbelow.


Predexing

WhengeneratingaJacklibraryfile,the.dexofthelibraryisgeneratedandstoredinsidethe.jacklibraryfileasapre-dex.Whencompiling,Jackreusesthepre-dexfromeachlibrary.
Alllibrariesarepre-dexed.



Figure4.Jacklibrarieswithpre-dex


Limitations

Currently,Jackdoesnotreusethelibrarypre-dexifshrinking/obfuscation/repackagingisusedinthecompilation.


Incrementalcompilation

Incrementalcompilationmeansthatonlycomponentsthatweretouchedsincethelastcompilation,andtheirdependencies,arerecompiled.Incrementalcompilationcanbesignificantlyfasterthanafullcompilation
whenchangesarelimitedtoonlyalimitedsetofcomponents.


Limitations

Incrementalcompilationisdeactivatedwhenshrinking,obfuscation,repackagingormulti-dexlegacyisenabled.


Enablingincrementalbuilds

Currentlyincrementalcompilationisnotenabledbydefault.Toenableincrementalbuilds,addthefollowinglinetotheAndroid.mkfileoftheprojectthatyouwanttobuildincrementally:
LOCAL_JACK_ENABLED:=incremental


Note:ThefirsttimethatyoubuildyourprojectwithJackifsomedependenciesarenotbuilt,use
mma
tobuildthem,andafterthatyoucanusethestandardbuildcommand.


ShrinkingandObfuscation

Jackhasshrinkingandobfuscationsupportandusesproguardconfigurationfilestoenableshrinkingandobfuscationfeatures.Herearethesupportedandignoredoptions:


Supportedcommonoptions

Commonoptionsincludethefollowing:

@

-include

-basedirectory

-injars

-outjars//only1outputjarsupported

-libraryjars

-keep

-keepclassmembers

-keepclasseswithmembers

-keepnames

-keepclassmembernames

-keepclasseswithmembernames

-printseeds



Supportedshrinkingoptions

Shrinkingoptionsincludethefollowing:

-dontshrink



Supportedobfuscationoptions

Obfuscationoptionsincludethefollowing:

-dontobfuscate

-printmapping

-applymapping

-obfuscationdictionary

-classobfuscationdictionary

-packageobfuscationdictionary

-useuniqueclassmembernames

-dontusemixedcaseclassnames

-keeppackagenames

-flattenpackagehierarchy

-repackageclasses

-keepattributes

-adaptclassstrings



Ignoredoptions

Ignoredoptionsincludethefollowing:

-dontoptimize//Jackdoesnotoptimize

-dontpreverify//Jackdoesnotpreverify

-skipnonpubliclibraryclasses

-dontskipnonpubliclibraryclasses

-dontskipnonpubliclibraryclassmembers

-keepdirectories

-target

-forceprocessing

-printusage

-whyareyoukeeping

-optimizations

-optimizationpasses

-assumenosideeffects

-allowaccessmodification

-mergeinterfacesaggressively

-overloadaggressively

-microedition

-verbose

-dontnote

-dontwarn

-ignorewarnings

-printconfiguration

-dump


Note:Otheroptionswillgenerateanerror.


Repackaging

Jackusesjarjarconfigurationfilestodotherepackaging.

Note:Jackiscompatiblewith"rule"ruletypes,butisnotcompatiblewith"zap"or"keep"ruletypes.Ifyouneed"zap"or"keep"ruletypespleasefileafeaturerequestwithadescriptionofhowyouusethefeatureinyourapp.


Multidexsupport

Sincedexfilesarelimitedto65Kmethods,appswithover65Kmethodsmustbesplitintomultipledexfiles.(See‘Building
AppswithOver65KMethods’formoreinformationaboutmultidex.)
Jackoffersnativeandlegacymultidexsupport.


SelectingDevices


INTHISDOCUMENT

HiKeyboards
RunningAndroidonHiKey

Compilinguserspace
Installinginitial
fastbootandptable
Flashingimages
Buildingthekernel
Settingmonitorresolution
Configuringkernelserial
output(uart3)

YoucancreatebuildsforNexusdevicesusingAndroidOpenSourceProject(AOSP)buildsandtherelevanthardware-specificbinaries.ForavailableAndroidbuildsandtargetedNexusdevices,seeSource
Code,Tags,andBuilds.

Note:Duetohardwaredifferences,donotuseAndroid4.1.1onaNexus7originallysoldwithAndroid4.1.2ornewer.
YoucanalsocreatebuildsfortheHiKeyAndroidreference
board(describedbelow).Referenceboardsaredesignedtohelpnon-NexuscomponentvendorsdevelopandportdriverstoAndroidreleases.Usingareferenceboardcaneaseupgradeefforts,reducetime-to-marketfornewAndroiddevices,lowerdevicecostsby
enablingODM/OEMstochoosefromawiderrangeofcompatiblecomponents,andincreasethespeedofinnovationamongcomponentsuppliers.


HiKeyboards

GooglesupportsHiKey,acertified96Board,
asanAndroidreferenceboard.AOSPprovideskernelsourceandboardsupportforHiKeytoenabledeveloperstoeasilycreateanddebugnewandexistingperipheraldrivers,dokerneldevelopment,andperformothertaskswithfewerOEMencumbrances.
HiKeyboardsareavailablein1GBRAMand2GB
RAMconfigurationsfromLenovator:



Figure1.HiKeyboardbyLenovator
Additionalresources:

HiKeyschematics
HiKeyUserGuide
HiKeywiki


RunningAndroidonHiKey

Usethefollowingcommandstodownload,build,andrunAndroidonaHiKeyboard.


Compilinguserspace

DownloadtheAndroidsourcetree:

$repoinit-uhttps://android.googlesource.com/platform/manifest-bmaster

$reposync-j24


DownloadandextractHDMIbinariesintotheAndroidsourcetree:

$wgethttps://dl.google.com/dl/android/aosp/linaro-hikey-20160226-67c37b1a.tgz

$tarxzflinaro-hikey-20160226-67c37b1a.tgz

$./extract-linaro-hikey.sh


Installmcopyutility:

$apt-getinstallmtools


Build:

$../build/envsetup.sh

$lunchhikey-userdebug

$make-j32


Note:For4GBeMMC,insteadof
$make-j32
use:
$make-j32TARGET_USERDATAIMAGE_4GB=true
.


Installinginitialfastbootandptable

SelectspecialbootloadermodebylinkingJ151-2and3-4pins(fordetails,refertotheHiKey
UserGuide).
ConnectUSBtoPCtogetttyUSBdevice(ex:
/dev/ttyUSB1
).
Powertheboard:

$cddevice/linaro/hikey/installer

$./flash-all.sh/dev/ttyUSB1[4g]


Removejumper3-4andpowertheboard.


Flashingimages

EnterfastbootmodebylinkingJ151-2and5-6pins.
Runthefollowingcommands:

$fastbootflashbootout/target/product/hikey/boot.img

$fastbootflash-wsystemout/target/product/hikey/system.img


Removejumper5-6andpowertheboard.


Buildingthekernel

Runthefollowingcommands:

$gitclonehttps://android.googlesource.com/kernel/hikey-linaro

$cdhikey-linaro

$gitcheckout-bandroid-hikey-linaro-4.4origin/android-hikey-linaro-4.4

$makeARCH=arm64hikey_defconfig

$makeARCH=arm64CROSS_COMPILE=aarch64-linux-android--j24


Copyoutputtothehikeykerneldirectory(
/kernel/hikey-linaro
):

Copyhi6220-hikey.dtb(
arch/arm64/boot/dts/hisilicon/hi6220-hikey.dtb
)tothehikey-kerneldirectory.
CopytheImagefile
(arch/arm64/boot/Image-dtb
)tothehikey-kerneldirectory.
Makethebootimage:
$makebootimage-j24



Settingmonitorresolution

Edit
device/linaro/hikey/BoardConfig.mk
parameter
BOARD_KERNEL_CMDLINE
and
configurethe
video
setting.Examplesettingfora24"monitor:
video=HDMI-A-1:1280x800@60
.


Configuringkernelserialoutput(uart3)

SettheJ2lowspeedexpansionconnectorto1-Gnd,11-Rx,13-Tx.Fordetails,refertotheHiKey
UserGuide).


RunningBuilds


INTHISDOCUMENT

Buildingfastboot
andadb
Bootingintofastboot
mode
Unlockingthebootloader
Selectingadevicebuild
Flashingadevice
Restoring
devicestofactorystate

ThispageprovidesdetailsforrunningbuildsonspecificdevicesandisdesignedtocomplementtheinformationinBuilding
theSystem.


Buildingfastbootandadb

Ifyoudon'talreadyhavefastbootandadb,youcanbuildthemwiththeregularbuildsystem.UsetheinstructionsinBuilding
aSystemandreplacethemain
make
commandwith:
$makefastbootadb


Bootingintofastbootmode

Duringacoldbootofadevice,usethefollowingkeycombinationstobootintofastbootmode,whichisamodeinthebootloaderthatcanbeusedtoflashthedevice:
DeviceKeys
hikeyLinkpins1-2and5-6ofJ15
anglerPressandholdVolumeDown,thenpressandholdPower
bullheadPressandholdVolumeDown,thenpressandholdPower
shamuPressandholdVolumeDown,thenpressandholdPower
fuguPressandholdPower
volantisPressandholdVolumeDown,thenpressandholdPower
hammerheadPressandholdbothVolumeUpandVolumeDown,thenpressandholdPower
floPressandholdVolumeDown,thenpressandholdPower
debPressandholdVolumeDown,thenpressandholdPower
mantaPressandholdbothVolumeUpandVolumeDown,thenpressandholdPower
makoPressandholdVolumeDown,thenpressandholdPower
grouperPressandholdVolumeDown,thenpressandholdPower
tilapiaPressandholdVolumeDown,thenpressandholdPower
phantasmPowerthedevice,coveritwithonehandaftertheLEDslightupanduntiltheyturnred
maguroPressandholdbothVolumeUpandVolumeDown,thenpressandholdPower
toroPressandholdbothVolumeUpandVolumeDown,thenpressandholdPower
toroplusPressandholdbothVolumeUpandVolumeDown,thenpressandholdPower
pandaPressandholdInput,thenpressPower
wingrayPressandholdVolumeDown,thenpressandholdPower
crespoPressandholdVolumeUp,thenpressandholdPower
crespo4gPressandholdVolumeUp,thenpressandholdPower
Youcanalsousethecommand
adbrebootbootloader
torebootfromAndroiddirectlyintothebootloaderwithnokeycombinations.


Unlockingthebootloader

It'spossibletoflashacustomsystemonlyifthebootloaderallowsit,andthebootloaderislockedbydefault.Youcanunlockthebootloader,butbeawarethatdoingsodeletestheuserdataforprivacyreasons
(theunlockoperationneedstorunonlyonce).Afterunlocking,alldataonthedeviceiserased,i.e.boththeapplications'privatedataandtheshareddatathatisaccessibleoverUSB,includingphotosandmovies.Besuretobackupanypreciousfilesbefore
unlockingthebootloader.
Withthedeviceinfastbootmode,unlockthebootloaderusing:
$fastbootoemunlock

Theproceduremustbeconfirmedon-screen.
OnNexus10,afterunlockingthebootloader,theinternalstorageremainsunformatted.Youcanformatthedeviceusing:
$fastbootformatcache
$fastbootformatuserdata

Tore-lockthebootloader,use:
$fastbootoemlock


Note:Re-lockingthebootloadingonaMotoroalXoomerasesuserdata(includingthesharedUSBdata).


Selectingadevicebuild

Therecommendedbuildsfordevicesareavailablefromthelunchmenu,accessedwhenrunningthe
lunch
commandwithnoarguments.Youcandownload
factoryimagesandbinariesforNexusdevicesfromdevelopers.google.com:

Previewbinaries(blobs)
Factoryimagesforreleaseddevices
Supportbinaries(drivers)forreleasedevices

SeeObtainingproprietarybinariesfor
moredetailsandDevicebinariesrequirementsforotherresources.
DeviceCodenameBuildconfiguration
HiKeyhikeyhikey-userdebug
Nexus6Pangleraosp_angler-userdebug
Nexus5Xbullheadaosp_bullhead-userdebug
Nexus6shamuaosp_shamu-userdebug
NexusPlayerfuguaosp_fugu-userdebug
Nexus9volantis(flounder)aosp_flounder-userdebug
Nexus5(GSM/LTE)hammerheadaosp_hammerhead-userdebug
Nexus7(Wi-Fi)razor(flo)aosp_flo-userdebug
Nexus7(Mobile)razorg(deb)aosp_deb-userdebug
Nexus10mantaray(manta)full_manta-userdebug
Nexus4occam(mako)full_mako-userdebug
Nexus7(Wi-Fi)nakasi(grouper)full_grouper-userdebug
Nexus7(Mobile)nakasig(tilapia)full_tilapia-userdebug
GalaxyNexus(GSM/HSPA+)yakju(maguro)full_maguro-userdebug
GalaxyNexus(Verizon)mysid(toro)aosp_toro-userdebug
GalaxyNexus(Experimental)mysidspr(toroplus)aosp_toroplus-userdebug
PandaBoard(Archived)pandaaosp_panda-userdebug
MotorolaXoom(U.S.Wi-Fi)wingrayfull_wingray-userdebug
NexusSsoju(crespo)full_crespo-userdebug
NexusS4Gsojus(crespo4g)full_crespo4g-userdebug
Note:DonotuseAndroid4.1.1onaNexus7originallysoldwithAndroid4.1.2ornewer.


Flashingadevice

YoucanflashanentireAndroidsysteminasinglecommand;doingsoverifiesthesystembeingflashediscompatiblewiththeinstalledbootloaderandradio,writestheboot,recovery,andsystempartitionstogether,
andthenrebootsthesystem.Flashingalsoerasesalluserdata,similarlyto
fastbootoemunlock
.
Placethedeviceinfastbootmodeeithermanuallybyholdingtheappropriatekeycombinationatboot,orfromtheshellwith:
$adbrebootbootloader

Oncethedeviceisinfastbootmode,run:
$fastbootflashall-w

The
-w
optionwipesthe
/data
partitiononthedevice;thisis
usefulforyourfirsttimeflashingaparticulardevicebutisotherwiseunnecessary.

Note:FilesystemscreatedviafastbootonMotorolaXoomdonotfunctionoptimally.Werecommendre-creatingfilesystemsthroughrecovery,using:
$adbrebootrecovery
.
Whileinrecovery,openthemenu(pressPower+VolumeUp),wipethecachepartition,thenwipedata.


Restoringdevicestofactorystate

FactoryimagesforNexus5,Nexus10,Nexus4,NexusQ,Nexus7,GalaxyNexus(GSM/HSPA+"yakju"and"takju",andCDMA/LTE"mysid"and"mysidspr"),NexusS,andNexusS4GareavailablefromGoogle's
factoryimagepage.
FactoryimagesfortheMotorolaXoomaredistributeddirectlybyMotorola.


BuildingKernels


INTHISDOCUMENT

Selecting
akernel
Identifyingkernelversion
Downloadingsources
Downloading
aprebuiltgcc
Buildingthekernel

Thispagedetailshowtobuildonlythekernel.ThefollowinginstructionsassumeyouhavenotdownloadedallofAOSP;ifyouhavealreadydoneso,youcanskipthe
git
clone
stepsexceptthestepthatdownloadsthekernelsources.
Allexamplesinthissectionusethehikeykernel.


Selectingakernel

Thistableliststhenameandlocationsofthekernelsourcesandbinaries:
DeviceBinarylocationSourcelocationBuildconfiguration
hikeydevice/linaro/hikey-kernelkernel/hikey-linarohikey_defconfig
anglerdevice/huawei/angler-kernelkernel/msmangler_defconfig
bullheaddevice/lge/bullhead-kernelkernel/msmbullhead_defconfig
shamudevice/moto/shamu-kernelkernel/msmshamu_defconfig
fugudevice/asus/fugu-kernelkernel/x86_64fugu_defconfig
volantisdevice/htc/flounder-kernelkernel/tegraflounder_defconfig
hammerheaddevice/lge/hammerhead-kernelkernel/msmhammerhead_defconfig
flodevice/asus/flo-kernel/kernelkernel/msmflo_defconfig
debdevice/asus/flo-kernel/kernelkernel/msmflo_defconfig
mantadevice/samsung/manta/kernelkernel/exynosmanta_defconfig
makodevice/lge/mako-kernel/kernelkernel/msmmako_defconfig
grouperdevice/asus/grouper/kernelkernel/tegrategra3_android_defconfig
tilapiadevice/asus/grouper/kernelkernel/tegrategra3_android_defconfig
magurodevice/samsung/tuna/kernelkernel/omaptuna_defconfig
torodevice/samsung/tuna/kernelkernel/omaptuna_defconfig
pandadevice/ti/panda/kernelkernel/omappanda_defconfig
stingraydevice/moto/wingray/kernelkernel/tegrastingray_defconfig
wingraydevice/moto/wingray/kernelkernel/tegrastingray_defconfig
crespodevice/samsung/crespo/kernelkernel/samsungherring_defconfig
crespo4gdevice/samsung/crespo/kernelkernel/samsungherring_defconfig
Afterdeterminingthedeviceprojectyouwanttoworkwith,viewthegitlogforthekernelbinary.Deviceprojectsusetheform
device/<vendor>/<name>
.
$gitclonehttps://android.googlesource.com/kernel/hikey-linaro$cdhikey-linaro
$gitlog--max-count=1kernel

Thecommitmessageforthekernelbinarycontainsapartialgitlogofthekernelsourcesusedtobuildthebinary.Thefirstentryinthelogisthemostrecent(theoneusedtobuildthekernel).Makeanoteof
thecommitmessageasyouwillneeditinalaterstep.


Identifyingkernelversion

Todeterminethekernelversionusedinasystemimage,runthefollowingcommandagainstthekernelfile:
$ddif=kernelbs=1skip=$(LC_ALL=Cgrep-a-b-o$'\x1f\x8b\x08\x00\x00\x00\x00\x00'kernel|cut-d':'-f1)|zgrep-a'Linuxversion'

ForNexus5(hammerhead),thecommandis:
$ddif=zImage-dtbbs=1skip=$(LC_ALL=Cod-Ad-x-w2zImage-dtb|grep8b1f|cut-d''-f1|head-1)|zgrep-a'Linuxversion'


Downloadingsources

Downloadthesourceforthekernelyouwanttobuildusingtheappropriate
gitclone
command:
$gitclonehttps://android.googlesource.com/kernel/common.git$gitclonehttps://android.googlesource.com/kernel/hikey-linaro$gitclonehttps://android.googlesource.com/kernel/x86_64.git$gitclonehttps://android.googlesource.com/kernel/exynos.git$gitclonehttps://android.googlesource.com/kernel/goldfish.git$gitclonehttps://android.googlesource.com/kernel/msm.git$gitclonehttps://android.googlesource.com/kernel/omap.git$gitclonehttps://android.googlesource.com/kernel/samsung.git$gitclonehttps://android.googlesource.com/kernel/tegra.git


The
goldfish
projectcontainsthekernelsourcesfortheemulatedplatforms.
The
msm
projecthasthesourcesforADP1,ADP2,NexusOne,Nexus4,Nexus5,Nexus6,Nexus5X,Nexus6P,Nexus7(2013),andcanbeusedasastarting
pointforworkonQualcommMSMchipsets.
The
omap
projectisusedforPandaBoardandGalaxyNexus,andcanbeusedasastartingpointforworkonTIOMAPchipsets.
The
samsung
projectisusedforNexusS,andcanbeusedasastartingpointforworkonSamsungHummingbirdchipsets.
The
tegra
projectisforXoom,Nexus7(2012),Nexus9,andcanbeusedasastartingpointforworkonNVIDIATegrachipsets.
The
exynos
projecthasthekernelsourcesforNexus10,andcanbeusedasastartingpointforworkonSamsungExynoschipsets.
The
x86_64
projecthasthekernelsourcesforNexusPlayer,andcanbeusedasastartingpointforworkonIntelx86_64chipsets.
The
hikey-linaro
projectisusedforHiKeyreferenceboards,andcanbeusedasastartingpointforworkonHiSilicon620chipsets.


Downloadingaprebuiltgcc

Ensuretheprebuilttoolchainisinyourpath:
$exportPATH=$(pwd)/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin:$PATH

or
$exportPATH=$(pwd)/prebuilts/gcc/darwin-x86/arm/arm-eabi-4.6/bin:$PATH

OnaLinuxhost,ifyoudon'thaveanAndroidsourcetree,youcandownloadtheprebuilttoolchainfrom:
$gitclone'target='_blank'>https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6[/code]


Buildingthekernel

Whenyouknowthelastcommitmessageforakernelandhavesuccessfullydownloadedthekernelsourceandprebuiltgcc,youarereadytobuildthekernel.Thefollowingbuildcommandsusethehikeykernel:
$exportARCH=arm64
$exportCROSS_COMPILE=aarch64-linux-android-
$cdhikey-linaro
$gitcheckout-bandroid-hikey-linaro-4.1origin/android-hikey-linaro-4.1
$makehikey_defconfig
$make

Tobuildadifferentkernel,simplyreplace
hikey-linaro
withthenameofthekernelyouwanttobuild.
Theimageoutputstothe
arch/arm64/boot/Image
directory;thekernelbinaryoutputstothe
arch/arm64/boot/dts/hisilicon/hi6220-hikey.dtb
fle.
Copythe
Image
directoryandthe
hi6220-hikey.dtb
filetothe
hikey-kernel
directory.
Alternatively,youcanincludethe
TARGET_PREBUILT_KERNEL
variablewhileusing
make
bootimage
(oranyother
make
commandlinethatbuildsabootimage).Thisvariableissupportedbyalldevicesasitissetupvia
device/common/populate-new-device.sh
.
Forexample:
$exportTARGET_PREBUILT_KERNEL=$your_kernel_path/arch/arm/boot/zImage-dtb


Note:Kernelnamesdifferbydevice.Tolocatethecorrectfilenameforyourkernel,referto
device/<vendor>/<name>
inthekernelsource.


KnownIssues


INTHISDOCUMENT

Buildissues

Missing
CellBroadcastReceiverintorobuilds
Missing
CTSNativeXMLGenerator
BlackGingerbread
Emulator
Emulator
builtonMacOS10.7Liondoesn'twork.
WITH_DEXPREOPT=true
and
emulatorbuilds.
"Permission
Denied"duringbuilds.
Build
errorsrelatedtousingthewrongcompiler.
Build
errorscausedbynon-defaulttoolsettings.
Build
errorwith4.0.xandearlieronMacOS10.7.
Build
erroronMacOSwithXCode4.3.
Build
errorwith4.0.xandearlieronUbuntu11.10.

Sourcesyncissues


Difficulties
syncingthesourcecode(proxyissues).
Difficulties
syncingthesourcetree(VirtualBoxEthernetissues).
Difficulties
syncingthesourcetree(DNSissues).
Difficulties
syncingthesourcetree(TCPissues).

Runtimeissues

Camera
andGPSdon'tworkonGalaxyNexus.

Evenwithourbestcare,smallproblemssometimesslipin.ThispagekeepstrackoftheknownissuesaroundusingtheAndroidsourcecode.


Buildissues


MissingCellBroadcastReceiverintorobuilds

Symptom
OnAOSPbuildsfortoro(uptoJellyBean4.2.1),CellBroadcastReceiverdoesn'tgetincludedinthesystem.

Cause:
There'satypoin
vendor/samsung/toro/device-partial.mk
,where
PRODUCT_PACKAGES
hastheKreplacedbyanH.
Fix:Usethelatestpackagesfor4.2.2,ormanuallyfixthetypo.


MissingCTSNativeXMLGenerator

Symptom:OnsomebuildsofIceCreamSandwichandlater,thefollowingwarningisprintedearlyduringthebuild:
/bin/bash:line
0:cd:cts/tools/cts-native-xml-generator/src/res:Nosuchfileordirectory

Cause:Somemakefilereferencesthatpath,whichdoesn'texist.
Fix:None.Thisisaharmlesswarning.


BlackGingerbreadEmulator

Symptom:Theemulatorbuiltdirectlyfromthegingerbreadbranchdoesn'tstartandstaysstuckonablackscreen.
Cause:ThegingerbreadbranchusesversionR7oftheemulator,whichdoesn'thaveallthefeaturesnecessarytorunrecentversionsofgingerbread.
Fix:UseversionR12oftheemulator,andanewerkernelthatmatchesthosetools.Noneedtodoacleanbuild.
$repoforallplatform/external/qemu-cgitcheckoutaosp/tools_r12
$make
$emulator-kernelprebuilt/android-arm/kernel/kernel-qemu-armv7


EmulatorbuiltonMacOS10.7Liondoesn'twork.

Symptom:Theemulator(anyversion)builtonMacOS10.7Lionand/oronXCode4.xdoesn'tstart.
Cause:Somechangeinthedevelopmentenvironmentcausestheemulatortobecompiledinawaythatpreventsitfromworking.
Fix:UseanemulatorbinaryfromtheSDK,whichisbuiltonMacOS10.6withXCode3andworksonMacOS10.7.


WITH_DEXPREOPT=true
andemulatorbuilds.

Symptom:Whenconductingpartialbuildsorsyncs(makesystemnodependencies)onemulatorbuilds,theresultingbuilddoesn'twork.
Cause:AllemulatorbuildsnowrunDexoptimizationatbuildtimebydefault,whichrequirestofollowalldependenciestore-optimizetheapplicationseachtimetheframeworkchanges.
Fix:LocallydisableDexoptimizationswith
exportWITH_DEXPREOPT=false
,deletetheexistingoptimizedversionswith
make
installclean
andrunafullbuildtore-generatenon-optimizedversions.Afterthat,partialbuildswillwork.


"PermissionDenied"duringbuilds.

Symptom:Allbuildsfailwith"PermissionDenied",possiblyalongwithanti-viruswarnings.
Cause:Someanti-virusprogramsmistakenlyrecognizesomesourcefilesintheAndroidsourcetreeasiftheycontainedviruses.
Fix:Afterverifyingthattherearenoactualvirusesinvolved,disableanti-virusontheAndroidtree.Thishastheaddedbenefitofreducingbuildtimes.


Builderrorsrelatedtousingthewrongcompiler.

Symptom:Thebuildfailswithvarioussymptoms.Onesuchsymptomis
cc1:error:unrecognizedcommandlineoption"-m32"

Cause:TheAndroidbuildsystemusesthedefaultcompilerinthePATH,assumingit'sasuitablecompilertogeneratebinariesthatrunonthehost.Othersituations(e.g.usingtheAndroidNDKor
buildingthekernel)causethedefaultcompilertonotbeahostcompiler.
Fix:Usea"clean"shell,inwhichnopreviousactionscouldhaveswappedthedefaultcompiler.


Builderrorscausedbynon-defaulttoolsettings.

Symptom:Thebuildfailswithvarioussymptoms,possiblycomplainingaboutmissingfilesorfilesthathavethewrongformat.Onesuchsymptomis
member
[...]inarchiveisnotanobject
.
Cause:TheAndroidbuildsystemtendstousemanyhosttoolsandtorelyontheirdefaultbehaviors.Somesettingschangethosetools'behaviorsandmakethembehaveinwaysthatconfusethebuild
system.Variablesknowntocausesuchissuesare
CDPATH
and
GREP_OPTIONS
.
Fix:BuildAndroidinanenvironmentthathasasfewcustomizationsaspossible.


Builderrorwith4.0.xandearlieronMacOS10.7.

Symptom:BuildingIceCreamSandwich4.0.x(andolderversions)failsonMacOS10.7witherrorssimilartothis:
Undefinedsymbols
forarchitecturei386:"_SDL_Init"

Cause:4.0.xisnotcompatiblewithMacOS10.7.
Fix:EitherdowngradetoMacOS10.6,orusethemasterbranch,whichcanbebuiltonMacOS10.7.
$repoinit-bmaster
$reposync


BuilderroronMacOSwithXCode4.3.

Symptom:AllbuildsfailwhenusingXCode4.3.
Cause:XCode4.3switchedthedefaultcompilerfromgcctollvm,andllvmrejectscodethatusedtobeacceptedbygcc.
Fix:UseXCode4.2.


Builderrorwith4.0.xandearlieronUbuntu11.10.

Symptom:BuildingIceCreamSandwich4.0.x(andolderversions)onUbuntu11.10andnewerfailswitherrorssimilartothis:
<command-line>:0:0:
warning:"_FORTIFY_SOURCE"redefined[enabledbydefault]

Cause:Ubuntu11.10usesaversionofgccwherethatsymbolisdefinedbydefault,andAndroidalsodefinesthatsymbol,whichcausesaconflict.
Fix:EitherdowngradetoUbuntu10.04,orusethemasterbranch,whichcanbecompiledonUbuntu11.10andnewer.
$repoinit-bmaster
$reposync


Sourcesyncissues



Difficultiessyncingthesourcecode(proxyissues).

Symptom:
repoinit
or
reposync
failwithhttp
errors,typically403or500.
Cause:Therearequiteafewpossiblecauses,mostoftenrelatedtohttpproxies,whichhavedifficultieshandlingthelargeamountsofdatagettingtransfered.
Fix:Whilethere'snogeneralsolution,usingpython2.7andexplicitlyusing
reposync-j1
havebeenreportedtoimprove
thesituationforsomeusers.


Difficultiessyncingthesourcetree(VirtualBoxEthernetissues).

Symptom:Whenrunning
reposync
insomeVirtualBoxinstallations,theprocesshangsorfailswithavarietyofpossible
symptoms.Onesuchsymptomis
DownloadError:HTTP500(InternalServerError:Servergotitselfintrouble)
.
Cause:ThedefaultnetworkbehaviorofVirtualBoxistouseNAT(NetworkAddressTranslation)toconnecttheguestsystemtothenetwork.Theheavynetworkactivityofreposynctriggerssomecorner
casesintheNATcode.
Fix:ConfigureVirtualBoxtousebridgednetworkinsteadofNAT.


Difficultiessyncingthesourcetree(DNSissues).

Symptom:Whenrunning
reposync
,theprocessfailswithvariouserrorsrelatedtonotrecognizingthehostname.Onesuch
erroris
<urlopenerror[Errno-2]Nameorservicenotknown>
.
Cause:SomeDNSsystemshaveahardtimecopingwiththehighnumberofqueriesinvolvedinsyncingthesourcetree(therecanbeseveralhundredrequestsinaworst-casescenario).
Fix:Manuallyresolvetherelevanthostnames,andhard-codethoseresultslocally.
Youcanresolvethemwiththe
nslookup
command,whichwillgiveyouonenumericalIPaddressforeachofthose(typicallyinthe"Address"
partoftheoutput).
$nslookupgooglesource.com
$nslookupandroid.googlesource.com

Youcanthenhard-codethemlocallybyediting
/etc/hosts
,andaddingtwolinesinthatfile,oftheform:
aaa.bbb.ccc.dddgooglesource.com
eee.fff.ggg.hhhandroid.googlesource.com

Notethatthiswillonlyworkaslongastheservers'addressesdon'tchange,andiftheydoandyoucan'tconnectyou'llhavetoresolvethosehostnamesagainandedit
etc/hosts
accordingly.


Difficultiessyncingthesourcetree(TCPissues).

Symptom:
reposync
hangswhilesyncing,oftenwhenit'scompleted99%ofthesync.
Cause:SomesettingsintheTCP/IPstackcausedifficultiesinsomenetworkenvironments,suchthat
reposync
neithercompletes
norfails.
Fix:Onlinux,
sysctl-wnet.ipv4.tcp_window_scaling=0
.OnMacOS,disabletherfc1323extensioninthenetworksettings.


Runtimeissues


CameraandGPSdon'tworkonGalaxyNexus.

Symptom:CameraandGPSdon'tworkonGalaxyNexus.Asanexample,theCameraapplicationcrashesassoonasit'slaunched.
Cause:Thosehardwareperipheralsrequireproprietarylibrariesthataren'tavailableintheAndroidOpenSourceProject.
Fix:None.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: