java.go 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306
  1. // Copyright 2015 Google Inc. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package java
  15. // This file contains the module types for compiling Java for Android, and converts the properties
  16. // into the flags and filenames necessary to pass to the Module. The final creation of the rules
  17. // is handled in builder.go
  18. import (
  19. "fmt"
  20. "path/filepath"
  21. "strconv"
  22. "strings"
  23. "github.com/google/blueprint"
  24. "github.com/google/blueprint/pathtools"
  25. "github.com/google/blueprint/proptools"
  26. "android/soong/android"
  27. "android/soong/java/config"
  28. "android/soong/tradefed"
  29. )
  30. func init() {
  31. android.RegisterModuleType("java_defaults", defaultsFactory)
  32. android.RegisterModuleType("java_library", LibraryFactory)
  33. android.RegisterModuleType("java_library_static", LibraryStaticFactory)
  34. android.RegisterModuleType("java_library_host", LibraryHostFactory)
  35. android.RegisterModuleType("java_binary", BinaryFactory)
  36. android.RegisterModuleType("java_binary_host", BinaryHostFactory)
  37. android.RegisterModuleType("java_test", TestFactory)
  38. android.RegisterModuleType("java_test_helper_library", TestHelperLibraryFactory)
  39. android.RegisterModuleType("java_test_host", TestHostFactory)
  40. android.RegisterModuleType("java_import", ImportFactory)
  41. android.RegisterModuleType("java_import_host", ImportFactoryHost)
  42. android.RegisterModuleType("java_device_for_host", DeviceForHostFactory)
  43. android.RegisterModuleType("java_host_for_device", HostForDeviceFactory)
  44. android.RegisterModuleType("dex_import", DexImportFactory)
  45. android.RegisterSingletonType("logtags", LogtagsSingleton)
  46. android.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory)
  47. }
  48. func (j *Module) checkPlatformAPI(ctx android.ModuleContext) {
  49. if sc, ok := ctx.Module().(sdkContext); ok {
  50. usePlatformAPI := proptools.Bool(j.deviceProperties.Platform_apis)
  51. if usePlatformAPI != (sc.sdkVersion() == "") {
  52. if usePlatformAPI {
  53. ctx.PropertyErrorf("platform_apis", "platform_apis must be false when sdk_version is not empty.")
  54. } else {
  55. ctx.PropertyErrorf("platform_apis", "platform_apis must be true when sdk_version is empty.")
  56. }
  57. }
  58. }
  59. }
  60. // TODO:
  61. // Autogenerated files:
  62. // Renderscript
  63. // Post-jar passes:
  64. // Proguard
  65. // Rmtypedefs
  66. // DroidDoc
  67. // Findbugs
  68. type CompilerProperties struct {
  69. // list of source files used to compile the Java module. May be .java, .logtags, .proto,
  70. // or .aidl files.
  71. Srcs []string `android:"path,arch_variant"`
  72. // list of source files that should not be used to build the Java module.
  73. // This is most useful in the arch/multilib variants to remove non-common files
  74. Exclude_srcs []string `android:"path,arch_variant"`
  75. // list of directories containing Java resources
  76. Java_resource_dirs []string `android:"arch_variant"`
  77. // list of directories that should be excluded from java_resource_dirs
  78. Exclude_java_resource_dirs []string `android:"arch_variant"`
  79. // list of files to use as Java resources
  80. Java_resources []string `android:"path,arch_variant"`
  81. // list of files that should be excluded from java_resources and java_resource_dirs
  82. Exclude_java_resources []string `android:"path,arch_variant"`
  83. // list of module-specific flags that will be used for javac compiles
  84. Javacflags []string `android:"arch_variant"`
  85. // list of module-specific flags that will be used for kotlinc compiles
  86. Kotlincflags []string `android:"arch_variant"`
  87. // list of of java libraries that will be in the classpath
  88. Libs []string `android:"arch_variant"`
  89. // list of java libraries that will be compiled into the resulting jar
  90. Static_libs []string `android:"arch_variant"`
  91. // manifest file to be included in resulting jar
  92. Manifest *string `android:"path"`
  93. // if not blank, run jarjar using the specified rules file
  94. Jarjar_rules *string `android:"path,arch_variant"`
  95. // If not blank, set the java version passed to javac as -source and -target
  96. Java_version *string
  97. // If set to true, allow this module to be dexed and installed on devices. Has no
  98. // effect on host modules, which are always considered installable.
  99. Installable *bool
  100. // If set to true, include sources used to compile the module in to the final jar
  101. Include_srcs *bool
  102. // If not empty, classes are restricted to the specified packages and their sub-packages.
  103. // This restriction is checked after applying jarjar rules and including static libs.
  104. Permitted_packages []string
  105. // List of modules to use as annotation processors
  106. Plugins []string
  107. // The number of Java source entries each Javac instance can process
  108. Javac_shard_size *int64
  109. // Add host jdk tools.jar to bootclasspath
  110. Use_tools_jar *bool
  111. Openjdk9 struct {
  112. // List of source files that should only be used when passing -source 1.9
  113. Srcs []string `android:"path"`
  114. // List of javac flags that should only be used when passing -source 1.9
  115. Javacflags []string
  116. }
  117. // When compiling language level 9+ .java code in packages that are part of
  118. // a system module, patch_module names the module that your sources and
  119. // dependencies should be patched into. The Android runtime currently
  120. // doesn't implement the JEP 261 module system so this option is only
  121. // supported at compile time. It should only be needed to compile tests in
  122. // packages that exist in libcore and which are inconvenient to move
  123. // elsewhere.
  124. Patch_module *string `android:"arch_variant"`
  125. Jacoco struct {
  126. // List of classes to include for instrumentation with jacoco to collect coverage
  127. // information at runtime when building with coverage enabled. If unset defaults to all
  128. // classes.
  129. // Supports '*' as the last character of an entry in the list as a wildcard match.
  130. // If preceded by '.' it matches all classes in the package and subpackages, otherwise
  131. // it matches classes in the package that have the class name as a prefix.
  132. Include_filter []string
  133. // List of classes to exclude from instrumentation with jacoco to collect coverage
  134. // information at runtime when building with coverage enabled. Overrides classes selected
  135. // by the include_filter property.
  136. // Supports '*' as the last character of an entry in the list as a wildcard match.
  137. // If preceded by '.' it matches all classes in the package and subpackages, otherwise
  138. // it matches classes in the package that have the class name as a prefix.
  139. Exclude_filter []string
  140. }
  141. Errorprone struct {
  142. // List of javac flags that should only be used when running errorprone.
  143. Javacflags []string
  144. }
  145. Proto struct {
  146. // List of extra options that will be passed to the proto generator.
  147. Output_params []string
  148. }
  149. Instrument bool `blueprint:"mutated"`
  150. // List of files to include in the META-INF/services folder of the resulting jar.
  151. Services []string `android:"path,arch_variant"`
  152. }
  153. type CompilerDeviceProperties struct {
  154. // list of module-specific flags that will be used for dex compiles
  155. Dxflags []string `android:"arch_variant"`
  156. // if not blank, set to the version of the sdk to compile against.
  157. // Defaults to compiling against the current platform.
  158. Sdk_version *string
  159. // if not blank, set the minimum version of the sdk that the compiled artifacts will run against.
  160. // Defaults to sdk_version if not set.
  161. Min_sdk_version *string
  162. // if not blank, set the targetSdkVersion in the AndroidManifest.xml.
  163. // Defaults to sdk_version if not set.
  164. Target_sdk_version *string
  165. // Whether to compile against the platform APIs instead of an SDK.
  166. // If true, then sdk_version must be empty. The value of this field
  167. // is ignored when module's type isn't android_app.
  168. Platform_apis *bool
  169. Aidl struct {
  170. // Top level directories to pass to aidl tool
  171. Include_dirs []string
  172. // Directories rooted at the Android.bp file to pass to aidl tool
  173. Local_include_dirs []string
  174. // directories that should be added as include directories for any aidl sources of modules
  175. // that depend on this module, as well as to aidl for this module.
  176. Export_include_dirs []string
  177. // whether to generate traces (for systrace) for this interface
  178. Generate_traces *bool
  179. // whether to generate Binder#GetTransaction name method.
  180. Generate_get_transaction_name *bool
  181. }
  182. // If true, export a copy of the module as a -hostdex module for host testing.
  183. Hostdex *bool
  184. Target struct {
  185. Hostdex struct {
  186. // Additional required dependencies to add to -hostdex modules.
  187. Required []string
  188. }
  189. }
  190. // If set to true, compile dex regardless of installable. Defaults to false.
  191. Compile_dex *bool
  192. Optimize struct {
  193. // If false, disable all optimization. Defaults to true for android_app and android_test
  194. // modules, false for java_library and java_test modules.
  195. Enabled *bool
  196. // True if the module containing this has it set by default.
  197. EnabledByDefault bool `blueprint:"mutated"`
  198. // If true, optimize for size by removing unused code. Defaults to true for apps,
  199. // false for libraries and tests.
  200. Shrink *bool
  201. // If true, optimize bytecode. Defaults to false.
  202. Optimize *bool
  203. // If true, obfuscate bytecode. Defaults to false.
  204. Obfuscate *bool
  205. // If true, do not use the flag files generated by aapt that automatically keep
  206. // classes referenced by the app manifest. Defaults to false.
  207. No_aapt_flags *bool
  208. // Flags to pass to proguard.
  209. Proguard_flags []string
  210. // Specifies the locations of files containing proguard flags.
  211. Proguard_flags_files []string `android:"path"`
  212. }
  213. // When targeting 1.9 and above, override the modules to use with --system,
  214. // otherwise provides defaults libraries to add to the bootclasspath.
  215. System_modules *string
  216. UncompressDex bool `blueprint:"mutated"`
  217. IsSDKLibrary bool `blueprint:"mutated"`
  218. }
  219. func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool {
  220. return BoolDefault(me.Optimize.Enabled, me.Optimize.EnabledByDefault)
  221. }
  222. // Module contains the properties and members used by all java module types
  223. type Module struct {
  224. android.ModuleBase
  225. android.DefaultableModuleBase
  226. android.ApexModuleBase
  227. android.SdkBase
  228. properties CompilerProperties
  229. protoProperties android.ProtoProperties
  230. deviceProperties CompilerDeviceProperties
  231. // jar file containing header classes including static library dependencies, suitable for
  232. // inserting into the bootclasspath/classpath of another compile
  233. headerJarFile android.Path
  234. // jar file containing implementation classes including static library dependencies but no
  235. // resources
  236. implementationJarFile android.Path
  237. // jar file containing only resources including from static library dependencies
  238. resourceJar android.Path
  239. // args and dependencies to package source files into a srcjar
  240. srcJarArgs []string
  241. srcJarDeps android.Paths
  242. // jar file containing implementation classes and resources including static library
  243. // dependencies
  244. implementationAndResourcesJar android.Path
  245. // output file containing classes.dex and resources
  246. dexJarFile android.Path
  247. // output file that contains classes.dex if it should be in the output file
  248. maybeStrippedDexJarFile android.Path
  249. // output file containing uninstrumented classes that will be instrumented by jacoco
  250. jacocoReportClassesFile android.Path
  251. // output file containing mapping of obfuscated names
  252. proguardDictionary android.Path
  253. // output file of the module, which may be a classes jar or a dex jar
  254. outputFile android.Path
  255. extraOutputFiles android.Paths
  256. exportAidlIncludeDirs android.Paths
  257. logtagsSrcs android.Paths
  258. // installed file for binary dependency
  259. installFile android.Path
  260. // list of .java files and srcjars that was passed to javac
  261. compiledJavaSrcs android.Paths
  262. compiledSrcJars android.Paths
  263. // list of extra progurad flag files
  264. extraProguardFlagFiles android.Paths
  265. // manifest file to use instead of properties.Manifest
  266. overrideManifest android.OptionalPath
  267. // list of SDK lib names that this java moudule is exporting
  268. exportedSdkLibs []string
  269. // list of source files, collected from srcFiles with uniqie java and all kt files,
  270. // will be used by android.IDEInfo struct
  271. expandIDEInfoCompiledSrcs []string
  272. // expanded Jarjar_rules
  273. expandJarjarRules android.Path
  274. // list of additional targets for checkbuild
  275. additionalCheckedModules android.Paths
  276. // Extra files generated by the module type to be added as java resources.
  277. extraResources android.Paths
  278. hiddenAPI
  279. dexpreopter
  280. // list of the xref extraction files
  281. kytheFiles android.Paths
  282. }
  283. func (j *Module) OutputFiles(tag string) (android.Paths, error) {
  284. switch tag {
  285. case "":
  286. return append(android.Paths{j.outputFile}, j.extraOutputFiles...), nil
  287. case ".jar":
  288. return android.Paths{j.implementationAndResourcesJar}, nil
  289. case ".proguard_map":
  290. return android.Paths{j.proguardDictionary}, nil
  291. default:
  292. return nil, fmt.Errorf("unsupported module reference tag %q", tag)
  293. }
  294. }
  295. func (j *Module) DexJarFile() android.Path {
  296. return j.dexJarFile
  297. }
  298. var _ android.OutputFileProducer = (*Module)(nil)
  299. type Dependency interface {
  300. HeaderJars() android.Paths
  301. ImplementationJars() android.Paths
  302. ResourceJars() android.Paths
  303. ImplementationAndResourcesJars() android.Paths
  304. DexJar() android.Path
  305. AidlIncludeDirs() android.Paths
  306. ExportedSdkLibs() []string
  307. SrcJarArgs() ([]string, android.Paths)
  308. BaseModuleName() string
  309. }
  310. type SdkLibraryDependency interface {
  311. SdkHeaderJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths
  312. SdkImplementationJars(ctx android.BaseModuleContext, sdkVersion string) android.Paths
  313. }
  314. type xref interface {
  315. XrefJavaFiles() android.Paths
  316. }
  317. func (j *Module) XrefJavaFiles() android.Paths {
  318. return j.kytheFiles
  319. }
  320. func InitJavaModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) {
  321. android.InitAndroidArchModule(module, hod, android.MultilibCommon)
  322. android.InitDefaultableModule(module)
  323. }
  324. type dependencyTag struct {
  325. blueprint.BaseDependencyTag
  326. name string
  327. }
  328. type jniDependencyTag struct {
  329. blueprint.BaseDependencyTag
  330. target android.Target
  331. }
  332. var (
  333. staticLibTag = dependencyTag{name: "staticlib"}
  334. libTag = dependencyTag{name: "javalib"}
  335. pluginTag = dependencyTag{name: "plugin"}
  336. bootClasspathTag = dependencyTag{name: "bootclasspath"}
  337. systemModulesTag = dependencyTag{name: "system modules"}
  338. frameworkResTag = dependencyTag{name: "framework-res"}
  339. frameworkApkTag = dependencyTag{name: "framework-apk"}
  340. kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
  341. kotlinAnnotationsTag = dependencyTag{name: "kotlin-annotations"}
  342. proguardRaiseTag = dependencyTag{name: "proguard-raise"}
  343. certificateTag = dependencyTag{name: "certificate"}
  344. instrumentationForTag = dependencyTag{name: "instrumentation_for"}
  345. usesLibTag = dependencyTag{name: "uses-library"}
  346. )
  347. func defaultSdkVersion(ctx checkVendorModuleContext) string {
  348. if ctx.SocSpecific() || ctx.DeviceSpecific() {
  349. return "system_current"
  350. }
  351. return ""
  352. }
  353. type checkVendorModuleContext interface {
  354. SocSpecific() bool
  355. DeviceSpecific() bool
  356. }
  357. type sdkDep struct {
  358. useModule, useFiles, useDefaultLibs, invalidVersion bool
  359. modules []string
  360. // The default system modules to use. Will be an empty string if no system
  361. // modules are to be used.
  362. systemModules string
  363. frameworkResModule string
  364. jars android.Paths
  365. aidl android.OptionalPath
  366. noStandardLibs, noFrameworksLibs bool
  367. }
  368. func (s sdkDep) hasStandardLibs() bool {
  369. return !s.noStandardLibs
  370. }
  371. func (s sdkDep) hasFrameworkLibs() bool {
  372. return !s.noStandardLibs && !s.noFrameworksLibs
  373. }
  374. type jniLib struct {
  375. name string
  376. path android.Path
  377. target android.Target
  378. }
  379. func (j *Module) shouldInstrument(ctx android.BaseModuleContext) bool {
  380. return j.properties.Instrument && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT")
  381. }
  382. func (j *Module) shouldInstrumentStatic(ctx android.BaseModuleContext) bool {
  383. return j.shouldInstrument(ctx) &&
  384. (ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_STATIC") ||
  385. ctx.Config().UnbundledBuild())
  386. }
  387. func (j *Module) sdkVersion() string {
  388. return proptools.StringDefault(j.deviceProperties.Sdk_version, defaultSdkVersion(j))
  389. }
  390. func (j *Module) systemModules() string {
  391. return proptools.String(j.deviceProperties.System_modules)
  392. }
  393. func (j *Module) minSdkVersion() string {
  394. if j.deviceProperties.Min_sdk_version != nil {
  395. return *j.deviceProperties.Min_sdk_version
  396. }
  397. return j.sdkVersion()
  398. }
  399. func (j *Module) targetSdkVersion() string {
  400. if j.deviceProperties.Target_sdk_version != nil {
  401. return *j.deviceProperties.Target_sdk_version
  402. }
  403. return j.sdkVersion()
  404. }
  405. func (j *Module) deps(ctx android.BottomUpMutatorContext) {
  406. if ctx.Device() {
  407. sdkDep := decodeSdkDep(ctx, sdkContext(j))
  408. if sdkDep.hasStandardLibs() {
  409. if sdkDep.useDefaultLibs {
  410. ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...)
  411. ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules)
  412. if sdkDep.hasFrameworkLibs() {
  413. ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...)
  414. }
  415. } else if sdkDep.useModule {
  416. ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
  417. ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
  418. if j.deviceProperties.EffectiveOptimizeEnabled() {
  419. ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...)
  420. ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...)
  421. }
  422. }
  423. } else if sdkDep.systemModules != "" {
  424. // Add the system modules to both the system modules and bootclasspath.
  425. ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
  426. ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.systemModules)
  427. }
  428. if ctx.ModuleName() == "android_stubs_current" ||
  429. ctx.ModuleName() == "android_system_stubs_current" ||
  430. ctx.ModuleName() == "android_test_stubs_current" {
  431. ctx.AddVariationDependencies(nil, frameworkApkTag, "framework-res")
  432. }
  433. }
  434. ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
  435. ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
  436. ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...)
  437. android.ProtoDeps(ctx, &j.protoProperties)
  438. if j.hasSrcExt(".proto") {
  439. protoDeps(ctx, &j.protoProperties)
  440. }
  441. if j.hasSrcExt(".kt") {
  442. // TODO(ccross): move this to a mutator pass that can tell if generated sources contain
  443. // Kotlin files
  444. ctx.AddVariationDependencies(nil, kotlinStdlibTag,
  445. "kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8")
  446. if len(j.properties.Plugins) > 0 {
  447. ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
  448. }
  449. }
  450. if j.shouldInstrumentStatic(ctx) {
  451. ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent")
  452. }
  453. }
  454. func hasSrcExt(srcs []string, ext string) bool {
  455. for _, src := range srcs {
  456. if filepath.Ext(src) == ext {
  457. return true
  458. }
  459. }
  460. return false
  461. }
  462. func (j *Module) hasSrcExt(ext string) bool {
  463. return hasSrcExt(j.properties.Srcs, ext)
  464. }
  465. func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath,
  466. aidlIncludeDirs android.Paths) (string, android.Paths) {
  467. aidlIncludes := android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Local_include_dirs)
  468. aidlIncludes = append(aidlIncludes,
  469. android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)...)
  470. aidlIncludes = append(aidlIncludes,
  471. android.PathsForSource(ctx, j.deviceProperties.Aidl.Include_dirs)...)
  472. var flags []string
  473. var deps android.Paths
  474. if aidlPreprocess.Valid() {
  475. flags = append(flags, "-p"+aidlPreprocess.String())
  476. deps = append(deps, aidlPreprocess.Path())
  477. } else if len(aidlIncludeDirs) > 0 {
  478. flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I"))
  479. }
  480. if len(j.exportAidlIncludeDirs) > 0 {
  481. flags = append(flags, android.JoinWithPrefix(j.exportAidlIncludeDirs.Strings(), "-I"))
  482. }
  483. if len(aidlIncludes) > 0 {
  484. flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I"))
  485. }
  486. flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String())
  487. if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() {
  488. flags = append(flags, "-I"+src.String())
  489. }
  490. if Bool(j.deviceProperties.Aidl.Generate_traces) {
  491. flags = append(flags, "-t")
  492. }
  493. if Bool(j.deviceProperties.Aidl.Generate_get_transaction_name) {
  494. flags = append(flags, "--transaction_names")
  495. }
  496. return strings.Join(flags, " "), deps
  497. }
  498. type deps struct {
  499. classpath classpath
  500. bootClasspath classpath
  501. processorPath classpath
  502. processorClasses []string
  503. staticJars android.Paths
  504. staticHeaderJars android.Paths
  505. staticResourceJars android.Paths
  506. aidlIncludeDirs android.Paths
  507. srcs android.Paths
  508. srcJars android.Paths
  509. systemModules *systemModules
  510. aidlPreprocess android.OptionalPath
  511. kotlinStdlib android.Paths
  512. kotlinAnnotations android.Paths
  513. disableTurbine bool
  514. }
  515. func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) {
  516. for _, f := range dep.Srcs() {
  517. if f.Ext() != ".jar" {
  518. ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency",
  519. ctx.OtherModuleName(dep.(blueprint.Module)))
  520. }
  521. }
  522. }
  523. type linkType int
  524. const (
  525. javaCore linkType = iota
  526. javaSdk
  527. javaSystem
  528. javaPlatform
  529. )
  530. func getLinkType(m *Module, name string) (ret linkType, stubs bool) {
  531. ver := m.sdkVersion()
  532. switch {
  533. case name == "core.current.stubs" || name == "core.platform.api.stubs" ||
  534. name == "stub-annotations" || name == "private-stub-annotations-jar" ||
  535. name == "core-lambda-stubs" || name == "core-generated-annotation-stubs":
  536. return javaCore, true
  537. case ver == "core_current":
  538. return javaCore, false
  539. case name == "android_system_stubs_current":
  540. return javaSystem, true
  541. case strings.HasPrefix(ver, "system_"):
  542. return javaSystem, false
  543. case name == "android_test_stubs_current":
  544. return javaSystem, true
  545. case strings.HasPrefix(ver, "test_"):
  546. return javaPlatform, false
  547. case name == "android_stubs_current":
  548. return javaSdk, true
  549. case ver == "current":
  550. return javaSdk, false
  551. case ver == "" || ver == "none" || ver == "core_platform":
  552. return javaPlatform, false
  553. default:
  554. if _, err := strconv.Atoi(ver); err != nil {
  555. panic(fmt.Errorf("expected sdk_version to be a number, got %q", ver))
  556. }
  557. return javaSdk, false
  558. }
  559. }
  560. func checkLinkType(ctx android.ModuleContext, from *Module, to *Library, tag dependencyTag) {
  561. if ctx.Host() {
  562. return
  563. }
  564. myLinkType, stubs := getLinkType(from, ctx.ModuleName())
  565. if stubs {
  566. return
  567. }
  568. otherLinkType, _ := getLinkType(&to.Module, ctx.OtherModuleName(to))
  569. commonMessage := "Adjust sdk_version: property of the source or target module so that target module is built with the same or smaller API set than the source."
  570. switch myLinkType {
  571. case javaCore:
  572. if otherLinkType != javaCore {
  573. ctx.ModuleErrorf("compiles against core Java API, but dependency %q is compiling against non-core Java APIs."+commonMessage,
  574. ctx.OtherModuleName(to))
  575. }
  576. break
  577. case javaSdk:
  578. if otherLinkType != javaCore && otherLinkType != javaSdk {
  579. ctx.ModuleErrorf("compiles against Android API, but dependency %q is compiling against non-public Android API."+commonMessage,
  580. ctx.OtherModuleName(to))
  581. }
  582. break
  583. case javaSystem:
  584. if otherLinkType == javaPlatform {
  585. ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage,
  586. ctx.OtherModuleName(to))
  587. }
  588. break
  589. case javaPlatform:
  590. // no restriction on link-type
  591. break
  592. }
  593. }
  594. func (j *Module) collectDeps(ctx android.ModuleContext) deps {
  595. var deps deps
  596. if ctx.Device() {
  597. sdkDep := decodeSdkDep(ctx, sdkContext(j))
  598. if sdkDep.invalidVersion {
  599. ctx.AddMissingDependencies(sdkDep.modules)
  600. } else if sdkDep.useFiles {
  601. // sdkDep.jar is actually equivalent to turbine header.jar.
  602. deps.classpath = append(deps.classpath, sdkDep.jars...)
  603. deps.aidlPreprocess = sdkDep.aidl
  604. } else {
  605. deps.aidlPreprocess = sdkDep.aidl
  606. }
  607. }
  608. ctx.VisitDirectDeps(func(module android.Module) {
  609. otherName := ctx.OtherModuleName(module)
  610. tag := ctx.OtherModuleDependencyTag(module)
  611. if _, ok := tag.(*jniDependencyTag); ok {
  612. // Handled by AndroidApp.collectAppDeps
  613. return
  614. }
  615. if tag == certificateTag {
  616. // Handled by AndroidApp.collectAppDeps
  617. return
  618. }
  619. if to, ok := module.(*Library); ok {
  620. switch tag {
  621. case bootClasspathTag, libTag, staticLibTag:
  622. checkLinkType(ctx, j, to, tag.(dependencyTag))
  623. }
  624. }
  625. switch dep := module.(type) {
  626. case SdkLibraryDependency:
  627. switch tag {
  628. case libTag:
  629. deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.sdkVersion())...)
  630. // names of sdk libs that are directly depended are exported
  631. j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
  632. case staticLibTag:
  633. ctx.ModuleErrorf("dependency on java_sdk_library %q can only be in libs", otherName)
  634. }
  635. case Dependency:
  636. switch tag {
  637. case bootClasspathTag:
  638. deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars()...)
  639. case libTag, instrumentationForTag:
  640. deps.classpath = append(deps.classpath, dep.HeaderJars()...)
  641. // sdk lib names from dependencies are re-exported
  642. j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
  643. deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
  644. case staticLibTag:
  645. deps.classpath = append(deps.classpath, dep.HeaderJars()...)
  646. deps.staticJars = append(deps.staticJars, dep.ImplementationJars()...)
  647. deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
  648. deps.staticResourceJars = append(deps.staticResourceJars, dep.ResourceJars()...)
  649. // sdk lib names from dependencies are re-exported
  650. j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
  651. deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs()...)
  652. case pluginTag:
  653. if plugin, ok := dep.(*Plugin); ok {
  654. deps.processorPath = append(deps.processorPath, dep.ImplementationAndResourcesJars()...)
  655. if plugin.pluginProperties.Processor_class != nil {
  656. deps.processorClasses = append(deps.processorClasses, *plugin.pluginProperties.Processor_class)
  657. }
  658. deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api)
  659. } else {
  660. ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName)
  661. }
  662. case frameworkApkTag:
  663. if ctx.ModuleName() == "android_stubs_current" ||
  664. ctx.ModuleName() == "android_system_stubs_current" ||
  665. ctx.ModuleName() == "android_test_stubs_current" {
  666. // framework stubs.jar need to depend on framework-res.apk, in order to pull the
  667. // resource files out of there for aapt.
  668. //
  669. // Normally the package rule runs aapt, which includes the resource,
  670. // but we're not running that in our package rule so just copy in the
  671. // resource files here.
  672. deps.staticResourceJars = append(deps.staticResourceJars, dep.(*AndroidApp).exportPackage)
  673. }
  674. case kotlinStdlibTag:
  675. deps.kotlinStdlib = append(deps.kotlinStdlib, dep.HeaderJars()...)
  676. case kotlinAnnotationsTag:
  677. deps.kotlinAnnotations = dep.HeaderJars()
  678. }
  679. case android.SourceFileProducer:
  680. switch tag {
  681. case libTag:
  682. checkProducesJars(ctx, dep)
  683. deps.classpath = append(deps.classpath, dep.Srcs()...)
  684. case staticLibTag:
  685. checkProducesJars(ctx, dep)
  686. deps.classpath = append(deps.classpath, dep.Srcs()...)
  687. deps.staticJars = append(deps.staticJars, dep.Srcs()...)
  688. deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...)
  689. }
  690. default:
  691. switch tag {
  692. case bootClasspathTag:
  693. // If a system modules dependency has been added to the bootclasspath
  694. // then add its libs to the bootclasspath.
  695. sm := module.(*SystemModules)
  696. deps.bootClasspath = append(deps.bootClasspath, sm.headerJars...)
  697. case systemModulesTag:
  698. if deps.systemModules != nil {
  699. panic("Found two system module dependencies")
  700. }
  701. sm := module.(*SystemModules)
  702. if sm.outputDir == nil || len(sm.outputDeps) == 0 {
  703. panic("Missing directory for system module dependency")
  704. }
  705. deps.systemModules = &systemModules{sm.outputDir, sm.outputDeps}
  706. }
  707. }
  708. })
  709. j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
  710. return deps
  711. }
  712. func getJavaVersion(ctx android.ModuleContext, javaVersion string, sdkContext sdkContext) string {
  713. var ret string
  714. v := sdkContext.sdkVersion()
  715. // For PDK builds, use the latest SDK version instead of "current"
  716. if ctx.Config().IsPdkBuild() &&
  717. (v == "" || v == "none" || v == "core_platform" || v == "current") {
  718. sdkVersions := ctx.Config().Get(sdkVersionsKey).([]int)
  719. latestSdkVersion := 0
  720. if len(sdkVersions) > 0 {
  721. latestSdkVersion = sdkVersions[len(sdkVersions)-1]
  722. }
  723. v = strconv.Itoa(latestSdkVersion)
  724. }
  725. sdk, err := sdkVersionToNumber(ctx, v)
  726. if err != nil {
  727. ctx.PropertyErrorf("sdk_version", "%s", err)
  728. }
  729. if javaVersion != "" {
  730. ret = normalizeJavaVersion(ctx, javaVersion)
  731. } else if ctx.Device() && sdk <= 23 {
  732. ret = "1.7"
  733. } else if ctx.Device() && sdk <= 29 || !ctx.Config().TargetOpenJDK9() {
  734. ret = "1.8"
  735. } else if ctx.Device() &&
  736. sdkContext.sdkVersion() != "" &&
  737. sdkContext.sdkVersion() != "none" &&
  738. sdkContext.sdkVersion() != "core_platform" &&
  739. sdk == android.FutureApiLevel {
  740. // TODO(ccross): once we generate stubs we should be able to use 1.9 for sdk_version: "current"
  741. ret = "1.8"
  742. } else {
  743. ret = "1.9"
  744. }
  745. return ret
  746. }
  747. func normalizeJavaVersion(ctx android.ModuleContext, javaVersion string) string {
  748. switch javaVersion {
  749. case "1.6", "6":
  750. return "1.6"
  751. case "1.7", "7":
  752. return "1.7"
  753. case "1.8", "8":
  754. return "1.8"
  755. case "1.9", "9":
  756. return "1.9"
  757. case "10", "11":
  758. ctx.PropertyErrorf("java_version", "Java language levels above 9 are not supported")
  759. return "unsupported"
  760. default:
  761. ctx.PropertyErrorf("java_version", "Unrecognized Java language level")
  762. return "unrecognized"
  763. }
  764. }
  765. func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaBuilderFlags {
  766. var flags javaBuilderFlags
  767. // javaVersion flag.
  768. flags.javaVersion = getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j))
  769. // javac flags.
  770. javacFlags := j.properties.Javacflags
  771. if flags.javaVersion == "1.9" {
  772. javacFlags = append(javacFlags, j.properties.Openjdk9.Javacflags...)
  773. }
  774. if ctx.Config().MinimizeJavaDebugInfo() {
  775. // Override the -g flag passed globally to remove local variable debug info to reduce
  776. // disk and memory usage.
  777. javacFlags = append(javacFlags, "-g:source,lines")
  778. }
  779. if ctx.Config().RunErrorProne() {
  780. if config.ErrorProneClasspath == nil {
  781. ctx.ModuleErrorf("cannot build with Error Prone, missing external/error_prone?")
  782. }
  783. errorProneFlags := []string{
  784. "-Xplugin:ErrorProne",
  785. "${config.ErrorProneChecks}",
  786. }
  787. errorProneFlags = append(errorProneFlags, j.properties.Errorprone.Javacflags...)
  788. flags.errorProneExtraJavacFlags = "${config.ErrorProneFlags} " +
  789. "'" + strings.Join(errorProneFlags, " ") + "'"
  790. flags.errorProneProcessorPath = classpath(android.PathsForSource(ctx, config.ErrorProneClasspath))
  791. }
  792. // classpath
  793. flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
  794. flags.classpath = append(flags.classpath, deps.classpath...)
  795. flags.processorPath = append(flags.processorPath, deps.processorPath...)
  796. flags.processor = strings.Join(deps.processorClasses, ",")
  797. if len(flags.bootClasspath) == 0 && ctx.Host() && flags.javaVersion != "1.9" &&
  798. decodeSdkDep(ctx, sdkContext(j)).hasStandardLibs() &&
  799. inList(flags.javaVersion, []string{"1.6", "1.7", "1.8"}) {
  800. // Give host-side tools a version of OpenJDK's standard libraries
  801. // close to what they're targeting. As of Dec 2017, AOSP is only
  802. // bundling OpenJDK 8 and 9, so nothing < 8 is available.
  803. //
  804. // When building with OpenJDK 8, the following should have no
  805. // effect since those jars would be available by default.
  806. //
  807. // When building with OpenJDK 9 but targeting a version < 1.8,
  808. // putting them on the bootclasspath means that:
  809. // a) code can't (accidentally) refer to OpenJDK 9 specific APIs
  810. // b) references to existing APIs are not reinterpreted in an
  811. // OpenJDK 9-specific way, eg. calls to subclasses of
  812. // java.nio.Buffer as in http://b/70862583
  813. java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME")
  814. flags.bootClasspath = append(flags.bootClasspath,
  815. android.PathForSource(ctx, java8Home, "jre/lib/jce.jar"),
  816. android.PathForSource(ctx, java8Home, "jre/lib/rt.jar"))
  817. if Bool(j.properties.Use_tools_jar) {
  818. flags.bootClasspath = append(flags.bootClasspath,
  819. android.PathForSource(ctx, java8Home, "lib/tools.jar"))
  820. }
  821. }
  822. if j.properties.Patch_module != nil && flags.javaVersion == "1.9" {
  823. // Manually specify build directory in case it is not under the repo root.
  824. // (javac doesn't seem to expand into symbolc links when searching for patch-module targets, so
  825. // just adding a symlink under the root doesn't help.)
  826. patchPaths := ".:" + ctx.Config().BuildDir()
  827. classPath := flags.classpath.FormJavaClassPath("")
  828. if classPath != "" {
  829. patchPaths += ":" + classPath
  830. }
  831. javacFlags = append(javacFlags, "--patch-module="+String(j.properties.Patch_module)+"="+patchPaths)
  832. }
  833. // systemModules
  834. flags.systemModules = deps.systemModules
  835. // aidl flags.
  836. flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs)
  837. if len(javacFlags) > 0 {
  838. // optimization.
  839. ctx.Variable(pctx, "javacFlags", strings.Join(javacFlags, " "))
  840. flags.javacFlags = "$javacFlags"
  841. }
  842. return flags
  843. }
  844. func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
  845. j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs)
  846. deps := j.collectDeps(ctx)
  847. flags := j.collectBuilderFlags(ctx, deps)
  848. if flags.javaVersion == "1.9" {
  849. j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...)
  850. }
  851. srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
  852. if hasSrcExt(srcFiles.Strings(), ".proto") {
  853. flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags)
  854. }
  855. srcFiles = j.genSources(ctx, srcFiles, flags)
  856. srcJars := srcFiles.FilterByExt(".srcjar")
  857. srcJars = append(srcJars, deps.srcJars...)
  858. if aaptSrcJar != nil {
  859. srcJars = append(srcJars, aaptSrcJar)
  860. }
  861. if j.properties.Jarjar_rules != nil {
  862. j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
  863. }
  864. jarName := ctx.ModuleName() + ".jar"
  865. javaSrcFiles := srcFiles.FilterByExt(".java")
  866. var uniqueSrcFiles android.Paths
  867. set := make(map[string]bool)
  868. for _, v := range javaSrcFiles {
  869. if _, found := set[v.String()]; !found {
  870. set[v.String()] = true
  871. uniqueSrcFiles = append(uniqueSrcFiles, v)
  872. }
  873. }
  874. // Collect .java files for AIDEGen
  875. j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, uniqueSrcFiles.Strings()...)
  876. var kotlinJars android.Paths
  877. if srcFiles.HasExt(".kt") {
  878. // user defined kotlin flags.
  879. kotlincFlags := j.properties.Kotlincflags
  880. CheckKotlincFlags(ctx, kotlincFlags)
  881. // If there are kotlin files, compile them first but pass all the kotlin and java files
  882. // kotlinc will use the java files to resolve types referenced by the kotlin files, but
  883. // won't emit any classes for them.
  884. kotlincFlags = append(kotlincFlags, "-no-stdlib")
  885. if ctx.Device() {
  886. kotlincFlags = append(kotlincFlags, "-no-jdk")
  887. }
  888. if len(kotlincFlags) > 0 {
  889. // optimization.
  890. ctx.Variable(pctx, "kotlincFlags", strings.Join(kotlincFlags, " "))
  891. flags.kotlincFlags += "$kotlincFlags"
  892. }
  893. var kotlinSrcFiles android.Paths
  894. kotlinSrcFiles = append(kotlinSrcFiles, uniqueSrcFiles...)
  895. kotlinSrcFiles = append(kotlinSrcFiles, srcFiles.FilterByExt(".kt")...)
  896. // Collect .kt files for AIDEGen
  897. j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.FilterByExt(".kt").Strings()...)
  898. flags.classpath = append(flags.classpath, deps.kotlinStdlib...)
  899. flags.classpath = append(flags.classpath, deps.kotlinAnnotations...)
  900. flags.kotlincClasspath = append(flags.kotlincClasspath, flags.bootClasspath...)
  901. flags.kotlincClasspath = append(flags.kotlincClasspath, flags.classpath...)
  902. if len(flags.processorPath) > 0 {
  903. // Use kapt for annotation processing
  904. kaptSrcJar := android.PathForModuleOut(ctx, "kapt", "kapt-sources.jar")
  905. kotlinKapt(ctx, kaptSrcJar, kotlinSrcFiles, srcJars, flags)
  906. srcJars = append(srcJars, kaptSrcJar)
  907. // Disable annotation processing in javac, it's already been handled by kapt
  908. flags.processorPath = nil
  909. flags.processor = ""
  910. }
  911. kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
  912. kotlinCompile(ctx, kotlinJar, kotlinSrcFiles, srcJars, flags)
  913. if ctx.Failed() {
  914. return
  915. }
  916. // Make javac rule depend on the kotlinc rule
  917. flags.classpath = append(flags.classpath, kotlinJar)
  918. // Jar kotlin classes into the final jar after javac
  919. kotlinJars = append(kotlinJars, kotlinJar)
  920. kotlinJars = append(kotlinJars, deps.kotlinStdlib...)
  921. }
  922. jars := append(android.Paths(nil), kotlinJars...)
  923. // Store the list of .java files that was passed to javac
  924. j.compiledJavaSrcs = uniqueSrcFiles
  925. j.compiledSrcJars = srcJars
  926. enable_sharding := false
  927. if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine {
  928. if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 {
  929. enable_sharding = true
  930. // Formerly, there was a check here that prevented annotation processors
  931. // from being used when sharding was enabled, as some annotation processors
  932. // do not function correctly in sharded environments. It was removed to
  933. // allow for the use of annotation processors that do function correctly
  934. // with sharding enabled. See: b/77284273.
  935. }
  936. j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars)
  937. if ctx.Failed() {
  938. return
  939. }
  940. }
  941. if len(uniqueSrcFiles) > 0 || len(srcJars) > 0 {
  942. var extraJarDeps android.Paths
  943. if ctx.Config().RunErrorProne() {
  944. // If error-prone is enabled, add an additional rule to compile the java files into
  945. // a separate set of classes (so that they don't overwrite the normal ones and require
  946. // a rebuild when error-prone is turned off).
  947. // TODO(ccross): Once we always compile with javac9 we may be able to conditionally
  948. // enable error-prone without affecting the output class files.
  949. errorprone := android.PathForModuleOut(ctx, "errorprone", jarName)
  950. RunErrorProne(ctx, errorprone, uniqueSrcFiles, srcJars, flags)
  951. extraJarDeps = append(extraJarDeps, errorprone)
  952. }
  953. if enable_sharding {
  954. flags.classpath = append(flags.classpath, j.headerJarFile)
  955. shardSize := int(*(j.properties.Javac_shard_size))
  956. var shardSrcs []android.Paths
  957. if len(uniqueSrcFiles) > 0 {
  958. shardSrcs = android.ShardPaths(uniqueSrcFiles, shardSize)
  959. for idx, shardSrc := range shardSrcs {
  960. classes := j.compileJavaClasses(ctx, jarName, idx, shardSrc,
  961. nil, flags, extraJarDeps)
  962. jars = append(jars, classes)
  963. }
  964. }
  965. if len(srcJars) > 0 {
  966. classes := j.compileJavaClasses(ctx, jarName, len(shardSrcs),
  967. nil, srcJars, flags, extraJarDeps)
  968. jars = append(jars, classes)
  969. }
  970. } else {
  971. classes := j.compileJavaClasses(ctx, jarName, -1, uniqueSrcFiles, srcJars, flags, extraJarDeps)
  972. jars = append(jars, classes)
  973. }
  974. if ctx.Failed() {
  975. return
  976. }
  977. }
  978. j.srcJarArgs, j.srcJarDeps = resourcePathsToJarArgs(srcFiles), srcFiles
  979. var includeSrcJar android.WritablePath
  980. if Bool(j.properties.Include_srcs) {
  981. includeSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+".srcjar")
  982. TransformResourcesToJar(ctx, includeSrcJar, j.srcJarArgs, j.srcJarDeps)
  983. }
  984. dirArgs, dirDeps := ResourceDirsToJarArgs(ctx, j.properties.Java_resource_dirs,
  985. j.properties.Exclude_java_resource_dirs, j.properties.Exclude_java_resources)
  986. fileArgs, fileDeps := ResourceFilesToJarArgs(ctx, j.properties.Java_resources, j.properties.Exclude_java_resources)
  987. extraArgs, extraDeps := resourcePathsToJarArgs(j.extraResources), j.extraResources
  988. var resArgs []string
  989. var resDeps android.Paths
  990. resArgs = append(resArgs, dirArgs...)
  991. resDeps = append(resDeps, dirDeps...)
  992. resArgs = append(resArgs, fileArgs...)
  993. resDeps = append(resDeps, fileDeps...)
  994. resArgs = append(resArgs, extraArgs...)
  995. resDeps = append(resDeps, extraDeps...)
  996. if len(resArgs) > 0 {
  997. resourceJar := android.PathForModuleOut(ctx, "res", jarName)
  998. TransformResourcesToJar(ctx, resourceJar, resArgs, resDeps)
  999. j.resourceJar = resourceJar
  1000. if ctx.Failed() {
  1001. return
  1002. }
  1003. }
  1004. var resourceJars android.Paths
  1005. if j.resourceJar != nil {
  1006. resourceJars = append(resourceJars, j.resourceJar)
  1007. }
  1008. if Bool(j.properties.Include_srcs) {
  1009. resourceJars = append(resourceJars, includeSrcJar)
  1010. }
  1011. resourceJars = append(resourceJars, deps.staticResourceJars...)
  1012. if len(resourceJars) > 1 {
  1013. combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName)
  1014. TransformJarsToJar(ctx, combinedJar, "for resources", resourceJars, android.OptionalPath{},
  1015. false, nil, nil)
  1016. j.resourceJar = combinedJar
  1017. } else if len(resourceJars) == 1 {
  1018. j.resourceJar = resourceJars[0]
  1019. }
  1020. if len(deps.staticJars) > 0 {
  1021. jars = append(jars, deps.staticJars...)
  1022. }
  1023. manifest := j.overrideManifest
  1024. if !manifest.Valid() && j.properties.Manifest != nil {
  1025. manifest = android.OptionalPathForPath(android.PathForModuleSrc(ctx, *j.properties.Manifest))
  1026. }
  1027. services := android.PathsForModuleSrc(ctx, j.properties.Services)
  1028. if len(services) > 0 {
  1029. servicesJar := android.PathForModuleOut(ctx, "services", jarName)
  1030. var zipargs []string
  1031. for _, file := range services {
  1032. serviceFile := file.String()
  1033. zipargs = append(zipargs, "-C", filepath.Dir(serviceFile), "-f", serviceFile)
  1034. }
  1035. ctx.Build(pctx, android.BuildParams{
  1036. Rule: zip,
  1037. Output: servicesJar,
  1038. Implicits: services,
  1039. Args: map[string]string{
  1040. "jarArgs": "-P META-INF/services/ " + strings.Join(proptools.NinjaAndShellEscapeList(zipargs), " "),
  1041. },
  1042. })
  1043. jars = append(jars, servicesJar)
  1044. }
  1045. // Combine the classes built from sources, any manifests, and any static libraries into
  1046. // classes.jar. If there is only one input jar this step will be skipped.
  1047. var outputFile android.ModuleOutPath
  1048. if len(jars) == 1 && !manifest.Valid() {
  1049. if moduleOutPath, ok := jars[0].(android.ModuleOutPath); ok {
  1050. // Optimization: skip the combine step if there is nothing to do
  1051. // TODO(ccross): this leaves any module-info.class files, but those should only come from
  1052. // prebuilt dependencies until we support modules in the platform build, so there shouldn't be
  1053. // any if len(jars) == 1.
  1054. outputFile = moduleOutPath
  1055. } else {
  1056. combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
  1057. ctx.Build(pctx, android.BuildParams{
  1058. Rule: android.Cp,
  1059. Input: jars[0],
  1060. Output: combinedJar,
  1061. })
  1062. outputFile = combinedJar
  1063. }
  1064. } else {
  1065. combinedJar := android.PathForModuleOut(ctx, "combined", jarName)
  1066. TransformJarsToJar(ctx, combinedJar, "for javac", jars, manifest,
  1067. false, nil, nil)
  1068. outputFile = combinedJar
  1069. }
  1070. // jarjar implementation jar if necessary
  1071. if j.expandJarjarRules != nil {
  1072. // Transform classes.jar into classes-jarjar.jar
  1073. jarjarFile := android.PathForModuleOut(ctx, "jarjar", jarName)
  1074. TransformJarJar(ctx, jarjarFile, outputFile, j.expandJarjarRules)
  1075. outputFile = jarjarFile
  1076. // jarjar resource jar if necessary
  1077. if j.resourceJar != nil {
  1078. resourceJarJarFile := android.PathForModuleOut(ctx, "res-jarjar", jarName)
  1079. TransformJarJar(ctx, resourceJarJarFile, j.resourceJar, j.expandJarjarRules)
  1080. j.resourceJar = resourceJarJarFile
  1081. }
  1082. if ctx.Failed() {
  1083. return
  1084. }
  1085. }
  1086. // Check package restrictions if necessary.
  1087. if len(j.properties.Permitted_packages) > 0 {
  1088. // Check packages and copy to package-checked file.
  1089. pkgckFile := android.PathForModuleOut(ctx, "package-check.stamp")
  1090. CheckJarPackages(ctx, pkgckFile, outputFile, j.properties.Permitted_packages)
  1091. j.additionalCheckedModules = append(j.additionalCheckedModules, pkgckFile)
  1092. if ctx.Failed() {
  1093. return
  1094. }
  1095. }
  1096. j.implementationJarFile = outputFile
  1097. if j.headerJarFile == nil {
  1098. j.headerJarFile = j.implementationJarFile
  1099. }
  1100. if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
  1101. if inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
  1102. j.properties.Instrument = true
  1103. }
  1104. }
  1105. if j.shouldInstrument(ctx) {
  1106. outputFile = j.instrument(ctx, flags, outputFile, jarName)
  1107. }
  1108. // merge implementation jar with resources if necessary
  1109. implementationAndResourcesJar := outputFile
  1110. if j.resourceJar != nil {
  1111. jars := android.Paths{j.resourceJar, implementationAndResourcesJar}
  1112. combinedJar := android.PathForModuleOut(ctx, "withres", jarName)
  1113. TransformJarsToJar(ctx, combinedJar, "for resources", jars, manifest,
  1114. false, nil, nil)
  1115. implementationAndResourcesJar = combinedJar
  1116. }
  1117. j.implementationAndResourcesJar = implementationAndResourcesJar
  1118. if ctx.Device() && j.hasCode(ctx) &&
  1119. (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
  1120. // Dex compilation
  1121. var dexOutputFile android.ModuleOutPath
  1122. dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
  1123. if ctx.Failed() {
  1124. return
  1125. }
  1126. // Hidden API CSV generation and dex encoding
  1127. dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile,
  1128. j.deviceProperties.UncompressDex)
  1129. // merge dex jar with resources if necessary
  1130. if j.resourceJar != nil {
  1131. jars := android.Paths{dexOutputFile, j.resourceJar}
  1132. combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
  1133. TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
  1134. false, nil, nil)
  1135. if j.deviceProperties.UncompressDex {
  1136. combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
  1137. TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
  1138. dexOutputFile = combinedAlignedJar
  1139. } else {
  1140. dexOutputFile = combinedJar
  1141. }
  1142. }
  1143. j.dexJarFile = dexOutputFile
  1144. // Dexpreopting
  1145. dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
  1146. j.maybeStrippedDexJarFile = dexOutputFile
  1147. outputFile = dexOutputFile
  1148. if ctx.Failed() {
  1149. return
  1150. }
  1151. } else {
  1152. outputFile = implementationAndResourcesJar
  1153. }
  1154. ctx.CheckbuildFile(outputFile)
  1155. // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
  1156. j.outputFile = outputFile.WithoutRel()
  1157. }
  1158. func (j *Module) compileJavaClasses(ctx android.ModuleContext, jarName string, idx int,
  1159. srcFiles, srcJars android.Paths, flags javaBuilderFlags, extraJarDeps android.Paths) android.WritablePath {
  1160. kzipName := pathtools.ReplaceExtension(jarName, "kzip")
  1161. if idx >= 0 {
  1162. kzipName = strings.TrimSuffix(jarName, filepath.Ext(jarName)) + strconv.Itoa(idx) + ".kzip"
  1163. jarName += strconv.Itoa(idx)
  1164. }
  1165. classes := android.PathForModuleOut(ctx, "javac", jarName)
  1166. TransformJavaToClasses(ctx, classes, idx, srcFiles, srcJars, flags, extraJarDeps)
  1167. if ctx.Config().EmitXrefRules() {
  1168. extractionFile := android.PathForModuleOut(ctx, kzipName)
  1169. emitXrefRule(ctx, extractionFile, idx, srcFiles, srcJars, flags, extraJarDeps)
  1170. j.kytheFiles = append(j.kytheFiles, extractionFile)
  1171. }
  1172. return classes
  1173. }
  1174. // Check for invalid kotlinc flags. Only use this for flags explicitly passed by the user,
  1175. // since some of these flags may be used internally.
  1176. func CheckKotlincFlags(ctx android.ModuleContext, flags []string) {
  1177. for _, flag := range flags {
  1178. flag = strings.TrimSpace(flag)
  1179. if !strings.HasPrefix(flag, "-") {
  1180. ctx.PropertyErrorf("kotlincflags", "Flag `%s` must start with `-`", flag)
  1181. } else if strings.HasPrefix(flag, "-Xintellij-plugin-root") {
  1182. ctx.PropertyErrorf("kotlincflags",
  1183. "Bad flag: `%s`, only use internal compiler for consistency.", flag)
  1184. } else if inList(flag, config.KotlincIllegalFlags) {
  1185. ctx.PropertyErrorf("kotlincflags", "Flag `%s` already used by build system", flag)
  1186. } else if flag == "-include-runtime" {
  1187. ctx.PropertyErrorf("kotlincflags", "Bad flag: `%s`, do not include runtime.", flag)
  1188. } else {
  1189. args := strings.Split(flag, " ")
  1190. if args[0] == "-kotlin-home" {
  1191. ctx.PropertyErrorf("kotlincflags",
  1192. "Bad flag: `%s`, kotlin home already set to default (path to kotlinc in the repo).", flag)
  1193. }
  1194. }
  1195. }
  1196. }
  1197. func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
  1198. deps deps, flags javaBuilderFlags, jarName string, extraJars android.Paths) android.Path {
  1199. var jars android.Paths
  1200. if len(srcFiles) > 0 || len(srcJars) > 0 {
  1201. // Compile java sources into turbine.jar.
  1202. turbineJar := android.PathForModuleOut(ctx, "turbine", jarName)
  1203. TransformJavaToHeaderClasses(ctx, turbineJar, srcFiles, srcJars, flags)
  1204. if ctx.Failed() {
  1205. return nil
  1206. }
  1207. jars = append(jars, turbineJar)
  1208. }
  1209. jars = append(jars, extraJars...)
  1210. // Combine any static header libraries into classes-header.jar. If there is only
  1211. // one input jar this step will be skipped.
  1212. var headerJar android.Path
  1213. jars = append(jars, deps.staticHeaderJars...)
  1214. // we cannot skip the combine step for now if there is only one jar
  1215. // since we have to strip META-INF/TRANSITIVE dir from turbine.jar
  1216. combinedJar := android.PathForModuleOut(ctx, "turbine-combined", jarName)
  1217. TransformJarsToJar(ctx, combinedJar, "for turbine", jars, android.OptionalPath{},
  1218. false, nil, []string{"META-INF/TRANSITIVE"})
  1219. headerJar = combinedJar
  1220. if j.expandJarjarRules != nil {
  1221. // Transform classes.jar into classes-jarjar.jar
  1222. jarjarFile := android.PathForModuleOut(ctx, "turbine-jarjar", jarName)
  1223. TransformJarJar(ctx, jarjarFile, headerJar, j.expandJarjarRules)
  1224. headerJar = jarjarFile
  1225. if ctx.Failed() {
  1226. return nil
  1227. }
  1228. }
  1229. return headerJar
  1230. }
  1231. func (j *Module) instrument(ctx android.ModuleContext, flags javaBuilderFlags,
  1232. classesJar android.Path, jarName string) android.ModuleOutPath {
  1233. specs := j.jacocoModuleToZipCommand(ctx)
  1234. jacocoReportClassesFile := android.PathForModuleOut(ctx, "jacoco-report-classes", jarName)
  1235. instrumentedJar := android.PathForModuleOut(ctx, "jacoco", jarName)
  1236. jacocoInstrumentJar(ctx, instrumentedJar, jacocoReportClassesFile, classesJar, specs)
  1237. j.jacocoReportClassesFile = jacocoReportClassesFile
  1238. return instrumentedJar
  1239. }
  1240. var _ Dependency = (*Module)(nil)
  1241. func (j *Module) HeaderJars() android.Paths {
  1242. if j.headerJarFile == nil {
  1243. return nil
  1244. }
  1245. return android.Paths{j.headerJarFile}
  1246. }
  1247. func (j *Module) ImplementationJars() android.Paths {
  1248. if j.implementationJarFile == nil {
  1249. return nil
  1250. }
  1251. return android.Paths{j.implementationJarFile}
  1252. }
  1253. func (j *Module) DexJar() android.Path {
  1254. return j.dexJarFile
  1255. }
  1256. func (j *Module) ResourceJars() android.Paths {
  1257. if j.resourceJar == nil {
  1258. return nil
  1259. }
  1260. return android.Paths{j.resourceJar}
  1261. }
  1262. func (j *Module) ImplementationAndResourcesJars() android.Paths {
  1263. if j.implementationAndResourcesJar == nil {
  1264. return nil
  1265. }
  1266. return android.Paths{j.implementationAndResourcesJar}
  1267. }
  1268. func (j *Module) AidlIncludeDirs() android.Paths {
  1269. // exportAidlIncludeDirs is type android.Paths already
  1270. return j.exportAidlIncludeDirs
  1271. }
  1272. func (j *Module) ExportedSdkLibs() []string {
  1273. // exportedSdkLibs is type []string
  1274. return j.exportedSdkLibs
  1275. }
  1276. func (j *Module) SrcJarArgs() ([]string, android.Paths) {
  1277. return j.srcJarArgs, j.srcJarDeps
  1278. }
  1279. var _ logtagsProducer = (*Module)(nil)
  1280. func (j *Module) logtags() android.Paths {
  1281. return j.logtagsSrcs
  1282. }
  1283. // Collect information for opening IDE project files in java/jdeps.go.
  1284. func (j *Module) IDEInfo(dpInfo *android.IdeInfo) {
  1285. dpInfo.Deps = append(dpInfo.Deps, j.CompilerDeps()...)
  1286. dpInfo.Srcs = append(dpInfo.Srcs, j.expandIDEInfoCompiledSrcs...)
  1287. dpInfo.SrcJars = append(dpInfo.SrcJars, j.compiledSrcJars.Strings()...)
  1288. dpInfo.Aidl_include_dirs = append(dpInfo.Aidl_include_dirs, j.deviceProperties.Aidl.Include_dirs...)
  1289. if j.expandJarjarRules != nil {
  1290. dpInfo.Jarjar_rules = append(dpInfo.Jarjar_rules, j.expandJarjarRules.String())
  1291. }
  1292. }
  1293. func (j *Module) CompilerDeps() []string {
  1294. jdeps := []string{}
  1295. jdeps = append(jdeps, j.properties.Libs...)
  1296. jdeps = append(jdeps, j.properties.Static_libs...)
  1297. return jdeps
  1298. }
  1299. func (j *Module) hasCode(ctx android.ModuleContext) bool {
  1300. srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs)
  1301. return len(srcFiles) > 0 || len(ctx.GetDirectDepsWithTag(staticLibTag)) > 0
  1302. }
  1303. //
  1304. // Java libraries (.jar file)
  1305. //
  1306. type Library struct {
  1307. Module
  1308. InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths)
  1309. }
  1310. func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool {
  1311. // Store uncompressed (and do not strip) dex files from boot class path jars.
  1312. if inList(ctx.ModuleName(), ctx.Config().BootJars()) {
  1313. return true
  1314. }
  1315. // Store uncompressed dex files that are preopted on /system.
  1316. if !dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, dexpreopter.installPath)) {
  1317. return true
  1318. }
  1319. if ctx.Config().UncompressPrivAppDex() &&
  1320. inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()) {
  1321. return true
  1322. }
  1323. return false
  1324. }
  1325. func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  1326. j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", ctx.ModuleName()+".jar")
  1327. j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
  1328. j.dexpreopter.isInstallable = Bool(j.properties.Installable)
  1329. j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
  1330. j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex
  1331. j.compile(ctx, nil)
  1332. exclusivelyForApex := android.InAnyApex(ctx.ModuleName()) && !j.IsForPlatform()
  1333. if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex {
  1334. var extraInstallDeps android.Paths
  1335. if j.InstallMixin != nil {
  1336. extraInstallDeps = j.InstallMixin(ctx, j.outputFile)
  1337. }
  1338. j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
  1339. ctx.ModuleName()+".jar", j.outputFile, extraInstallDeps...)
  1340. }
  1341. }
  1342. func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
  1343. j.deps(ctx)
  1344. }
  1345. // java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
  1346. //
  1347. // By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were
  1348. // compiled against the device bootclasspath. This jar is not suitable for installing on a device, but can be used
  1349. // as a `static_libs` dependency of another module.
  1350. //
  1351. // Specifying `installable: true` will product a `.jar` file containing `classes.dex` files, suitable for installing on
  1352. // a device.
  1353. //
  1354. // Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
  1355. // compiled against the host bootclasspath.
  1356. func LibraryFactory() android.Module {
  1357. module := &Library{}
  1358. module.AddProperties(
  1359. &module.Module.properties,
  1360. &module.Module.deviceProperties,
  1361. &module.Module.dexpreoptProperties,
  1362. &module.Module.protoProperties)
  1363. InitJavaModule(module, android.HostAndDeviceSupported)
  1364. android.InitApexModule(module)
  1365. android.InitSdkAwareModule(module)
  1366. return module
  1367. }
  1368. // java_library_static is an obsolete alias for java_library.
  1369. func LibraryStaticFactory() android.Module {
  1370. return LibraryFactory()
  1371. }
  1372. // java_library_host builds and links sources into a `.jar` file for the host.
  1373. //
  1374. // A java_library_host has a single variant that produces a `.jar` file containing `.class` files that were
  1375. // compiled against the host bootclasspath.
  1376. func LibraryHostFactory() android.Module {
  1377. module := &Library{}
  1378. module.AddProperties(
  1379. &module.Module.properties,
  1380. &module.Module.protoProperties)
  1381. module.Module.properties.Installable = proptools.BoolPtr(true)
  1382. InitJavaModule(module, android.HostSupported)
  1383. android.InitApexModule(module)
  1384. return module
  1385. }
  1386. //
  1387. // Java Tests
  1388. //
  1389. type testProperties struct {
  1390. // list of compatibility suites (for example "cts", "vts") that the module should be
  1391. // installed into.
  1392. Test_suites []string `android:"arch_variant"`
  1393. // the name of the test configuration (for example "AndroidTest.xml") that should be
  1394. // installed with the module.
  1395. Test_config *string `android:"path,arch_variant"`
  1396. // the name of the test configuration template (for example "AndroidTestTemplate.xml") that
  1397. // should be installed with the module.
  1398. Test_config_template *string `android:"path,arch_variant"`
  1399. // list of files or filegroup modules that provide data that should be installed alongside
  1400. // the test
  1401. Data []string `android:"path"`
  1402. // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
  1403. // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
  1404. // explicitly.
  1405. Auto_gen_config *bool
  1406. }
  1407. type testHelperLibraryProperties struct {
  1408. // list of compatibility suites (for example "cts", "vts") that the module should be
  1409. // installed into.
  1410. Test_suites []string `android:"arch_variant"`
  1411. }
  1412. type Test struct {
  1413. Library
  1414. testProperties testProperties
  1415. testConfig android.Path
  1416. data android.Paths
  1417. }
  1418. type TestHelperLibrary struct {
  1419. Library
  1420. testHelperLibraryProperties testHelperLibraryProperties
  1421. }
  1422. func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  1423. j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template,
  1424. j.testProperties.Test_suites, j.testProperties.Auto_gen_config)
  1425. j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data)
  1426. j.Library.GenerateAndroidBuildActions(ctx)
  1427. }
  1428. func (j *TestHelperLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  1429. j.Library.GenerateAndroidBuildActions(ctx)
  1430. }
  1431. // java_test builds a and links sources into a `.jar` file for the device, and possibly for the host as well, and
  1432. // creates an `AndroidTest.xml` file to allow running the test with `atest` or a `TEST_MAPPING` file.
  1433. //
  1434. // By default, a java_test has a single variant that produces a `.jar` file containing `classes.dex` files that were
  1435. // compiled against the device bootclasspath.
  1436. //
  1437. // Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
  1438. // compiled against the host bootclasspath.
  1439. func TestFactory() android.Module {
  1440. module := &Test{}
  1441. module.AddProperties(
  1442. &module.Module.properties,
  1443. &module.Module.deviceProperties,
  1444. &module.Module.dexpreoptProperties,
  1445. &module.Module.protoProperties,
  1446. &module.testProperties)
  1447. module.Module.properties.Installable = proptools.BoolPtr(true)
  1448. module.Module.dexpreopter.isTest = true
  1449. InitJavaModule(module, android.HostAndDeviceSupported)
  1450. return module
  1451. }
  1452. // java_test_helper_library creates a java library and makes sure that it is added to the appropriate test suite.
  1453. func TestHelperLibraryFactory() android.Module {
  1454. module := &TestHelperLibrary{}
  1455. module.AddProperties(
  1456. &module.Module.properties,
  1457. &module.Module.deviceProperties,
  1458. &module.Module.dexpreoptProperties,
  1459. &module.Module.protoProperties,
  1460. &module.testHelperLibraryProperties)
  1461. module.Module.properties.Installable = proptools.BoolPtr(true)
  1462. module.Module.dexpreopter.isTest = true
  1463. InitJavaModule(module, android.HostAndDeviceSupported)
  1464. return module
  1465. }
  1466. // java_test_host builds a and links sources into a `.jar` file for the host, and creates an `AndroidTest.xml` file to
  1467. // allow running the test with `atest` or a `TEST_MAPPING` file.
  1468. //
  1469. // A java_test_host has a single variant that produces a `.jar` file containing `.class` files that were
  1470. // compiled against the host bootclasspath.
  1471. func TestHostFactory() android.Module {
  1472. module := &Test{}
  1473. module.AddProperties(
  1474. &module.Module.properties,
  1475. &module.Module.protoProperties,
  1476. &module.testProperties)
  1477. module.Module.properties.Installable = proptools.BoolPtr(true)
  1478. InitJavaModule(module, android.HostSupported)
  1479. return module
  1480. }
  1481. //
  1482. // Java Binaries (.jar file plus wrapper script)
  1483. //
  1484. type binaryProperties struct {
  1485. // installable script to execute the resulting jar
  1486. Wrapper *string `android:"path"`
  1487. // Name of the class containing main to be inserted into the manifest as Main-Class.
  1488. Main_class *string
  1489. }
  1490. type Binary struct {
  1491. Library
  1492. binaryProperties binaryProperties
  1493. isWrapperVariant bool
  1494. wrapperFile android.Path
  1495. binaryFile android.InstallPath
  1496. }
  1497. func (j *Binary) HostToolPath() android.OptionalPath {
  1498. return android.OptionalPathForPath(j.binaryFile)
  1499. }
  1500. func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  1501. if ctx.Arch().ArchType == android.Common {
  1502. // Compile the jar
  1503. if j.binaryProperties.Main_class != nil {
  1504. if j.properties.Manifest != nil {
  1505. ctx.PropertyErrorf("main_class", "main_class cannot be used when manifest is set")
  1506. }
  1507. manifestFile := android.PathForModuleOut(ctx, "manifest.txt")
  1508. GenerateMainClassManifest(ctx, manifestFile, String(j.binaryProperties.Main_class))
  1509. j.overrideManifest = android.OptionalPathForPath(manifestFile)
  1510. }
  1511. j.Library.GenerateAndroidBuildActions(ctx)
  1512. } else {
  1513. // Handle the binary wrapper
  1514. j.isWrapperVariant = true
  1515. if j.binaryProperties.Wrapper != nil {
  1516. j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper)
  1517. } else {
  1518. j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
  1519. }
  1520. // Depend on the installed jar so that the wrapper doesn't get executed by
  1521. // another build rule before the jar has been installed.
  1522. jarFile := ctx.PrimaryModule().(*Binary).installFile
  1523. j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
  1524. ctx.ModuleName(), j.wrapperFile, jarFile)
  1525. }
  1526. }
  1527. func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
  1528. if ctx.Arch().ArchType == android.Common {
  1529. j.deps(ctx)
  1530. }
  1531. }
  1532. // java_binary builds a `.jar` file and a shell script that executes it for the device, and possibly for the host
  1533. // as well.
  1534. //
  1535. // By default, a java_binary has a single variant that produces a `.jar` file containing `classes.dex` files that were
  1536. // compiled against the device bootclasspath.
  1537. //
  1538. // Specifying `host_supported: true` will produce two variants, one compiled against the device bootclasspath and one
  1539. // compiled against the host bootclasspath.
  1540. func BinaryFactory() android.Module {
  1541. module := &Binary{}
  1542. module.AddProperties(
  1543. &module.Module.properties,
  1544. &module.Module.deviceProperties,
  1545. &module.Module.dexpreoptProperties,
  1546. &module.Module.protoProperties,
  1547. &module.binaryProperties)
  1548. module.Module.properties.Installable = proptools.BoolPtr(true)
  1549. android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommonFirst)
  1550. android.InitDefaultableModule(module)
  1551. return module
  1552. }
  1553. // java_binary_host builds a `.jar` file and a shell script that executes it for the host.
  1554. //
  1555. // A java_binary_host has a single variant that produces a `.jar` file containing `.class` files that were
  1556. // compiled against the host bootclasspath.
  1557. func BinaryHostFactory() android.Module {
  1558. module := &Binary{}
  1559. module.AddProperties(
  1560. &module.Module.properties,
  1561. &module.Module.protoProperties,
  1562. &module.binaryProperties)
  1563. module.Module.properties.Installable = proptools.BoolPtr(true)
  1564. android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommonFirst)
  1565. android.InitDefaultableModule(module)
  1566. return module
  1567. }
  1568. //
  1569. // Java prebuilts
  1570. //
  1571. type ImportProperties struct {
  1572. Jars []string `android:"path"`
  1573. Sdk_version *string
  1574. Installable *bool
  1575. // List of shared java libs that this module has dependencies to
  1576. Libs []string
  1577. // List of files to remove from the jar file(s)
  1578. Exclude_files []string
  1579. // List of directories to remove from the jar file(s)
  1580. Exclude_dirs []string
  1581. // if set to true, run Jetifier against .jar file. Defaults to false.
  1582. Jetifier *bool
  1583. }
  1584. type Import struct {
  1585. android.ModuleBase
  1586. android.DefaultableModuleBase
  1587. android.ApexModuleBase
  1588. prebuilt android.Prebuilt
  1589. android.SdkBase
  1590. properties ImportProperties
  1591. combinedClasspathFile android.Path
  1592. exportedSdkLibs []string
  1593. }
  1594. func (j *Import) sdkVersion() string {
  1595. return proptools.StringDefault(j.properties.Sdk_version, defaultSdkVersion(j))
  1596. }
  1597. func (j *Import) minSdkVersion() string {
  1598. return j.sdkVersion()
  1599. }
  1600. func (j *Import) Prebuilt() *android.Prebuilt {
  1601. return &j.prebuilt
  1602. }
  1603. func (j *Import) PrebuiltSrcs() []string {
  1604. return j.properties.Jars
  1605. }
  1606. func (j *Import) Name() string {
  1607. return j.prebuilt.Name(j.ModuleBase.Name())
  1608. }
  1609. func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) {
  1610. ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
  1611. }
  1612. func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  1613. jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
  1614. jarName := ctx.ModuleName() + ".jar"
  1615. outputFile := android.PathForModuleOut(ctx, "combined", jarName)
  1616. TransformJarsToJar(ctx, outputFile, "for prebuilts", jars, android.OptionalPath{},
  1617. false, j.properties.Exclude_files, j.properties.Exclude_dirs)
  1618. if Bool(j.properties.Jetifier) {
  1619. inputFile := outputFile
  1620. outputFile = android.PathForModuleOut(ctx, "jetifier", jarName)
  1621. TransformJetifier(ctx, outputFile, inputFile)
  1622. }
  1623. j.combinedClasspathFile = outputFile
  1624. ctx.VisitDirectDeps(func(module android.Module) {
  1625. otherName := ctx.OtherModuleName(module)
  1626. tag := ctx.OtherModuleDependencyTag(module)
  1627. switch dep := module.(type) {
  1628. case Dependency:
  1629. switch tag {
  1630. case libTag, staticLibTag:
  1631. // sdk lib names from dependencies are re-exported
  1632. j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
  1633. }
  1634. case SdkLibraryDependency:
  1635. switch tag {
  1636. case libTag:
  1637. // names of sdk libs that are directly depended are exported
  1638. j.exportedSdkLibs = append(j.exportedSdkLibs, otherName)
  1639. }
  1640. }
  1641. })
  1642. j.exportedSdkLibs = android.FirstUniqueStrings(j.exportedSdkLibs)
  1643. if Bool(j.properties.Installable) {
  1644. ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
  1645. ctx.ModuleName()+".jar", outputFile)
  1646. }
  1647. }
  1648. var _ Dependency = (*Import)(nil)
  1649. func (j *Import) HeaderJars() android.Paths {
  1650. if j.combinedClasspathFile == nil {
  1651. return nil
  1652. }
  1653. return android.Paths{j.combinedClasspathFile}
  1654. }
  1655. func (j *Import) ImplementationJars() android.Paths {
  1656. if j.combinedClasspathFile == nil {
  1657. return nil
  1658. }
  1659. return android.Paths{j.combinedClasspathFile}
  1660. }
  1661. func (j *Import) ResourceJars() android.Paths {
  1662. return nil
  1663. }
  1664. func (j *Import) ImplementationAndResourcesJars() android.Paths {
  1665. if j.combinedClasspathFile == nil {
  1666. return nil
  1667. }
  1668. return android.Paths{j.combinedClasspathFile}
  1669. }
  1670. func (j *Import) DexJar() android.Path {
  1671. return nil
  1672. }
  1673. func (j *Import) AidlIncludeDirs() android.Paths {
  1674. return nil
  1675. }
  1676. func (j *Import) ExportedSdkLibs() []string {
  1677. return j.exportedSdkLibs
  1678. }
  1679. func (j *Import) SrcJarArgs() ([]string, android.Paths) {
  1680. return nil, nil
  1681. }
  1682. // Add compile time check for interface implementation
  1683. var _ android.IDEInfo = (*Import)(nil)
  1684. var _ android.IDECustomizedModuleName = (*Import)(nil)
  1685. // Collect information for opening IDE project files in java/jdeps.go.
  1686. const (
  1687. removedPrefix = "prebuilt_"
  1688. )
  1689. func (j *Import) IDEInfo(dpInfo *android.IdeInfo) {
  1690. dpInfo.Jars = append(dpInfo.Jars, j.PrebuiltSrcs()...)
  1691. }
  1692. func (j *Import) IDECustomizedModuleName() string {
  1693. // TODO(b/113562217): Extract the base module name from the Import name, often the Import name
  1694. // has a prefix "prebuilt_". Remove the prefix explicitly if needed until we find a better
  1695. // solution to get the Import name.
  1696. name := j.Name()
  1697. if strings.HasPrefix(name, removedPrefix) {
  1698. name = strings.TrimPrefix(name, removedPrefix)
  1699. }
  1700. return name
  1701. }
  1702. var _ android.PrebuiltInterface = (*Import)(nil)
  1703. // java_import imports one or more `.jar` files into the build graph as if they were built by a java_library module.
  1704. //
  1705. // By default, a java_import has a single variant that expects a `.jar` file containing `.class` files that were
  1706. // compiled against an Android classpath.
  1707. //
  1708. // Specifying `host_supported: true` will produce two variants, one for use as a dependency of device modules and one
  1709. // for host modules.
  1710. func ImportFactory() android.Module {
  1711. module := &Import{}
  1712. module.AddProperties(&module.properties)
  1713. android.InitPrebuiltModule(module, &module.properties.Jars)
  1714. InitJavaModule(module, android.HostAndDeviceSupported)
  1715. android.InitApexModule(module)
  1716. android.InitSdkAwareModule(module)
  1717. return module
  1718. }
  1719. // java_import imports one or more `.jar` files into the build graph as if they were built by a java_library_host
  1720. // module.
  1721. //
  1722. // A java_import_host has a single variant that expects a `.jar` file containing `.class` files that were
  1723. // compiled against a host bootclasspath.
  1724. func ImportFactoryHost() android.Module {
  1725. module := &Import{}
  1726. module.AddProperties(&module.properties)
  1727. android.InitPrebuiltModule(module, &module.properties.Jars)
  1728. InitJavaModule(module, android.HostSupported)
  1729. android.InitApexModule(module)
  1730. return module
  1731. }
  1732. // dex_import module
  1733. type DexImportProperties struct {
  1734. Jars []string `android:"path"`
  1735. }
  1736. type DexImport struct {
  1737. android.ModuleBase
  1738. android.DefaultableModuleBase
  1739. android.ApexModuleBase
  1740. prebuilt android.Prebuilt
  1741. properties DexImportProperties
  1742. dexJarFile android.Path
  1743. maybeStrippedDexJarFile android.Path
  1744. dexpreopter
  1745. }
  1746. func (j *DexImport) Prebuilt() *android.Prebuilt {
  1747. return &j.prebuilt
  1748. }
  1749. func (j *DexImport) PrebuiltSrcs() []string {
  1750. return j.properties.Jars
  1751. }
  1752. func (j *DexImport) Name() string {
  1753. return j.prebuilt.Name(j.ModuleBase.Name())
  1754. }
  1755. func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  1756. if len(j.properties.Jars) != 1 {
  1757. ctx.PropertyErrorf("jars", "exactly one jar must be provided")
  1758. }
  1759. j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", ctx.ModuleName()+".jar")
  1760. j.dexpreopter.isInstallable = true
  1761. j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
  1762. inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars")
  1763. dexOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar")
  1764. if j.dexpreopter.uncompressedDex {
  1765. rule := android.NewRuleBuilder()
  1766. temporary := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar.unaligned")
  1767. rule.Temporary(temporary)
  1768. // use zip2zip to uncompress classes*.dex files
  1769. rule.Command().
  1770. BuiltTool(ctx, "zip2zip").
  1771. FlagWithInput("-i ", inputJar).
  1772. FlagWithOutput("-o ", temporary).
  1773. FlagWithArg("-0 ", "'classes*.dex'")
  1774. // use zipalign to align uncompressed classes*.dex files
  1775. rule.Command().
  1776. BuiltTool(ctx, "zipalign").
  1777. Flag("-f").
  1778. Text("4").
  1779. Input(temporary).
  1780. Output(dexOutputFile)
  1781. rule.DeleteTemporaryFiles()
  1782. rule.Build(pctx, ctx, "uncompress_dex", "uncompress dex")
  1783. } else {
  1784. ctx.Build(pctx, android.BuildParams{
  1785. Rule: android.Cp,
  1786. Input: inputJar,
  1787. Output: dexOutputFile,
  1788. })
  1789. }
  1790. j.dexJarFile = dexOutputFile
  1791. dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
  1792. j.maybeStrippedDexJarFile = dexOutputFile
  1793. ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
  1794. ctx.ModuleName()+".jar", dexOutputFile)
  1795. }
  1796. func (j *DexImport) DexJar() android.Path {
  1797. return j.dexJarFile
  1798. }
  1799. // dex_import imports a `.jar` file containing classes.dex files.
  1800. //
  1801. // A dex_import module cannot be used as a dependency of a java_* or android_* module, it can only be installed
  1802. // to the device.
  1803. func DexImportFactory() android.Module {
  1804. module := &DexImport{}
  1805. module.AddProperties(&module.properties)
  1806. android.InitPrebuiltModule(module, &module.properties.Jars)
  1807. InitJavaModule(module, android.DeviceSupported)
  1808. android.InitApexModule(module)
  1809. return module
  1810. }
  1811. //
  1812. // Defaults
  1813. //
  1814. type Defaults struct {
  1815. android.ModuleBase
  1816. android.DefaultsModuleBase
  1817. android.ApexModuleBase
  1818. }
  1819. // java_defaults provides a set of properties that can be inherited by other java or android modules.
  1820. //
  1821. // A module can use the properties from a java_defaults module using `defaults: ["defaults_module_name"]`. Each
  1822. // property in the defaults module that exists in the depending module will be prepended to the depending module's
  1823. // value for that property.
  1824. //
  1825. // Example:
  1826. //
  1827. // java_defaults {
  1828. // name: "example_defaults",
  1829. // srcs: ["common/**/*.java"],
  1830. // javacflags: ["-Xlint:all"],
  1831. // aaptflags: ["--auto-add-overlay"],
  1832. // }
  1833. //
  1834. // java_library {
  1835. // name: "example",
  1836. // defaults: ["example_defaults"],
  1837. // srcs: ["example/**/*.java"],
  1838. // }
  1839. //
  1840. // is functionally identical to:
  1841. //
  1842. // java_library {
  1843. // name: "example",
  1844. // srcs: [
  1845. // "common/**/*.java",
  1846. // "example/**/*.java",
  1847. // ],
  1848. // javacflags: ["-Xlint:all"],
  1849. // }
  1850. func defaultsFactory() android.Module {
  1851. return DefaultsFactory()
  1852. }
  1853. func DefaultsFactory(props ...interface{}) android.Module {
  1854. module := &Defaults{}
  1855. module.AddProperties(props...)
  1856. module.AddProperties(
  1857. &CompilerProperties{},
  1858. &CompilerDeviceProperties{},
  1859. &DexpreoptProperties{},
  1860. &android.ProtoProperties{},
  1861. &aaptProperties{},
  1862. &androidLibraryProperties{},
  1863. &appProperties{},
  1864. &appTestProperties{},
  1865. &overridableAppProperties{},
  1866. &ImportProperties{},
  1867. &AARImportProperties{},
  1868. &sdkLibraryProperties{},
  1869. &DexImportProperties{},
  1870. )
  1871. android.InitDefaultsModule(module)
  1872. android.InitApexModule(module)
  1873. return module
  1874. }
  1875. func kytheExtractJavaFactory() android.Singleton {
  1876. return &kytheExtractJavaSingleton{}
  1877. }
  1878. type kytheExtractJavaSingleton struct {
  1879. }
  1880. func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonContext) {
  1881. var xrefTargets android.Paths
  1882. ctx.VisitAllModules(func(module android.Module) {
  1883. if javaModule, ok := module.(xref); ok {
  1884. xrefTargets = append(xrefTargets, javaModule.XrefJavaFiles()...)
  1885. }
  1886. })
  1887. // TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets
  1888. if len(xrefTargets) > 0 {
  1889. ctx.Build(pctx, android.BuildParams{
  1890. Rule: blueprint.Phony,
  1891. Output: android.PathForPhony(ctx, "xref_java"),
  1892. Inputs: xrefTargets,
  1893. })
  1894. }
  1895. }
  1896. var Bool = proptools.Bool
  1897. var BoolDefault = proptools.BoolDefault
  1898. var String = proptools.String
  1899. var inList = android.InList