diff --git a/build-tools/android-toolchain/android-toolchain.projitems b/build-tools/android-toolchain/android-toolchain.projitems index 7ddf02309b3..ce7ad78a844 100644 --- a/build-tools/android-toolchain/android-toolchain.projitems +++ b/build-tools/android-toolchain/android-toolchain.projitems @@ -137,7 +137,7 @@ <_NdkToolchain Include="arm-linux-androideabi-clang" Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains(':armeabi:')) Or $(AndroidSupportedTargetJitAbisForConditionalChecks.Contains(':armeabi-v7a:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-armeabi:'))"> - 9 + 14 arm <_NdkToolchain Include="aarch64-linux-android-clang" Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains(':arm64-v8a:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-arm64:'))"> @@ -145,7 +145,7 @@ arm64 <_NdkToolchain Include="x86-clang" Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains(':x86:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-x86:'))"> - 9 + 14 x86 <_NdkToolchain Include="x86_64-clang" Condition="$(AndroidSupportedTargetJitAbisForConditionalChecks.Contains(':x86_64:')) Or $(AndroidSupportedTargetAotAbisForConditionalChecks.Contains (':win-x86_64:'))"> diff --git a/build-tools/scripts/RunTests.targets b/build-tools/scripts/RunTests.targets index 92ce345062c..78708ec8fde 100644 --- a/build-tools/scripts/RunTests.targets +++ b/build-tools/scripts/RunTests.targets @@ -17,6 +17,7 @@ <_TestAssembly Include="$(_TopDir)\bin\Test$(Configuration)\Xamarin.Android.Build.Tests.dll" /> <_ApkTestProject Include="$(_TopDir)\src\Mono.Android\Test\Mono.Android-Tests.csproj" /> <_ApkTestProject Include="$(_TopDir)\tests\CodeGen-Binding\Xamarin.Android.JcwGen-Tests\Xamarin.Android.JcwGen-Tests.csproj" /> + <_ApkTestProject Include="$(_TopDir)\tests\CodeGen-MkBundle\Xamarin.Android.MakeBundle-Tests\Xamarin.Android.MakeBundle-Tests.csproj" /> <_ApkTestProject Include="$(_TopDir)\tests\locales\Xamarin.Android.Locale-Tests\Xamarin.Android.Locale-Tests.csproj" /> <_ApkTestProject Include="$(_TopDir)\tests\Xamarin.Android.Bcl-Tests\Xamarin.Android.Bcl-Tests.csproj" /> <_ApkTestProject Include="$(_TopDir)\tests\Xamarin.Forms-Performance-Integration\Droid\Xamarin.Forms.Performance.Integration.Droid.csproj" /> diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/MakeBundleNativeCodeExternal.cs b/src/Xamarin.Android.Build.Tasks/Tasks/MakeBundleNativeCodeExternal.cs index 9399ca438b4..9405388bfe5 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/MakeBundleNativeCodeExternal.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/MakeBundleNativeCodeExternal.cs @@ -169,12 +169,24 @@ bool DoExecute () clb = new CommandLineBuilder (); clb.AppendSwitch ("-c"); + + // This is necessary only when unified headers are in use but it won't hurt to have it + // defined even if we don't use them + clb.AppendSwitch ($"-D__ANDROID_API__={level}"); + clb.AppendSwitch ("-o"); clb.AppendFileNameIfNotNull (Path.Combine (outpath, "temp.o")); if (!string.IsNullOrWhiteSpace (IncludePath)) { clb.AppendSwitch ("-I"); clb.AppendFileNameIfNotNull (IncludePath); } + + string asmIncludePath = NdkUtil.GetNdkAsmIncludePath (AndroidNdkDirectory, arch, level); + if (!String.IsNullOrEmpty (asmIncludePath)) { + clb.AppendSwitch ("-I"); + clb.AppendFileNameIfNotNull (asmIncludePath); + } + clb.AppendSwitch ("-I"); clb.AppendFileNameIfNotNull (NdkUtil.GetNdkPlatformIncludePath (AndroidNdkDirectory, arch, level)); clb.AppendFileNameIfNotNull (Path.Combine (outpath, "temp.c")); diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/NdkUtils.cs b/src/Xamarin.Android.Build.Tasks/Tasks/NdkUtils.cs index ce89695662a..5ffc0820866 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/NdkUtils.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/NdkUtils.cs @@ -95,11 +95,69 @@ public static string GetNdkTool (string androidNdkPath, AndroidTargetArch arch, return null; } - public static string GetNdkPlatformIncludePath (string androidNdkPath, AndroidTargetArch arch, int level) + static string GetUnifiedHeadersPath (string androidNdkPath) + { + return Path.Combine (androidNdkPath, "sysroot", "usr", "include"); + } + + static string GetPerPlatformHeadersPath (string androidNdkPath, AndroidTargetArch arch, int level) + { + return Path.Combine (androidNdkPath, "platforms", "android-" + level, "arch-" + GetPlatformArch (arch), "usr", "include"); + } + + public static string GetNdkAsmIncludePath (string androidNdkPath, AndroidTargetArch arch, int level) { - string path = Path.Combine (androidNdkPath, "platforms", "android-" + level, "arch-" + GetPlatformArch (arch), "usr", "include"); + string path = GetPerPlatformHeadersPath (androidNdkPath, arch, level); + if (Directory.Exists (path)) + return null; + + path = GetUnifiedHeadersPath (androidNdkPath); if (!Directory.Exists (path)) + return null; + + string archDir = null; + switch (arch) { + case AndroidTargetArch.Arm: + archDir = "arm-linux-androideabi"; + break; + + case AndroidTargetArch.Arm64: + archDir = "aarch64-linux-android"; + break; + + case AndroidTargetArch.Mips: + archDir = "mipsel-linux-android"; + break; + + case AndroidTargetArch.X86: + archDir = "i686-linux-android"; + break; + + case AndroidTargetArch.X86_64: + archDir = "x86_64-linux-android"; + break; + } + + if (archDir == null) + return null; + + return Path.Combine (path, archDir); + } + + public static string GetNdkPlatformIncludePath (string androidNdkPath, AndroidTargetArch arch, int level) + { + // This is for NDK older than r16 which isn't configured to use unified headers. We + string path = GetPerPlatformHeadersPath (androidNdkPath, arch, level); + if (!Directory.Exists (path)) { + // This is for NDK r15 (if configured to use unified headers) or NDK r16+ (which doesn't have + // the per-platform includes anymore) + path = GetUnifiedHeadersPath (androidNdkPath); + if (Directory.Exists (path)) + return path; + throw new InvalidOperationException (String.Format ("Platform header files for target {0} and API Level {1} was not found. Expected path is \"{2}\"", arch, level, path)); + } + return path; } @@ -257,7 +315,7 @@ public static IEnumerable GetSupportedPlatforms (string androidNdkPath) public static int GetMinimumApiLevelFor (AndroidTargetArch arch, string androidNdkPath) { - var minValue = NdkUtil.IsNdk64BitArch (arch) ? 21 : arch == AndroidTargetArch.Arm ? 4 : 9; + var minValue = NdkUtil.IsNdk64BitArch (arch) ? 21 : 14; var platforms = GetSupportedPlatforms (androidNdkPath).OrderBy (x => x).Where (x => x >= minValue); return platforms.First (x => Directory.Exists (Path.Combine (androidNdkPath, "platforms", $"android-{x}", $"arch-{archPathMap[arch]}"))); }