Merge "Android: use unified headers from the NDK"
diff --git a/build/BUILD.gn b/build/BUILD.gn
index 3a48665..3258166 100644
--- a/build/BUILD.gn
+++ b/build/BUILD.gn
@@ -107,9 +107,11 @@
   if (is_android) {
     asmflags += [ "--target=$android_abi_target" ]
     cflags += [
-      "-isystem$android_ndk_root/$android_sysroot_subdir/usr/include",
-      "--sysroot=$android_ndk_root/$android_sysroot_subdir",
+      "--sysroot=$android_compile_sysroot",
+      "-isystem$android_compile_sysroot/$android_compile_sysroot_subdir",
+      "-isystem$android_compile_sysroot",
       "-DANDROID",
+      "-D__ANDROID_API__=21",
       "--target=$android_abi_target",
     ]
     cflags_cc += [
@@ -121,7 +123,7 @@
       "-Wl,-z,nocopyreloc",
       "-gcc-toolchain",
       "$android_toolchain_root",
-      "--sysroot=$android_ndk_root/$android_sysroot_subdir",
+      "--sysroot=$android_ndk_root/$android_link_sysroot_subdir",
       "--target=$android_abi_target",
       "-Wl,--exclude-libs,libunwind.a",
       "-Wl,--exclude-libs,libgcc.a",
@@ -134,10 +136,7 @@
       "-Wl,--warn-shared-textrel",
       "-Wl,--fatal-warnings",
     ]
-    lib_dirs = [
-      "$android_ndk_root/sources/cxx-stl/llvm-libc++/libs/$android_app_abi",
-      "$android_ndk_root/$android_sysroot_subdir/usr/lib",
-    ]
+    lib_dirs = [ "$android_ndk_root/sources/cxx-stl/llvm-libc++/libs/$android_app_abi" ]
     libs += [
       "gcc",
       "c++_static",
diff --git a/build/android.gni b/build/android.gni
index ef620ee..e339eb2 100644
--- a/build/android.gni
+++ b/build/android.gni
@@ -29,29 +29,37 @@
 declare_args() {
   android_llvm_dir = "$android_ndk_root/toolchains/llvm/prebuilt/$android_host"
   android_clangrt_dir = "$android_llvm_dir/lib64/clang/5.0/lib/linux"
+  android_compile_sysroot = "$android_ndk_root/sysroot/usr/include"
 
   if (current_cpu == "x86") {
     android_abi_target = "i686-linux-androideabi"
-    android_sysroot_subdir = "platforms/android-${android_api_level}/arch-x86"
+    android_compile_sysroot_subdir = "i686-linux-android"
+    android_link_sysroot_subdir =
+        "platforms/android-${android_api_level}/arch-x86"
     android_prebuilt_arch = "android-x86"
     android_toolchain_root = "$android_ndk_root/toolchains/x86-${_android_toolchain_version}/prebuilt/$android_host"
     android_llvm_arch = "i686"
   } else if (current_cpu == "arm") {
     android_abi_target = "arm-linux-androideabi"
-    android_sysroot_subdir = "platforms/android-${android_api_level}/arch-arm"
+    android_compile_sysroot_subdir = "arm-linux-androideabi"
+    android_link_sysroot_subdir =
+        "platforms/android-${android_api_level}/arch-arm"
     android_prebuilt_arch = "android-arm"
     android_toolchain_root = "$android_ndk_root/toolchains/arm-linux-androideabi-${_android_toolchain_version}/prebuilt/$android_host"
     android_llvm_arch = "arm"
   } else if (current_cpu == "x64") {
     android_abi_target = "x86_64-linux-androideabi"
-    android_sysroot_subdir =
+    android_compile_sysroot_subdir = "x86_64-linux-android"
+    android_link_sysroot_subdir =
         "platforms/android-${android_api_level}/arch-x86_64"
     android_prebuilt_arch = "android-x86_64"
     android_toolchain_root = "$android_ndk_root/toolchains/x86_64-${_android_toolchain_version}/prebuilt/$android_host"
     android_llvm_arch = "x86_64"
   } else if (current_cpu == "arm64") {
     android_abi_target = "aarch64-linux-android"
-    android_sysroot_subdir = "platforms/android-${android_api_level}/arch-arm64"
+    android_compile_sysroot_subdir = "aarch64-linux-android"
+    android_link_sysroot_subdir =
+        "platforms/android-${android_api_level}/arch-arm64"
     android_prebuilt_arch = "android-arm64"
     android_toolchain_root = "$android_ndk_root/toolchains/aarch64-linux-android-${_android_toolchain_version}/prebuilt/$android_host"
     android_llvm_arch = "aarch64"