Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/Xamarin.Android.Build.Tasks/Tasks/Aot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class Aot : AsyncTask
[Required]
public string SdkBinDirectory { get; set; }

[Required]
public ITaskItem ManifestFile { get; set; }

[Required]
public ITaskItem[] ResolvedAssemblies { get; set; }

Expand Down Expand Up @@ -168,9 +171,22 @@ static bool ValidateAotConfiguration (TaskLoggingHelper log, AndroidTargetArch a
return true;
}

static int GetNdkApiLevel(string androidNdkPath, string androidApiLevel, AndroidTargetArch arch)
int GetNdkApiLevel(string androidNdkPath, string androidApiLevel, AndroidTargetArch arch)
{
int level = int.Parse(androidApiLevel);
var manifest = AndroidAppManifest.Load (ManifestFile.ItemSpec);

int level;
if (manifest.MinSdkVersion.HasValue) {
level = manifest.MinSdkVersion.Value;
}
else if (int.TryParse (androidApiLevel, out level)) {
// level already set
}
else {
// Probably not ideal!
level = AndroidVersion.MaxApiLevel;
}

// Some Android API levels do not exist on the NDK level. Workaround this my mapping them to the
// most appropriate API level that does exist.
if (level == 6 || level == 7) level = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using Microsoft.Build.Framework;
using NUnit.Framework;
Expand Down Expand Up @@ -209,12 +210,29 @@ public void BuildAotApplication (string supportedAbis, bool enableLLVM, bool exp
proj.SetProperty (KnownProperties.TargetFrameworkVersion, "v5.1");
proj.SetProperty (KnownProperties.AndroidSupportedAbis, supportedAbis);
proj.SetProperty ("EnableLLVM", enableLLVM.ToString ());
if (enableLLVM) {
// Set //uses-sdk/@android:minSdkVersion so that LLVM uses the right libc.so
proj.AndroidManifest = $@"<?xml version=""1.0"" encoding=""utf-8""?>
<manifest xmlns:android=""http://schemas.android.com/apk/res/android"" android:versionCode=""1"" android:versionName=""1.0"" package=""{proj.PackageName}"">
<uses-sdk android:minSdkVersion=""10"" />
<application android:label=""{proj.ProjectName}"">
</application>
</manifest>";
}
using (var b = CreateApkBuilder (path)) {
b.ThrowOnBuildFailure = false;
b.Verbosity = LoggerVerbosity.Diagnostic;
Assert.AreEqual (expectedResult, b.Build (proj), "Build should have {0}.", expectedResult ? "succeeded" : "failed");
if (!expectedResult)
return;
if (enableLLVM) {
// LLVM passes a direct path to libc.so, and we need to use the libc.so
// which corresponds to the *minimum* SDK version specified in AndroidManifest.xml
// Since we overrode minSdkVersion=10, that means we should use libc.so from android-9.
var rightLibc = new Regex (@"^\s*\[AOT\].*cross-.*--llvm.*,ld-flags=.*android-9.arch-.*.usr.lib.libc\.so", RegexOptions.Multiline);
var m = rightLibc.Match (b.LastBuildOutput);
Assert.IsTrue (m.Success, "AOT+LLVM should use libc.so from minSdkVersion!");
}
foreach (var abi in supportedAbis.Split (new char [] { ';' })) {
var libapp = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath,
"bundles", abi, "libmonodroid_bundle_app.so");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2145,6 +2145,7 @@ because xbuild doesn't support framework reference assemblies.
AndroidNdkDirectory="$(_AndroidNdkDirectory)"
AndroidApiLevel="$(_AndroidApiLevel)"
SdkBinDirectory="$(MonoAndroidBinDirectory)"
ManifestFile="$(IntermediateOutputPath)android\AndroidManifest.xml"
SupportedAbis="$(_BuildTargetAbis)"
AndroidSequencePointsMode="$(_SequencePointsMode)"
AotAdditionalArguments="$(AndroidAotAdditionalArguments)"
Expand Down