android—Compiling with Jack—Jack is a new Android toolchain
2016-06-10 17:56
453 查看
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/.jackfile.
$HOME/.jackfile
The$HOME/.jackfilecontainssettingsforJackservervariables,inafullbashsyntax.
Herearetheavailablesettings,withtheirdefinitionsanddefaultvalues:
SERVER=trueEnabletheserverfeatureofJack.
SERVER_PORT_SERVICE=8072SettheTCPportnumberoftheserverforcompilationpurposes.
SERVER_PORT_ADMIN=8073SettheTCPportnumberoftheserverforadminpurposes.
SERVER_COUNT=1Unusedatpresent.
SERVER_NB_COMPILE=4Maximumnumberofparallelcompilationsallowed.
SERVER_TIMEOUT=60Numberofidlesecondstheserverhastowaitwithoutanycompilationbeforeshuttingitselfdown.
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/.jackandchanging
SERVER_NB_COMPILEtoalowervalue.
Ifyourcompilationsarefailingon“Cannotlaunchbackgroundserver”
ThemostlikelycauseisTCPportsarealreadyusedonyourcomputer.Trytochangeitbyeditingyour
$HOME/.jack(
SERVER_PORT_SERVICEand
SERVER_PORT_ADMINvariables).
Ifitdoesn’tsolvetheproblem,pleasereportandattachyourcompilationlogandtheJackserverlog(see‘FindingtheJacklog’belowtoknowwheretofindtheserverlogfile).Tounblockthesituation,disablejackcompilationserverbyeditingyour
$HOME/.jackandchanging
SERVERtofalse.Unfortunatelythiswillsignificantlyslowdownyourcompilationandmayforceyoutolaunch
make-jwithloadcontrol(option"
-l"of
make).
Ifyourcompilationgetsstuckwithoutanyprogress
Pleasereportthisandgiveusthefollowingadditionalinformation(wherepossible):
Thecommandlineatwhichyouarestuck.
Theoutputofthiscommandline.
Theresultofexecuting
jack-adminserver-stat.
The
$HOME/.jackfile.
Thecontentoftheserverlogwiththeserverstatedumped.Togetthis—
FindtheJackbackgroundserverprocessbyrunning
jack-adminlist-server.
Senda
kill-3commandtothisservertodumpitsstateintothelogfile.
Tolocatetheserverlogfile,see‘FindingtheJacklog’below.
Theresultofexecuting
ls-lR$TMPDIR/jack-$USER.
Theresultofrunning
psj-U$USER.
YoushouldbeabletounblockyourselfbykillingtheJackbackgroundserver(use
jack-adminkill-server),andthenbyremovingitstemporarydirectoriescontainedin
jack-$USERofyourtemporarydirectory(
/tmpor
$TMPDIR).
Ifyouhaveanyotherissues
Toreportbugsorrequestfeatures,pleaseuseourpublicissuetracker,availableat
Jacktoolbugreportor
Jacktoolfeaturerequesttemplates.PleaseattachtheJacklogtothebugreport.
FindingtheJacklog Ifyouranamakecommandwithadisttarget,theJacklogislocatedat $ANDROID_BUILD_TOP/out/dist/logs/jack-server.log Otherwiseyoucanfinditinbyrunning jack-adminserver-log |
$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=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.Incrementalcompilationcanbesignificantlyfasterthanafullcompilationwhenchangesarelimitedtoonlyalimitedsetofcomponents.
Limitations
Incrementalcompilationisdeactivatedwhenshrinking,obfuscation,repackagingormulti-dexlegacyisenabled.Enablingincrementalbuilds
Currentlyincrementalcompilationisnotenabledbydefault.Toenableincrementalbuilds,addthefollowinglinetotheAndroid.mkfileoftheprojectthatyouwanttobuildincrementally:LOCAL_JACK_ENABLED:=incremental
Note:ThefirsttimethatyoubuildyourprojectwithJackifsomedependenciesarenotbuilt,use
mmatobuildthem,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.
相关文章推荐
- android文件下载自动安装或打开
- android中获取布局文件的三种方法
- 【自定义View】01--常用工具介绍
- Android Studio教程(二)之AS的安装和配置目录介绍
- Android Studio教程(一)之AS的安装教程
- Android之GLES2.0显示立方体各面不同图片测试代码2
- 国内技术社区活跃的 Android 大神汇总
- 【Android】Activity入门
- Android View 测量参数
- Android View中重要的回调方法
- android 自定义View基础(1)
- 玩转Android之调试应用
- 玩转Android之如何处理返回按钮
- Splash的实现
- 如何设定Android Activity间切换时的动画
- Android_Service
- 作业——在线学习Android课程之第十五周(设计模式二)
- Android之BLE开发(一)
- 【Android】Intent介绍和使用
- Android configChanges属性