diff --git a/cc/cc_test.go b/cc/cc_test.go index 4c9f5799b..58489c271 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -3585,6 +3585,58 @@ func TestAidlFlagsPassedToTheAidlCompiler(t *testing.T) { } } +func TestAidlFlagsWithMinSdkVersion(t *testing.T) { + for _, tc := range []struct { + name string + sdkVersion string + variant string + expected string + }{ + { + name: "default is current", + sdkVersion: "", + variant: "android_arm64_armv8-a_static", + expected: "platform_apis", + }, + { + name: "use sdk_version", + sdkVersion: `sdk_version: "29"`, + variant: "android_arm64_armv8-a_static", + expected: "platform_apis", + }, + { + name: "use sdk_version(sdk variant)", + sdkVersion: `sdk_version: "29"`, + variant: "android_arm64_armv8-a_sdk_static", + expected: "29", + }, + { + name: "use min_sdk_version", + sdkVersion: `min_sdk_version: "29"`, + variant: "android_arm64_armv8-a_static", + expected: "29", + }, + } { + t.Run(tc.name, func(t *testing.T) { + ctx := testCc(t, ` + cc_library { + name: "libfoo", + stl: "none", + srcs: ["a/Foo.aidl"], + `+tc.sdkVersion+` + } + `) + libfoo := ctx.ModuleForTests("libfoo", tc.variant) + manifest := android.RuleBuilderSboxProtoForTests(t, libfoo.Output("aidl.sbox.textproto")) + aidlCommand := manifest.Commands[0].GetCommand() + expectedAidlFlag := "--min_sdk_version=" + tc.expected + if !strings.Contains(aidlCommand, expectedAidlFlag) { + t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) + } + }) + } +} + func TestMinSdkVersionInClangTriple(t *testing.T) { ctx := testCc(t, ` cc_library_shared { diff --git a/cc/compiler.go b/cc/compiler.go index 00df66912..ffe8b2e36 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -552,6 +552,12 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps flags.aidlFlags = append(flags.aidlFlags, "-t") } + aidlMinSdkVersion := ctx.minSdkVersion() + if aidlMinSdkVersion == "" { + aidlMinSdkVersion = "platform_apis" + } + flags.aidlFlags = append(flags.aidlFlags, "--min_sdk_version="+aidlMinSdkVersion) + flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+android.PathForModuleGen(ctx, "aidl").String()) } diff --git a/java/base.go b/java/base.go index ca34f2eef..859baaff7 100644 --- a/java/base.go +++ b/java/base.go @@ -784,6 +784,9 @@ func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.Opt flags = append(flags, "--transaction_names") } + aidlMinSdkVersion := j.MinSdkVersion(ctx).ApiLevel.String() + flags = append(flags, "--min_sdk_version="+aidlMinSdkVersion) + return strings.Join(flags, " "), deps } diff --git a/java/java_test.go b/java/java_test.go index bc9b40964..c039f7246 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1357,6 +1357,36 @@ func TestAidlFlagsArePassedToTheAidlCompiler(t *testing.T) { } } +func TestAidlFlagsWithMinSdkVersion(t *testing.T) { + fixture := android.GroupFixturePreparers( + prepareForJavaTest, FixtureWithPrebuiltApis(map[string][]string{"14": {"foo"}})) + + for _, tc := range []struct { + name string + sdkVersion string + expected string + }{ + {"default is current", "", "current"}, + {"use sdk_version", `sdk_version: "14"`, "14"}, + {"system_current", `sdk_version: "system_current"`, "current"}, + } { + t.Run(tc.name, func(t *testing.T) { + ctx := fixture.RunTestWithBp(t, ` + java_library { + name: "foo", + srcs: ["aidl/foo/IFoo.aidl"], + `+tc.sdkVersion+` + } + `) + aidlCommand := ctx.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command + expectedAidlFlag := "--min_sdk_version=" + tc.expected + if !strings.Contains(aidlCommand, expectedAidlFlag) { + t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) + } + }) + } +} + func TestDataNativeBinaries(t *testing.T) { ctx, _ := testJava(t, ` java_test_host {