diff options
Diffstat (limited to 'java/app.go')
-rwxr-xr-x | java/app.go | 68 |
1 files changed, 42 insertions, 26 deletions
diff --git a/java/app.go b/java/app.go index fc1ace07b..4e967ad45 100755 --- a/java/app.go +++ b/java/app.go @@ -1213,7 +1213,7 @@ func (u *usesLibrary) addLib(lib string, optional bool) { } func (u *usesLibrary) deps(ctx android.BottomUpMutatorContext, hasFrameworkLibs bool) { - if !ctx.Config().UnbundledBuild() { + if !ctx.Config().UnbundledBuild() || ctx.Config().UnbundledBuildImage() { ctx.AddVariationDependencies(nil, usesLibTag, u.usesLibraryProperties.Uses_libs...) ctx.AddVariationDependencies(nil, usesLibTag, u.presentOptionalUsesLibs(ctx)...) // Only add these extra dependencies if the module depends on framework libs. This avoids @@ -1245,36 +1245,52 @@ func replaceInList(list []string, oldstr, newstr string) { } } -// Returns a map of module names of shared library dependencies to the paths -// to their dex jars on host and on device. +// Returns a map of module names of shared library dependencies to the paths to their dex jars on +// host and on device. func (u *usesLibrary) classLoaderContextForUsesLibDeps(ctx android.ModuleContext) dexpreopt.ClassLoaderContextMap { clcMap := make(dexpreopt.ClassLoaderContextMap) - if !ctx.Config().UnbundledBuild() { - ctx.VisitDirectDeps(func(m android.Module) { - if tag, ok := ctx.OtherModuleDependencyTag(m).(usesLibraryDependencyTag); ok { - dep := ctx.OtherModuleName(m) - if lib, ok := m.(UsesLibraryDependency); ok { - libName := dep - if ulib, ok := m.(ProvidesUsesLib); ok && ulib.ProvidesUsesLib() != nil { - libName = *ulib.ProvidesUsesLib() - // Replace module name with library name in `uses_libs`/`optional_uses_libs` - // in order to pass verify_uses_libraries check (which compares these - // properties against library names written in the manifest). - replaceInList(u.usesLibraryProperties.Uses_libs, dep, libName) - replaceInList(u.usesLibraryProperties.Optional_uses_libs, dep, libName) - } - clcMap.AddContext(ctx, tag.sdkVersion, libName, - lib.DexJarBuildPath(), lib.DexJarInstallPath(), lib.ClassLoaderContexts()) - } else if ctx.Config().AllowMissingDependencies() { - ctx.AddMissingDependencies([]string{dep}) - } else { - ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be a java library", dep) - } - } - }) + // Skip when UnbundledBuild() is true, but UnbundledBuildImage() is false. With + // UnbundledBuildImage() it is necessary to generate dexpreopt.config for post-dexpreopting. + if ctx.Config().UnbundledBuild() && !ctx.Config().UnbundledBuildImage() { + return clcMap } + ctx.VisitDirectDeps(func(m android.Module) { + tag, isUsesLibTag := ctx.OtherModuleDependencyTag(m).(usesLibraryDependencyTag) + if !isUsesLibTag { + return + } + + dep := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(m)) + + // Skip stub libraries. A dependency on the implementation library has been added earlier, + // so it will be added to CLC, but the stub shouldn't be. Stub libraries can be distingushed + // from implementation libraries by their name, which is different as it has a suffix. + if comp, ok := m.(SdkLibraryComponentDependency); ok { + if impl := comp.OptionalSdkLibraryImplementation(); impl != nil && *impl != dep { + return + } + } + + if lib, ok := m.(UsesLibraryDependency); ok { + libName := dep + if ulib, ok := m.(ProvidesUsesLib); ok && ulib.ProvidesUsesLib() != nil { + libName = *ulib.ProvidesUsesLib() + // Replace module name with library name in `uses_libs`/`optional_uses_libs` in + // order to pass verify_uses_libraries check (which compares these properties + // against library names written in the manifest). + replaceInList(u.usesLibraryProperties.Uses_libs, dep, libName) + replaceInList(u.usesLibraryProperties.Optional_uses_libs, dep, libName) + } + clcMap.AddContext(ctx, tag.sdkVersion, libName, + lib.DexJarBuildPath(), lib.DexJarInstallPath(), lib.ClassLoaderContexts()) + } else if ctx.Config().AllowMissingDependencies() { + ctx.AddMissingDependencies([]string{dep}) + } else { + ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be a java library", dep) + } + }) return clcMap } |