Merge "mark platform un-availability"
diff --git a/Android.bp b/Android.bp
index 97233f5..7cdd928 100644
--- a/Android.bp
+++ b/Android.bp
@@ -644,7 +644,8 @@
     arch: {
         arm: {
             src: "prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/lib/gcc/arm-linux-androideabi/4.9.x/libgcc.a",
-            repack_objects_to_keep: ["unwind-arm.o", "libunwind.o", "pr-support.o"],
+            repack_objects_to_keep: [],
+            enabled: false,
         },
         arm64: {
             src: "prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/lib/gcc/aarch64-linux-android/4.9.x/libgcc.a",
diff --git a/android/apex.go b/android/apex.go
index d144990..f9350d1 100644
--- a/android/apex.go
+++ b/android/apex.go
@@ -118,6 +118,11 @@
 
 	// Tests if the module comes from an updatable APEX.
 	Updatable() bool
+
+	// List of APEXes that this module tests. The module has access to
+	// the private part of the listed APEXes even when it is not included in the
+	// APEXes.
+	TestFor() []string
 }
 
 type ApexProperties struct {
@@ -163,6 +168,11 @@
 	return m.ApexProperties.Apex_available
 }
 
+func (m *ApexModuleBase) TestFor() []string {
+	// To be implemented by concrete types inheriting ApexModuleBase
+	return nil
+}
+
 func (m *ApexModuleBase) BuildForApexes(apexes []ApexInfo) {
 	m.apexVariationsLock.Lock()
 	defer m.apexVariationsLock.Unlock()
diff --git a/android/api_levels.go b/android/api_levels.go
index 4b7a8fd..b6296d8 100644
--- a/android/api_levels.go
+++ b/android/api_levels.go
@@ -16,6 +16,7 @@
 
 import (
 	"encoding/json"
+	"fmt"
 	"strconv"
 )
 
@@ -84,14 +85,19 @@
 // Converts an API level string into its numeric form.
 // * Codenames are decoded.
 // * Numeric API levels are simply converted.
-// * "minimum" and "current" are not currently handled since the former is
-//   NDK specific and the latter has inconsistent meaning.
+// * "current" is mapped to FutureApiLevel(10000)
+// * "minimum" is NDK specific and not handled with this. (refer normalizeNdkApiLevel in cc.go)
 func ApiStrToNum(ctx BaseModuleContext, apiLevel string) (int, error) {
-	num, ok := getApiLevelsMap(ctx.Config())[apiLevel]
-	if ok {
+	if apiLevel == "current" {
+		return FutureApiLevel, nil
+	}
+	if num, ok := getApiLevelsMap(ctx.Config())[apiLevel]; ok {
 		return num, nil
 	}
-	return strconv.Atoi(apiLevel)
+	if num, err := strconv.Atoi(apiLevel); err == nil {
+		return num, nil
+	}
+	return 0, fmt.Errorf("SDK version should be one of \"current\", <number> or <codename>: %q", apiLevel)
 }
 
 func (a *apiLevelsSingleton) GenerateBuildActions(ctx SingletonContext) {
diff --git a/apex/apex.go b/apex/apex.go
index 8bcd7ef..39968ab 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -20,7 +20,6 @@
 	"path/filepath"
 	"regexp"
 	"sort"
-	"strconv"
 	"strings"
 	"sync"
 
@@ -94,24 +93,6 @@
 	//
 	// Module separator
 	//
-	m["com.android.adbd"] = []string{
-		"libadbd_auth",
-		"libbuildversion",
-		"libcap",
-		"libmdnssd",
-		"libminijail",
-		"libminijail_gen_constants",
-		"libminijail_gen_constants_obj",
-		"libminijail_gen_syscall",
-		"libminijail_gen_syscall_obj",
-		"libminijail_generated",
-		"libpackagelistparser",
-		"libpcre2",
-		"libprocessgroup_headers",
-	}
-	//
-	// Module separator
-	//
 	artApexContents := []string{
 		"art_cmdlineparser_headers",
 		"art_disassembler_headers",
@@ -135,14 +116,12 @@
 		"libandroidicuinit",
 		"libart_runtime_headers_ndk",
 		"libartd-disassembler",
-		"libasync_safe",
 		"libdexfile_all_headers",
 		"libdexfile_external_headers",
 		"libdexfile_support",
 		"libdmabufinfo",
 		"libexpat",
 		"libfdlibm",
-		"libgtest_prod",
 		"libicui18n_headers",
 		"libicuuc",
 		"libicuuc_headers",
@@ -232,13 +211,10 @@
 		"libevent",
 		"libfmq",
 		"libg722codec",
-		"libgtest_prod",
 		"libgui_headers",
 		"libmedia_headers",
 		"libmodpb64",
 		"libosi",
-		"libprocessgroup",
-		"libprocessgroup_headers",
 		"libstagefright_foundation_headers",
 		"libstagefright_headers",
 		"libstatslog",
@@ -264,9 +240,7 @@
 	// Module separator
 	//
 	m["com.android.conscrypt"] = []string{
-		"boringssl_self_test",
 		"libnativehelper_header_only",
-		"unsupportedappusage",
 	}
 	//
 	// Module separator
@@ -284,18 +258,6 @@
 	//
 	// Module separator
 	//
-	m["com.android.cronet"] = []string{
-		"cronet_impl_common_java",
-		"cronet_impl_native_java",
-		"cronet_impl_platform_java",
-		"libcronet.80.0.3986.0",
-		"org.chromium.net.cronet",
-		"org.chromium.net.cronet.xml",
-		"prebuilt_libcronet.80.0.3986.0",
-	}
-	//
-	// Module separator
-	//
 	m["com.android.neuralnetworks"] = []string{
 		"android.hardware.neuralnetworks@1.0",
 		"android.hardware.neuralnetworks@1.1",
@@ -308,8 +270,6 @@
 		"libarect",
 		"libbuildversion",
 		"libmath",
-		"libprocessgroup",
-		"libprocessgroup_headers",
 		"libprocpartition",
 		"libsync",
 	}
@@ -352,7 +312,6 @@
 		"libaacextractor",
 		"libamrextractor",
 		"libarect",
-		"libasync_safe",
 		"libaudio_system_headers",
 		"libaudioclient",
 		"libaudioclient_headers",
@@ -406,13 +365,10 @@
 		"libnblog",
 		"liboggextractor",
 		"libpackagelistparser",
-		"libpcre2",
 		"libpdx",
 		"libpdx_default_transport",
 		"libpdx_headers",
 		"libpdx_uds",
-		"libprocessgroup",
-		"libprocessgroup_headers",
 		"libprocinfo",
 		"libsonivox",
 		"libspeexresampler",
@@ -478,7 +434,6 @@
 		"libFraunhoferAAC",
 		"libLibGuiProperties",
 		"libarect",
-		"libasync_safe",
 		"libaudio_system_headers",
 		"libaudioutils",
 		"libaudioutils",
@@ -492,7 +447,6 @@
 		"libbluetooth-types-header",
 		"libbufferhub_headers",
 		"libc_scudo",
-		"libcap",
 		"libcodec2",
 		"libcodec2_headers",
 		"libcodec2_hidl@1.0",
@@ -551,20 +505,12 @@
 		"libmath",
 		"libmedia_codecserviceregistrant",
 		"libmedia_headers",
-		"libminijail",
-		"libminijail_gen_constants",
-		"libminijail_gen_constants_obj",
-		"libminijail_gen_syscall",
-		"libminijail_gen_syscall_obj",
-		"libminijail_generated",
 		"libmpeg2dec",
 		"libnativebase_headers",
 		"libnativebridge_lazy",
 		"libnativeloader_lazy",
 		"libnativewindow_headers",
 		"libpdx_headers",
-		"libprocessgroup",
-		"libprocessgroup_headers",
 		"libscudo_wrapper",
 		"libsfplugin_ccodec_utils",
 		"libstagefright_amrnb_common",
@@ -632,8 +578,6 @@
 	m["com.android.runtime"] = []string{
 		"bionic_libc_platform_headers",
 		"libarm-optimized-routines-math",
-		"libasync_safe",
-		"libasync_safe_headers",
 		"libc_aeabi",
 		"libc_bionic",
 		"libc_bionic_ndk",
@@ -669,13 +613,11 @@
 		"libdexfile_support",
 		"libdexfile_support_static",
 		"libdl_static",
-		"libgtest_prod",
 		"libjemalloc5",
 		"liblinker_main",
 		"liblinker_malloc",
 		"liblz4",
 		"liblzma",
-		"libprocessgroup_headers",
 		"libprocinfo",
 		"libpropertyinfoparser",
 		"libscudo",
@@ -689,34 +631,11 @@
 	//
 	// Module separator
 	//
-	m["com.android.resolv"] = []string{
-		"dnsresolver_aidl_interface-unstable-ndk_platform",
-		"libgtest_prod",
-		"libnativehelper_header_only",
-		"libnetd_client_headers",
-		"libnetd_resolv",
-		"libnetdutils",
-		"libprocessgroup",
-		"libprocessgroup_headers",
-		"libstatslog_resolv",
-		"libstatspush_compat",
-		"libstatssocket",
-		"libstatssocket_headers",
-		"libsysutils",
-		"netd_event_listener_interface-ndk_platform",
-		"server_configurable_flags",
-		"stats_proto",
-	}
-	//
-	// Module separator
-	//
 	m["com.android.tethering"] = []string{
 		"libnativehelper_compat_libc++",
 		"android.hardware.tetheroffload.config@1.0",
 		"libcgrouprc",
 		"libcgrouprc_format",
-		"libprocessgroup",
-		"libprocessgroup_headers",
 		"libtetherutilsjni",
 		"libvndksupport",
 		"tethering-aidl-interfaces-java",
@@ -754,8 +673,6 @@
 		"ipmemorystore-aidl-interfaces-java",
 		"ksoap2",
 		"libnanohttpd",
-		"libprocessgroup",
-		"libprocessgroup_headers",
 		"libwifi-jni",
 		"net-utils-services-common",
 		"netd_aidl_interface-V2-java",
@@ -783,7 +700,6 @@
 	// Module separator
 	//
 	m["com.android.os.statsd"] = []string{
-		"libprocessgroup_headers",
 		"libstatssocket",
 	}
 	//
@@ -1160,8 +1076,10 @@
 	IsCoverageVariant bool `blueprint:"mutated"`
 
 	// Whether this APEX is considered updatable or not. When set to true, this will enforce additional
-	// rules for making sure that the APEX is truely updatable. This will also disable the size optimizations
-	// like symlinking to the system libs. Default is false.
+	// rules for making sure that the APEX is truly updatable.
+	// - To be updatable, min_sdk_version should be set as well
+	// This will also disable the size optimizations like symlinking to the system libs.
+	// Default is false.
 	Updatable *bool
 
 	// The minimum SDK version that this apex must be compatibile with.
@@ -1861,14 +1779,11 @@
 
 func (a *apexBundle) minSdkVersion(ctx android.BaseModuleContext) int {
 	ver := proptools.StringDefault(a.properties.Min_sdk_version, "current")
-	if ver != "current" {
-		minSdkVersion, err := strconv.Atoi(ver)
-		if err != nil {
-			ctx.PropertyErrorf("min_sdk_version", "should be \"current\" or <number>, but %q", ver)
-		}
-		return minSdkVersion
+	intVer, err := android.ApiStrToNum(ctx, ver)
+	if err != nil {
+		ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
 	}
-	return android.FutureApiLevel
+	return intVer
 }
 
 // A regexp for removing boilerplate from BaseDependencyTag from the string representation of
@@ -1936,6 +1851,14 @@
 	})
 }
 
+func (a *apexBundle) checkUpdatable(ctx android.ModuleContext) {
+	if proptools.Bool(a.properties.Updatable) {
+		if String(a.properties.Min_sdk_version) == "" {
+			ctx.PropertyErrorf("updatable", "updatable APEXes should set min_sdk_version as well")
+		}
+	}
+}
+
 // Collects the list of module names that directly or indirectly contributes to the payload of this APEX
 func (a *apexBundle) collectDepsInfo(ctx android.ModuleContext) {
 	a.depInfos = make(map[string]depInfo)
@@ -2001,6 +1924,7 @@
 	}
 
 	a.checkApexAvailability(ctx)
+	a.checkUpdatable(ctx)
 
 	a.collectDepsInfo(ctx)
 
diff --git a/apex/apex_test.go b/apex/apex_test.go
index bb59a54..c4ab0be 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -1144,6 +1144,60 @@
 	expectNoLink("liba", "shared_otherapex", "libz", "shared")
 }
 
+func TestApexMinSdkVersion_SupportsCodeNames(t *testing.T) {
+	ctx, _ := testApex(t, `
+		apex {
+			name: "myapex",
+			key: "myapex.key",
+			native_shared_libs: ["libx"],
+			min_sdk_version: "R",
+		}
+
+		apex_key {
+			name: "myapex.key",
+			public_key: "testkey.avbpubkey",
+			private_key: "testkey.pem",
+		}
+
+		cc_library {
+			name: "libx",
+			shared_libs: ["libz"],
+			system_shared_libs: [],
+			stl: "none",
+			apex_available: [ "myapex" ],
+		}
+
+		cc_library {
+			name: "libz",
+			system_shared_libs: [],
+			stl: "none",
+			stubs: {
+				versions: ["29", "R"],
+			},
+		}
+	`, func(fs map[string][]byte, config android.Config) {
+		config.TestProductVariables.Platform_version_active_codenames = []string{"R"}
+	})
+
+	expectLink := func(from, from_variant, to, to_variant string) {
+		ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
+		ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
+	}
+	expectNoLink := func(from, from_variant, to, to_variant string) {
+		ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"]
+		ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
+	}
+	// 9000 is quite a magic number.
+	// Finalized SDK codenames are mapped as P(28), Q(29), ...
+	// And, codenames which are not finalized yet(active_codenames + future_codenames) are numbered from 9000, 9001, ...
+	// to distinguish them from finalized and future_api(10000)
+	// In this test, "R" is assumed not finalized yet( listed in Platform_version_active_codenames) and translated into 9000
+	// (refer android/api_levels.go)
+	expectLink("libx", "shared_myapex", "libz", "shared_9000")
+	expectNoLink("libx", "shared_myapex", "libz", "shared_29")
+	expectNoLink("libx", "shared_myapex", "libz", "shared")
+}
+
 func TestApexMinSdkVersionDefaultsToLatest(t *testing.T) {
 	ctx, _ := testApex(t, `
 		apex {
@@ -1334,11 +1388,11 @@
 		}
 	`)
 
-	testApexError(t, `"myapex" .*: min_sdk_version: should be "current" or <number>`, `
+	testApexError(t, `"myapex" .*: min_sdk_version: SDK version should be .*`, `
 		apex {
 			name: "myapex",
 			key: "myapex.key",
-			min_sdk_version: "R",
+			min_sdk_version: "abc",
 		}
 
 		apex_key {
@@ -4068,6 +4122,7 @@
 			native_shared_libs: ["mylib"],
 			java_libs: ["myjar"],
 			updatable: true,
+			min_sdk_version: "current",
 		}
 
 		apex_key {
@@ -4365,6 +4420,22 @@
 	}
 }
 
+func TestUpdatable_should_set_min_sdk_version(t *testing.T) {
+	testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, `
+		apex {
+			name: "myapex",
+			key: "myapex.key",
+			updatable: true,
+		}
+
+		apex_key {
+			name: "myapex.key",
+			public_key: "testkey.avbpubkey",
+			private_key: "testkey.pem",
+		}
+	`)
+}
+
 func TestNoUpdatableJarsInBootImage(t *testing.T) {
 	bp := `
 		java_library {
@@ -4403,6 +4474,7 @@
 			key: "some-updatable-apex.key",
 			java_libs: ["some-updatable-apex-lib"],
 			updatable: true,
+			min_sdk_version: "current",
 		}
 
 		apex {
@@ -4424,6 +4496,7 @@
 			key: "com.android.art.something.key",
 			java_libs: ["some-art-lib"],
 			updatable: true,
+			min_sdk_version: "current",
 		}
 
 		apex_key {
@@ -4502,6 +4575,58 @@
 	testNoUpdatableJarsInBootImage(t, "", bp, transform)
 }
 
+func TestTestFor(t *testing.T) {
+	ctx, _ := testApex(t, `
+		apex {
+			name: "myapex",
+			key: "myapex.key",
+			native_shared_libs: ["mylib", "myprivlib"],
+		}
+
+		apex_key {
+			name: "myapex.key",
+			public_key: "testkey.avbpubkey",
+			private_key: "testkey.pem",
+		}
+
+		cc_library {
+			name: "mylib",
+			srcs: ["mylib.cpp"],
+			system_shared_libs: [],
+			stl: "none",
+			stubs: {
+				versions: ["1"],
+			},
+			apex_available: ["myapex"],
+		}
+
+		cc_library {
+			name: "myprivlib",
+			srcs: ["mylib.cpp"],
+			system_shared_libs: [],
+			stl: "none",
+			apex_available: ["myapex"],
+		}
+
+
+		cc_test {
+			name: "mytest",
+			gtest: false,
+			srcs: ["mylib.cpp"],
+			system_shared_libs: [],
+			stl: "none",
+			shared_libs: ["mylib", "myprivlib"],
+			test_for: ["myapex"]
+		}
+	`)
+
+	// the test 'mytest' is a test for the apex, therefore is linked to the
+	// actual implementation of mylib instead of its stub.
+	ldFlags := ctx.ModuleForTests("mytest", "android_arm64_armv8-a").Rule("ld").Args["libFlags"]
+	ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so")
+	ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so")
+}
+
 func TestMain(m *testing.M) {
 	run := func() int {
 		setUp()
diff --git a/cc/builder.go b/cc/builder.go
index d8e90b6..990069d 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -38,13 +38,6 @@
 )
 
 var (
-	abiCheckAllowFlags = []string{
-		"-allow-unreferenced-changes",
-		"-allow-unreferenced-elf-symbol-changes",
-	}
-)
-
-var (
 	pctx = android.NewPackageContext("android/soong/cc")
 
 	cc = pctx.AndroidRemoteStaticRule("cc", android.RemoteRuleSupports{Goma: true, RBE: true},
@@ -221,8 +214,7 @@
 
 	sAbiDiff = pctx.RuleFunc("sAbiDiff",
 		func(ctx android.PackageRuleContext) blueprint.RuleParams {
-			// TODO(b/78139997): Add -check-all-apis back
-			commandStr := "($sAbiDiffer ${allowFlags} -lib ${libName} -arch ${arch} -o ${out} -new ${in} -old ${referenceDump})"
+			commandStr := "($sAbiDiffer ${extraFlags} -lib ${libName} -arch ${arch} -o ${out} -new ${in} -old ${referenceDump})"
 			commandStr += "|| (echo 'error: Please update ABI references with: $$ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py ${createReferenceDumpFlags} -l ${libName}'"
 			commandStr += " && (mkdir -p $$DIST_DIR/abidiffs && cp ${out} $$DIST_DIR/abidiffs/)"
 			commandStr += " && exit 1)"
@@ -231,7 +223,7 @@
 				CommandDeps: []string{"$sAbiDiffer"},
 			}
 		},
-		"allowFlags", "referenceDump", "libName", "arch", "createReferenceDumpFlags")
+		"extraFlags", "referenceDump", "libName", "arch", "createReferenceDumpFlags")
 
 	unzipRefSAbiDump = pctx.AndroidStaticRule("unzipRefSAbiDump",
 		blueprint.RuleParams{
@@ -742,27 +734,36 @@
 }
 
 func SourceAbiDiff(ctx android.ModuleContext, inputDump android.Path, referenceDump android.Path,
-	baseName, exportedHeaderFlags string, isLlndk, isNdk, isVndkExt bool) android.OptionalPath {
+	baseName, exportedHeaderFlags string, checkAllApis, isLlndk, isNdk, isVndkExt bool) android.OptionalPath {
 
 	outputFile := android.PathForModuleOut(ctx, baseName+".abidiff")
 	libName := strings.TrimSuffix(baseName, filepath.Ext(baseName))
 	createReferenceDumpFlags := ""
 
-	localAbiCheckAllowFlags := append([]string(nil), abiCheckAllowFlags...)
-	if exportedHeaderFlags == "" {
-		localAbiCheckAllowFlags = append(localAbiCheckAllowFlags, "-advice-only")
+	var extraFlags []string
+	if checkAllApis {
+		extraFlags = append(extraFlags, "-check-all-apis")
+	} else {
+		extraFlags = append(extraFlags,
+			"-allow-unreferenced-changes",
+			"-allow-unreferenced-elf-symbol-changes")
 	}
+
+	if exportedHeaderFlags == "" {
+		extraFlags = append(extraFlags, "-advice-only")
+	}
+
 	if isLlndk || isNdk {
 		createReferenceDumpFlags = "--llndk"
 		if isLlndk {
 			// TODO(b/130324828): "-consider-opaque-types-different" should apply to
 			// both LLNDK and NDK shared libs. However, a known issue in header-abi-diff
 			// breaks libaaudio. Remove the if-guard after the issue is fixed.
-			localAbiCheckAllowFlags = append(localAbiCheckAllowFlags, "-consider-opaque-types-different")
+			extraFlags = append(extraFlags, "-consider-opaque-types-different")
 		}
 	}
 	if isVndkExt {
-		localAbiCheckAllowFlags = append(localAbiCheckAllowFlags, "-allow-extensions")
+		extraFlags = append(extraFlags, "-allow-extensions")
 	}
 
 	ctx.Build(pctx, android.BuildParams{
@@ -775,7 +776,7 @@
 			"referenceDump":            referenceDump.String(),
 			"libName":                  libName,
 			"arch":                     ctx.Arch().ArchType.Name,
-			"allowFlags":               strings.Join(localAbiCheckAllowFlags, " "),
+			"extraFlags":               strings.Join(extraFlags, " "),
 			"createReferenceDumpFlags": createReferenceDumpFlags,
 		},
 	})
diff --git a/cc/cc.go b/cc/cc.go
index 24173ee..66425c7 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -2338,6 +2338,15 @@
 						// always link to non-stub variant
 						useThisDep = !depIsStubs
 					}
+					for _, testFor := range c.TestFor() {
+						// Another exception: if this module is bundled with an APEX, then
+						// it is linked with the non-stub variant of a module in the APEX
+						// as if this is part of the APEX.
+						if android.DirectlyInApex(testFor, depName) {
+							useThisDep = !depIsStubs
+							break
+						}
+					}
 				} else {
 					// If building for APEX, use stubs only when it is not from
 					// the same APEX
@@ -2764,6 +2773,16 @@
 	}
 }
 
+func (c *Module) TestFor() []string {
+	if test, ok := c.linker.(interface {
+		testFor() []string
+	}); ok {
+		return test.testFor()
+	} else {
+		return c.ApexModuleBase.TestFor()
+	}
+}
+
 // Return true if the module is ever installable.
 func (c *Module) EverInstallable() bool {
 	return c.installer != nil &&
diff --git a/cc/libbuildversion/Android.bp b/cc/libbuildversion/Android.bp
index 825b920..b63338d 100644
--- a/cc/libbuildversion/Android.bp
+++ b/cc/libbuildversion/Android.bp
@@ -10,4 +10,8 @@
             enabled: true,
         },
     },
+    apex_available: [
+        "//apex_available:platform",
+        "//apex_available:anyapex",
+    ],
 }
diff --git a/cc/library.go b/cc/library.go
index e79d9bd..ecea2ea 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -102,6 +102,10 @@
 
 		// Symbol tags that should be ignored from the symbol file
 		Exclude_symbol_tags []string
+
+		// Run checks on all APIs (in addition to the ones referred by
+		// one of exported ELF symbols.)
+		Check_all_apis *bool
 	}
 
 	// Order symbols in .bss section by their sizes.  Only useful for shared libraries.
@@ -1072,7 +1076,9 @@
 		refAbiDumpFile := getRefAbiDumpFile(ctx, vndkVersion, fileName)
 		if refAbiDumpFile != nil {
 			library.sAbiDiff = SourceAbiDiff(ctx, library.sAbiOutputFile.Path(),
-				refAbiDumpFile, fileName, exportedHeaderFlags, ctx.isLlndk(ctx.Config()), ctx.isNdk(), ctx.isVndkExt())
+				refAbiDumpFile, fileName, exportedHeaderFlags,
+				Bool(library.Properties.Header_abi_checker.Check_all_apis),
+				ctx.isLlndk(ctx.Config()), ctx.isNdk(), ctx.isVndkExt())
 		}
 	}
 }
@@ -1501,18 +1507,22 @@
 	return ""
 }
 
-func checkVersions(ctx android.BaseModuleContext, versions []string) {
+func normalizeVersions(ctx android.BaseModuleContext, versions []string) {
 	numVersions := make([]int, len(versions))
 	for i, v := range versions {
-		numVer, err := strconv.Atoi(v)
+		numVer, err := android.ApiStrToNum(ctx, v)
 		if err != nil {
-			ctx.PropertyErrorf("versions", "%q is not a number", v)
+			ctx.PropertyErrorf("versions", "%s", err.Error())
+			return
 		}
 		numVersions[i] = numVer
 	}
 	if !sort.IsSorted(sort.IntSlice(numVersions)) {
 		ctx.PropertyErrorf("versions", "not sorted: %v", versions)
 	}
+	for i, v := range numVersions {
+		versions[i] = strconv.Itoa(v)
+	}
 }
 
 func createVersionVariations(mctx android.BottomUpMutatorContext, versions []string) {
@@ -1542,7 +1552,7 @@
 	if library, ok := mctx.Module().(LinkableInterface); ok && VersionVariantAvailable(library) {
 		if library.CcLibrary() && library.BuildSharedVariant() && len(library.StubsVersions()) > 0 {
 			versions := library.StubsVersions()
-			checkVersions(mctx, versions)
+			normalizeVersions(mctx, versions)
 			if mctx.Failed() {
 				return
 			}
diff --git a/cc/library_test.go b/cc/library_test.go
index b8d8895..cb16725 100644
--- a/cc/library_test.go
+++ b/cc/library_test.go
@@ -17,6 +17,8 @@
 import (
 	"reflect"
 	"testing"
+
+	"android/soong/android"
 )
 
 func TestLibraryReuse(t *testing.T) {
@@ -186,3 +188,55 @@
 		}
 	})
 }
+
+func TestStubsVersions(t *testing.T) {
+	bp := `
+		cc_library {
+			name: "libfoo",
+			srcs: ["foo.c"],
+			stubs: {
+				versions: ["29", "R", "10000"],
+			},
+		}
+	`
+	config := TestConfig(buildDir, android.Android, nil, bp, nil)
+	config.TestProductVariables.Platform_version_active_codenames = []string{"R"}
+	ctx := testCcWithConfig(t, config)
+
+	variants := ctx.ModuleVariantsForTests("libfoo")
+	for _, expectedVer := range []string{"29", "9000", "10000"} {
+		expectedVariant := "android_arm_armv7-a-neon_shared_" + expectedVer
+		if !inList(expectedVariant, variants) {
+			t.Errorf("missing expected variant: %q", expectedVariant)
+		}
+	}
+}
+
+func TestStubsVersions_NotSorted(t *testing.T) {
+	bp := `
+		cc_library {
+			name: "libfoo",
+			srcs: ["foo.c"],
+			stubs: {
+				versions: ["29", "10000", "R"],
+			},
+		}
+	`
+	config := TestConfig(buildDir, android.Android, nil, bp, nil)
+	config.TestProductVariables.Platform_version_active_codenames = []string{"R"}
+	testCcErrorWithConfig(t, `"libfoo" .*: versions: not sorted`, config)
+}
+
+func TestStubsVersions_ParseError(t *testing.T) {
+	bp := `
+		cc_library {
+			name: "libfoo",
+			srcs: ["foo.c"],
+			stubs: {
+				versions: ["29", "10000", "X"],
+			},
+		}
+	`
+
+	testCcError(t, `"libfoo" .*: versions: SDK version should be`, bp)
+}
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index 68d4ac0..1597b88 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -96,6 +96,8 @@
 	Unversioned_until *string
 
 	// Private property for use by the mutator that splits per-API level.
+	// can be one of <number:sdk_version> or <codename> or "current"
+	// passed to "gen_stub_libs.py" as it is
 	ApiLevel string `blueprint:"mutated"`
 
 	// True if this API is not yet ready to be shipped in the NDK. It will be
diff --git a/cc/test.go b/cc/test.go
index 1085d3a..f51cf01 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -29,6 +29,11 @@
 
 	// if set, use the isolated gtest runner. Defaults to false.
 	Isolated *bool
+
+	// List of APEXes that this module tests. The module has access to
+	// the private part of the listed APEXes even when it is not included in the
+	// APEXes.
+	Test_for []string
 }
 
 // Test option struct.
@@ -215,6 +220,10 @@
 	return BoolDefault(test.Properties.Gtest, true)
 }
 
+func (test *testDecorator) testFor() []string {
+	return test.Properties.Test_for
+}
+
 func (test *testDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
 	if !test.gtest() {
 		return flags
diff --git a/java/builder.go b/java/builder.go
index 98f70cd..6844809 100644
--- a/java/builder.go
+++ b/java/builder.go
@@ -196,7 +196,7 @@
 	classpath      classpath
 	java9Classpath classpath
 	processorPath  classpath
-	processor      string
+	processors     []string
 	systemModules  *systemModules
 	aidlFlags      string
 	aidlDeps       android.Paths
@@ -270,8 +270,8 @@
 	deps = append(deps, flags.processorPath...)
 
 	processor := "-proc:none"
-	if flags.processor != "" {
-		processor = "-processor " + flags.processor
+	if len(flags.processors) > 0 {
+		processor = "-processor " + strings.Join(flags.processors, ",")
 	}
 
 	intermediatesDir := "xref"
@@ -385,8 +385,8 @@
 	deps = append(deps, flags.processorPath...)
 
 	processor := "-proc:none"
-	if flags.processor != "" {
-		processor = "-processor " + flags.processor
+	if len(flags.processors) > 0 {
+		processor = "-processor " + strings.Join(flags.processors, ",")
 	}
 
 	srcJarDir := "srcjars"
diff --git a/java/java.go b/java/java.go
index 61974f5..38f485e 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1134,7 +1134,8 @@
 	flags.java9Classpath = append(flags.java9Classpath, deps.java9Classpath...)
 	flags.processorPath = append(flags.processorPath, deps.processorPath...)
 
-	flags.processor = strings.Join(deps.processorClasses, ",")
+	flags.processors = append(flags.processors, deps.processorClasses...)
+	flags.processors = android.FirstUniqueStrings(flags.processors)
 
 	if len(flags.bootClasspath) == 0 && ctx.Host() && !flags.javaVersion.usesJavaModules() &&
 		decodeSdkDep(ctx, sdkContext(j)).hasStandardLibs() {
@@ -1269,7 +1270,7 @@
 			srcJars = append(srcJars, kaptSrcJar)
 			// Disable annotation processing in javac, it's already been handled by kapt
 			flags.processorPath = nil
-			flags.processor = ""
+			flags.processors = nil
 		}
 
 		kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
diff --git a/java/kotlin.go b/java/kotlin.go
index cb7da20..9b160a0 100644
--- a/java/kotlin.go
+++ b/java/kotlin.go
@@ -136,8 +136,11 @@
 	kaptProcessorPath := flags.processorPath.FormRepeatedClassPath("-P plugin:org.jetbrains.kotlin.kapt3:apclasspath=")
 
 	kaptProcessor := ""
-	if flags.processor != "" {
-		kaptProcessor = "-P plugin:org.jetbrains.kotlin.kapt3:processors=" + flags.processor
+	for i, p := range flags.processors {
+		if i > 0 {
+			kaptProcessor += " "
+		}
+		kaptProcessor += "-P plugin:org.jetbrains.kotlin.kapt3:processors=" + p
 	}
 
 	encodedJavacFlags := kaptEncodeFlags([][2]string{
diff --git a/java/kotlin_test.go b/java/kotlin_test.go
index 5c6d45f..60ca1c4 100644
--- a/java/kotlin_test.go
+++ b/java/kotlin_test.go
@@ -88,7 +88,7 @@
 		java_library {
 			name: "foo",
 			srcs: ["a.java", "b.kt"],
-			plugins: ["bar"],
+			plugins: ["bar", "baz"],
 		}
 
 		java_plugin {
@@ -96,6 +96,12 @@
 			processor_class: "com.bar",
 			srcs: ["b.java"],
 		}
+
+		java_plugin {
+			name: "baz",
+			processor_class: "com.baz",
+			srcs: ["b.java"],
+		}
 		`)
 
 	buildOS := android.BuildOs.String()
@@ -105,6 +111,7 @@
 	javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
 
 	bar := ctx.ModuleForTests("bar", buildOS+"_common").Rule("javac").Output.String()
+	baz := ctx.ModuleForTests("baz", buildOS+"_common").Rule("javac").Output.String()
 
 	// Test that the kotlin and java sources are passed to kapt and kotlinc
 	if len(kapt.Inputs) != 2 || kapt.Inputs[0].String() != "a.java" || kapt.Inputs[1].String() != "b.kt" {
@@ -136,11 +143,12 @@
 	}
 
 	// Test that the processors are passed to kapt
-	expectedProcessorPath := "-P plugin:org.jetbrains.kotlin.kapt3:apclasspath=" + bar
+	expectedProcessorPath := "-P plugin:org.jetbrains.kotlin.kapt3:apclasspath=" + bar +
+		" -P plugin:org.jetbrains.kotlin.kapt3:apclasspath=" + baz
 	if kapt.Args["kaptProcessorPath"] != expectedProcessorPath {
 		t.Errorf("expected kaptProcessorPath %q, got %q", expectedProcessorPath, kapt.Args["kaptProcessorPath"])
 	}
-	expectedProcessor := "-P plugin:org.jetbrains.kotlin.kapt3:processors=com.bar"
+	expectedProcessor := "-P plugin:org.jetbrains.kotlin.kapt3:processors=com.bar -P plugin:org.jetbrains.kotlin.kapt3:processors=com.baz"
 	if kapt.Args["kaptProcessor"] != expectedProcessor {
 		t.Errorf("expected kaptProcessor %q, got %q", expectedProcessor, kapt.Args["kaptProcessor"])
 	}
diff --git a/rust/rust_test.go b/rust/rust_test.go
index 020581d..02b190f 100644
--- a/rust/rust_test.go
+++ b/rust/rust_test.go
@@ -215,25 +215,6 @@
 			srcs: ["foo.rs"],
 			crate_name: "bar",
 		}
-		// Make a dummy libstd to let resolution go through
-		rust_library_dylib {
-			name: "libstd",
-			crate_name: "std",
-			srcs: ["foo.rs"],
-			no_stdlibs: true,
-		}
-		rust_library_dylib {
-			name: "libterm",
-			crate_name: "term",
-			srcs: ["foo.rs"],
-			no_stdlibs: true,
-		}
-		rust_library_dylib {
-			name: "libtest",
-			crate_name: "test",
-			srcs: ["foo.rs"],
-			no_stdlibs: true,
-		}
 		rust_proc_macro {
 			name: "libpm",
 			rlibs: ["libbar"],
diff --git a/rust/testing.go b/rust/testing.go
index f9adec8..c3a4625 100644
--- a/rust/testing.go
+++ b/rust/testing.go
@@ -22,51 +22,11 @@
 func GatherRequiredDepsForTest() string {
 	bp := `
 		rust_prebuilt_dylib {
-				name: "libarena_x86_64-unknown-linux-gnu",
-				srcs: [""],
-				host_supported: true,
-		}
-		rust_prebuilt_dylib {
-				name: "libfmt_macros_x86_64-unknown-linux-gnu",
-				srcs: [""],
-				host_supported: true,
-		}
-		rust_prebuilt_dylib {
-				name: "libgraphviz_x86_64-unknown-linux-gnu",
-				srcs: [""],
-				host_supported: true,
-		}
-		rust_prebuilt_dylib {
-				name: "libserialize_x86_64-unknown-linux-gnu",
-				srcs: [""],
-				host_supported: true,
-		}
-		rust_prebuilt_dylib {
 				name: "libstd_x86_64-unknown-linux-gnu",
 				srcs: [""],
 				host_supported: true,
 		}
 		rust_prebuilt_dylib {
-				name: "libsyntax_x86_64-unknown-linux-gnu",
-				srcs: [""],
-				host_supported: true,
-		}
-		rust_prebuilt_dylib {
-				name: "libsyntax_ext_x86_64-unknown-linux-gnu",
-				srcs: [""],
-				host_supported: true,
-		}
-		rust_prebuilt_dylib {
-				name: "libsyntax_pos_x86_64-unknown-linux-gnu",
-				srcs: [""],
-				host_supported: true,
-		}
-		rust_prebuilt_dylib {
-				name: "libterm_x86_64-unknown-linux-gnu",
-				srcs: [""],
-				host_supported: true,
-		}
-		rust_prebuilt_dylib {
 				name: "libtest_x86_64-unknown-linux-gnu",
 				srcs: [""],
 				host_supported: true,
@@ -81,6 +41,31 @@
 			nocrt: true,
 			system_shared_libs: [],
 		}
+		rust_library_dylib {
+			name: "libstd",
+			crate_name: "std",
+			srcs: ["foo.rs"],
+			no_stdlibs: true,
+		}
+		rust_library_rlib {
+			name: "libstd.static",
+			crate_name: "std",
+			srcs: ["foo.rs"],
+			no_stdlibs: true,
+		}
+		rust_library_dylib {
+			name: "libtest",
+			crate_name: "test",
+			srcs: ["foo.rs"],
+			no_stdlibs: true,
+		}
+		rust_library_rlib {
+			name: "libtest.static",
+			crate_name: "test",
+			srcs: ["foo.rs"],
+			no_stdlibs: true,
+		}
+
 ` + cc.GatherRequiredDepsForTest(android.NoOsType)
 	return bp
 }
diff --git a/scripts/build-aml-prebuilts.sh b/scripts/build-aml-prebuilts.sh
index 35a6ff3..7408349 100755
--- a/scripts/build-aml-prebuilts.sh
+++ b/scripts/build-aml-prebuilts.sh
@@ -50,15 +50,20 @@
 mkdir -p ${SOONG_OUT}
 SOONG_VARS=${SOONG_OUT}/soong.variables
 
+# We enable bionic linux builds as ART also needs prebuilts for it.
+# Enabling bionic linux requires setting allow_missing_dependencies.
 cat > ${SOONG_VARS}.new << EOF
 {
     "Platform_sdk_version": ${PLATFORM_SDK_VERSION},
     "Platform_sdk_codename": "${PLATFORM_VERSION}",
     "Platform_version_active_codenames": ${PLATFORM_VERSION_ALL_CODENAMES},
+    "Allow_missing_dependencies": true,
 
     "DeviceName": "generic_arm64",
     "HostArch": "x86_64",
     "HostSecondaryArch": "x86",
+    "CrossHost": "linux_bionic",
+    "CrossHostArch": "x86_64",
     "Aml_abis": true,
 
     "UseGoma": ${USE_GOMA}