diff --git a/java/app.go b/java/app.go index 39f06d004..2d918e942 100755 --- a/java/app.go +++ b/java/app.go @@ -1217,6 +1217,15 @@ func (u *usesLibrary) presentOptionalUsesLibs(ctx android.BaseModuleContext) []s return optionalUsesLibs } +// Helper function to replace string in a list. +func replaceInList(list []string, oldstr, newstr string) { + for i, str := range list { + if str == oldstr { + list[i] = newstr + } + } +} + // 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 { @@ -1227,7 +1236,16 @@ func (u *usesLibrary) classLoaderContextForUsesLibDeps(ctx android.ModuleContext if tag, ok := ctx.OtherModuleDependencyTag(m).(usesLibraryDependencyTag); ok { dep := ctx.OtherModuleName(m) if lib, ok := m.(UsesLibraryDependency); ok { - clcMap.AddContext(ctx, tag.sdkVersion, dep, + 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}) diff --git a/java/app_test.go b/java/app_test.go index 89d77742d..c5a618c95 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -2357,10 +2357,9 @@ func TestUsesLibraries(t *testing.T) { `--uses-library qux ` + `--uses-library quuz ` + `--uses-library foo ` + // TODO(b/132357300): "foo" should not be passed to manifest_fixer - `--uses-library non-sdk-lib ` + // TODO(b/132357300): "non-sdk-lib" should not be passed to manifest_fixer + `--uses-library com.non.sdk.lib ` + // TODO(b/132357300): "com.non.sdk.lib" should not be passed to manifest_fixer `--uses-library bar ` + // TODO(b/132357300): "bar" should not be passed to manifest_fixer - `--uses-library runtime-library ` + - `--uses-library com.non.sdk.lib` // TODO(b/132357300): "com.non.sdk.lib" should not be passed to manifest_fixer + `--uses-library runtime-library` if actualManifestFixerArgs != expectManifestFixerArgs { t.Errorf("unexpected manifest_fixer args:\n\texpect: %q\n\tactual: %q", expectManifestFixerArgs, actualManifestFixerArgs) @@ -2369,11 +2368,10 @@ func TestUsesLibraries(t *testing.T) { // Test that all libraries are verified (library order matters). verifyCmd := app.Rule("verify_uses_libraries").RuleParams.Command verifyArgs := `--uses-library foo ` + - `--uses-library non-sdk-lib ` + // TODO(b/132357300): "non-sdk-lib" should not be here + `--uses-library com.non.sdk.lib ` + `--uses-library qux ` + `--uses-library quuz ` + `--uses-library runtime-library ` + - `--uses-library com.non.sdk.lib ` + `--optional-uses-library bar ` + `--optional-uses-library baz ` if !strings.Contains(verifyCmd, verifyArgs) {