diff options
Diffstat (limited to 'dexpreopt/dexpreopt.go')
| -rw-r--r-- | dexpreopt/dexpreopt.go | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/dexpreopt/dexpreopt.go b/dexpreopt/dexpreopt.go index 5b658d989..0be37d0ff 100644 --- a/dexpreopt/dexpreopt.go +++ b/dexpreopt/dexpreopt.go @@ -226,15 +226,6 @@ func dexpreoptCommand(ctx android.PathContext, global GlobalConfig, module Modul bootImageLocation = PathToLocation(bootImage, arch) } - // Lists of used and optional libraries from the build config to be verified against the manifest in the APK - var verifyUsesLibs []string - var verifyOptionalUsesLibs []string - - // Lists of used and optional libraries from the build config, with optional libraries that are known to not - // be present in the current product removed. - var filteredUsesLibs []string - var filteredOptionalUsesLibs []string - // The class loader context using paths in the build var classLoaderContextHost android.Paths @@ -252,14 +243,10 @@ func dexpreoptCommand(ctx android.PathContext, global GlobalConfig, module Modul var classLoaderContextHostString string if module.EnforceUsesLibraries { - verifyUsesLibs = copyOf(module.UsesLibraries) - verifyOptionalUsesLibs = copyOf(module.OptionalUsesLibraries) - - filteredOptionalUsesLibs = filterOut(global.MissingUsesLibraries, module.OptionalUsesLibraries) - filteredUsesLibs = append(copyOf(module.UsesLibraries), filteredOptionalUsesLibs...) + usesLibs := append(copyOf(module.UsesLibraries), module.PresentOptionalUsesLibraries...) // Create class loader context for dex2oat from uses libraries and filtered optional libraries - for _, l := range filteredUsesLibs { + for _, l := range usesLibs { classLoaderContextHost = append(classLoaderContextHost, pathForLibrary(module, l)) @@ -270,11 +257,13 @@ func dexpreoptCommand(ctx android.PathContext, global GlobalConfig, module Modul const httpLegacy = "org.apache.http.legacy" const httpLegacyImpl = "org.apache.http.legacy.impl" - // Fix up org.apache.http.legacy.impl since it should be org.apache.http.legacy in the manifest. - replace(verifyUsesLibs, httpLegacyImpl, httpLegacy) - replace(verifyOptionalUsesLibs, httpLegacyImpl, httpLegacy) + // org.apache.http.legacy contains classes that were in the default classpath until API 28. If the + // targetSdkVersion in the manifest or APK is < 28, and the module does not explicitly depend on + // org.apache.http.legacy, then implicitly add the classes to the classpath for dexpreopt. One the + // device the classes will be in a file called org.apache.http.legacy.impl.jar. + module.LibraryPaths[httpLegacyImpl] = module.LibraryPaths[httpLegacy] - if !contains(verifyUsesLibs, httpLegacy) && !contains(verifyOptionalUsesLibs, httpLegacy) { + if !contains(module.UsesLibraries, httpLegacy) && !contains(module.PresentOptionalUsesLibraries, httpLegacy) { conditionalClassLoaderContextHost28 = append(conditionalClassLoaderContextHost28, pathForLibrary(module, httpLegacyImpl)) conditionalClassLoaderContextTarget28 = append(conditionalClassLoaderContextTarget28, @@ -284,6 +273,9 @@ func dexpreoptCommand(ctx android.PathContext, global GlobalConfig, module Modul const hidlBase = "android.hidl.base-V1.0-java" const hidlManager = "android.hidl.manager-V1.0-java" + // android.hidl.base-V1.0-java and android.hidl.manager-V1.0 contain classes that were in the default + // classpath until API 29. If the targetSdkVersion in the manifest or APK is < 29 then implicitly add + // the classes to the classpath for dexpreopt. conditionalClassLoaderContextHost29 = append(conditionalClassLoaderContextHost29, pathForLibrary(module, hidlManager)) conditionalClassLoaderContextTarget29 = append(conditionalClassLoaderContextTarget29, @@ -309,9 +301,21 @@ func dexpreoptCommand(ctx android.PathContext, global GlobalConfig, module Modul rule.Command().Text(`stored_class_loader_context_arg=""`) if module.EnforceUsesLibraries { - rule.Command().Textf(`uses_library_names="%s"`, strings.Join(verifyUsesLibs, " ")) - rule.Command().Textf(`optional_uses_library_names="%s"`, strings.Join(verifyOptionalUsesLibs, " ")) - rule.Command().Textf(`aapt_binary="%s"`, global.Tools.Aapt) + if module.ManifestPath != nil { + rule.Command().Text(`target_sdk_version="$(`). + Tool(global.Tools.ManifestCheck). + Flag("--extract-target-sdk-version"). + Input(module.ManifestPath). + Text(`)"`) + } else { + // No manifest to extract targetSdkVersion from, hope that DexJar is an APK + rule.Command().Text(`target_sdk_version="$(`). + Tool(global.Tools.Aapt). + Flag("dump badging"). + Input(module.DexPath). + Text(`| grep "targetSdkVersion" | sed -n "s/targetSdkVersion:'\(.*\)'/\1/p"`). + Text(`)"`) + } rule.Command().Textf(`dex_preopt_host_libraries="%s"`, strings.Join(classLoaderContextHost.Strings(), " ")). Implicits(classLoaderContextHost) @@ -327,8 +331,7 @@ func dexpreoptCommand(ctx android.PathContext, global GlobalConfig, module Modul Implicits(conditionalClassLoaderContextHost29) rule.Command().Textf(`conditional_target_libs_29="%s"`, strings.Join(conditionalClassLoaderContextTarget29, " ")) - rule.Command().Text("source").Tool(global.Tools.VerifyUsesLibraries).Input(module.DexPath) - rule.Command().Text("source").Tool(global.Tools.ConstructContext) + rule.Command().Text("source").Tool(global.Tools.ConstructContext).Input(module.DexPath) } // Devices that do not have a product partition use a symlink from /product to /system/product. |