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

android—Compiling with Jack—Jack is a new Android toolchain

2016-06-10 17:56 453 查看
http://source.android.com/source/jack.html

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.Italsoprovidesverygoodcompilationtimesduringsmallcompilations(e.g.inincremental
mode).
Theserverisalsoashort-termsolutiontocontrolthenumberofparallelJackcompilations,andsotoavoidoverloadingyourcomputer(memoryordiskissue),becauseitlimitsthenumberofparallelcompilations.
TheJackservershutsitselfdownafteranidletimewithoutanycompilation.ItusestwoTCPportsonthelocalhostinterface,andsoisnotavailableexternally.Alltheseparameters(numberofparallelcompilations,timeout,portsnumber,etc)canbemodified
byeditingthe
$HOME/.jack
file.

$HOME/.jackfile

The
$HOME/.jack
filecontainssettingsforJackservervariables,inafullbashsyntax.

Herearetheavailablesettings,withtheirdefinitionsanddefaultvalues:

SERVER=true
EnabletheserverfeatureofJack.

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,thisvariablecanbeoverloadedbyenvironmentvariable.

Jacktroubleshooting

IfyourcomputerbecomesunresponsiveduringcompilationorifyouexperienceJackcompilationsfailingon“Outofmemoryerror”

YoucanimprovethesituationbyreducingthenumberofJacksimultaneouscompilationsbyeditingyour
$HOME/.jack
andchanging
SERVER_NB_COMPILE
toalowervalue.

Ifyourcompilationsarefailingon“Cannotlaunchbackgroundserver”

ThemostlikelycauseisTCPportsarealreadyusedonyourcomputer.Trytochangeitbyeditingyour
$HOME/.jack
(
SERVER_PORT_SERVICE
and
SERVER_PORT_ADMIN
variables).

Ifitdoesn’tsolvetheproblem,pleasereportandattachyourcompilationlogandtheJackserverlog(see‘FindingtheJacklog’belowtoknowwheretofindtheserverlogfile).Tounblockthesituation,disablejackcompilationserverbyeditingyour
$HOME/.jack
andchanging
SERVER
tofalse.Unfortunatelythiswillsignificantlyslowdownyourcompilationandmayforceyoutolaunch
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
),andthenbyremovingitstemporarydirectoriescontainedin
jack-$USER
ofyourtemporarydirectory(
/tmp
or
$TMPDIR
).

Ifyouhaveanyotherissues

Toreportbugsorrequestfeatures,pleaseuseourpublicissuetracker,availableat
http://b.android.com,withthe

Jacktoolbugreportor
Jacktoolfeaturerequesttemplates.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.YoucanalsodisabletheJackserverbysettingSERVER=false
inyour$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.Incrementalcompilationcanbesignificantlyfasterthanafullcompilationwhenchangesarelimitedtoonlyalimitedset
ofcomponents.

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"ruletypespleasefileafeaturerequestwithadescriptionofhowyouusethefeatureinyour
app.

Multidexsupport

Sincedexfilesarelimitedto65Kmethods,appswithover65Kmethodsmustbesplitintomultipledexfiles.(See

‘BuildingAppswithOver65KMethods’formoreinformationaboutmultidex.)

Jackoffersnativeandlegacymultidexsupport.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: