diff --git a/android/visibility.go b/android/visibility.go index 6558e4622..5aa7f3f67 100644 --- a/android/visibility.go +++ b/android/visibility.go @@ -496,6 +496,13 @@ func EffectiveVisibilityRules(ctx BaseModuleContext, module Module) []string { rule := effectiveVisibilityRules(ctx.Config(), qualified) + // Modules are implicitly visible to other modules in the same package, + // without checking the visibility rules. Here we need to add that visibility + // explicitly. + if rule != nil && !rule.matches(qualified) { + rule = append(rule, packageRule{dir}) + } + return rule.Strings() } diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index eb514342b..9bbf410b7 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -155,14 +155,20 @@ func TestSnapshotVisibility(t *testing.T) { java_import { name: "mysdk_myjavalib@current", sdk_member_name: "myjavalib", - visibility: ["//other/foo"], + visibility: [ + "//other/foo", + "//package", + ], jars: ["java/myjavalib.jar"], } java_import { name: "myjavalib", prefer: false, - visibility: ["//other/foo"], + visibility: [ + "//other/foo", + "//package", + ], jars: ["java/myjavalib.jar"], } @@ -183,14 +189,20 @@ java_import { java_import { name: "mysdk_mydefaultedjavalib@current", sdk_member_name: "mydefaultedjavalib", - visibility: ["//other/bar"], + visibility: [ + "//other/bar", + "//package", + ], jars: ["java/mydefaultedjavalib.jar"], } java_import { name: "mydefaultedjavalib", prefer: false, - visibility: ["//other/bar"], + visibility: [ + "//other/bar", + "//package", + ], jars: ["java/mydefaultedjavalib.jar"], }