Merge "Add export_include_dirs to the local include path"
diff --git a/android/config.go b/android/config.go
index f6ca2e7..725f43d 100644
--- a/android/config.go
+++ b/android/config.go
@@ -323,8 +323,12 @@
 	return "M"
 }
 
+func (c *config) PlatformSdkVersionInt() int {
+	return *c.ProductVariables.Platform_sdk_version
+}
+
 func (c *config) PlatformSdkVersion() string {
-	return strconv.Itoa(*c.ProductVariables.Platform_sdk_version)
+	return strconv.Itoa(c.PlatformSdkVersionInt())
 }
 
 func (c *config) BuildNumber() string {
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index 48fbf4d..94be17c 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -139,16 +139,7 @@
 }
 
 func generateStubApiVariants(mctx android.BottomUpMutatorContext, c *stubDecorator) {
-	// TODO(danalbert): Use PlatformSdkVersion when possible.
-	// This is an interesting case because for the moment we actually need 24
-	// even though the latest released version in aosp is 23. prebuilts/ndk/r11
-	// has android-24 versions of libraries, and as platform libraries get
-	// migrated the libraries in prebuilts will need to depend on them.
-	//
-	// Once everything is all moved over to the new stuff (when there isn't a
-	// prebuilts/ndk any more) then this should be fixable, but for now I think
-	// it needs to remain as-is.
-	maxVersion := 24
+	maxVersion := mctx.AConfig().PlatformSdkVersionInt()
 
 	firstVersion, err := normalizeNdkApiLevel(c.properties.First_version,
 		mctx.Arch())
diff --git a/root.bp b/root.bp
index 76e7aee..f2fb8b7 100644
--- a/root.bp
+++ b/root.bp
@@ -14,6 +14,7 @@
     "build/kati",
     "build/tools/*",
     "dalvik",
+    "development/ndk",
     "external/*",
     "frameworks/av",
     "frameworks/base",
diff --git a/scripts/build-ndk-prebuilts.sh b/scripts/build-ndk-prebuilts.sh
index cc418d4..65a2329 100755
--- a/scripts/build-ndk-prebuilts.sh
+++ b/scripts/build-ndk-prebuilts.sh
@@ -7,13 +7,17 @@
 
 TOP=$(pwd)
 
+source build/envsetup.sh
+PLATFORM_SDK_VERSION=$(get_build_var PLATFORM_SDK_VERSION)
+
 SOONG_OUT=${OUT_DIR}/soong
 SOONG_NDK_OUT=${OUT_DIR}/soong/ndk
 rm -rf ${SOONG_OUT}
 mkdir -p ${SOONG_OUT}
 cat > ${SOONG_OUT}/soong.config << EOF
 {
-    "Ndk_abis": true
+    "Ndk_abis": true,
+    "Platform_sdk_version": ${PLATFORM_SDK_VERSION}
 }
 EOF
 BUILDDIR=${SOONG_OUT} ./bootstrap.bash