diff --git a/apex/apex.go b/apex/apex.go index 180dcb4e2..c19732eb1 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -1663,12 +1663,12 @@ var _ javaModule = (*java.DexImport)(nil) var _ javaModule = (*java.SdkLibraryImport)(nil) // apexFileForJavaModule creates an apexFile for a java module's dex implementation jar. -func apexFileForJavaModule(ctx android.BaseModuleContext, module javaModule) apexFile { +func apexFileForJavaModule(ctx android.ModuleContext, module javaModule) apexFile { return apexFileForJavaModuleWithFile(ctx, module, module.DexJarBuildPath(ctx).PathOrNil()) } // apexFileForJavaModuleWithFile creates an apexFile for a java module with the supplied file. -func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaModule, dexImplementationJar android.Path) apexFile { +func apexFileForJavaModuleWithFile(ctx android.ModuleContext, module javaModule, dexImplementationJar android.Path) apexFile { dirInApex := "javalib" af := newApexFile(ctx, dexImplementationJar, module.BaseModuleName(), dirInApex, javaSharedLib, module) af.jacocoReportClassesFile = module.JacocoReportClassesFile() @@ -1679,10 +1679,12 @@ func apexFileForJavaModuleWithFile(ctx android.BaseModuleContext, module javaMod if sdkLib, ok := module.(*java.SdkLibrary); ok { for _, install := range sdkLib.BuiltInstalledForApex() { af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName()) + install.PackageFile(ctx) } } else if dexpreopter, ok := module.(java.DexpreopterInterface); ok { for _, install := range dexpreopter.DexpreoptBuiltInstalledForApex() { af.requiredModuleNames = append(af.requiredModuleNames, install.FullModuleName()) + install.PackageFile(ctx) } } return af diff --git a/apex/prebuilt.go b/apex/prebuilt.go index 9ad5159b5..d91943fdf 100644 --- a/apex/prebuilt.go +++ b/apex/prebuilt.go @@ -197,6 +197,7 @@ func (p *prebuiltCommon) initApexFilesForAndroidMk(ctx android.ModuleContext) { // If this apex contains a system server jar, then the dexpreopt artifacts should be added as required for _, install := range p.Dexpreopter.DexpreoptBuiltInstalledForApex() { p.requiredModuleNames = append(p.requiredModuleNames, install.FullModuleName()) + install.PackageFile(ctx) } } diff --git a/java/dexpreopt.go b/java/dexpreopt.go index 57aaa1a2d..794924401 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -96,6 +96,10 @@ func (install dexpreopterInstall) ToMakeEntries() android.AndroidMkEntries { } } +func (install dexpreopterInstall) PackageFile(ctx android.ModuleContext) android.PackagingSpec { + return ctx.PackageFile(install.installDirOnDevice, install.installFileOnDevice, install.outputPathOnHost) +} + type Dexpreopter struct { dexpreopter } @@ -541,10 +545,18 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, libName string, dexJa // Use the path of the dex file to determine the library name isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(dexJarStem) - partition := d.installPath.Partition() + dexpreoptPartition := d.installPath.Partition() + // dexpreoptPartition is set to empty for dexpreopts of system APEX and system_other. + // In case of system APEX, however, we can set it to "system" manually. + // TODO(b/346662300): Let dexpreopter generate the installPath for dexpreopt files instead of + // using the dex location to generate the installPath. + if isApexSystemServerJar { + dexpreoptPartition = "system" + } for _, install := range dexpreoptRule.Installs() { // Remove the "/" prefix because the path should be relative to $ANDROID_PRODUCT_OUT. installDir := strings.TrimPrefix(filepath.Dir(install.To), "/") + partition := dexpreoptPartition if strings.HasPrefix(installDir, partition+"/") { installDir = strings.TrimPrefix(installDir, partition+"/") } else {