Skip to content

Commit

Permalink
[Xamarin.Android.Build.Utilities] Add AndroidVersions (dotnet#599)
Browse files Browse the repository at this point in the history
Commit 8e7d37b is a sign of duplication: in order to use a
`Mono.Android.dll` binding assembly, not only do we need to *build*
the binding assembly, but we *also* need to update
`Xamarin.Android.Build.Utilities.dll` to "know" about the new binding
version (to map API level to `$(TargetFrameworkVersion)`).

Even "better" (worse), if the new API level is a *preview*, there is
no *consistent* API level. For example, with API-O, `android.jar`
isn't at
`$(AndroidSdkDirectory)\platforms\android-@API_LEVEL@\android.jar`,
where `@API_LEVEL@` is 26 (because various codepaths require that the
"api level" be an integer). Instead, it's installed at
`$(AndroidSdkDirectory)\platforms\android-O\android.jar`, where
`O` is the "id" of the preview API level.

This "id" is "leaky", in turn requiring that
`Xamarin.Android.Build.Tasks.dll` *also* be updated to deal with the
mappings.

Even "better" (worse), if we *forget* to cross all our our 't's and
dot all of our 'i's, we'll have a binding assembly which can't be
used. (Which is why we needed commit 8e7d37b; without it, the API-O
binding can't be used!)

This is all obviously madness. ;-)

Clean this mess up:

 1. Update `src/Mono.Android` to create a new `AndroidApiInfo.xml`
    file within the `$(TargetFrameworkVersion)` directory.
    This will contain all the information needed to map Android API
    levels to Ids and Android OS versions and
    `$(TargetFrameworkVersion)` values.

    ```xml
    <AndroidApiInfo>
      <Id>10</Id>
      <Level>10</Level>
      <Name>Gingerbread</Name>
      <Version>v2.3</Version>
    </AndroidApiInfo>
    ```

 2. Add a new `Xamarin.Android.Build.Utilities.AndroidVersions` type
    which looks for and parses these new `AndroidApiInfo.xml` files.

 3. Fixup all the other places using `AndroidVersion.KnownVersions`
    and related members to instead use `AndroidVersions`.

 4. Remove all the old APIs which rely on hardcoded data.

The advantage to all this is that we can support new API level
bindings by just building a new `Mono.Android.dll` and placing an
`AndroidApiInfo.xml` into the appropriate location (next to
`Mono.Android.dll`). No further code changes would be required.

Related: The build system still has a nasy habit of using system-wide
directories to resolve files we'd really rather it not, e.g. in
[xamarin-android/master build dotnet#503][m503]:

[m503]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android/503/consoleText

	Building target "_GetReferenceAssemblyPaths" in project "/Users/builder/jenkins/workspace/xamarin-android/xamarin-android/src/Xamarin.Android.NUnitLite/Xamarin.Android.NUnitLite.csproj" ("/Users/builder/jenkins/workspace/xamarin-android/xamarin-android/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/Xamarin.Android.Common.targets"); "_SetLatestTargetFrameworkVersion" depends on it.
	  Target _GetReferenceAssemblyPaths:
	  Task "GetReferenceAssemblyPaths"
	    Using task GetReferenceAssemblyPaths from Microsoft.Build.Tasks.GetReferenceAssemblyPaths, Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
	    Looking for framework 'MonoAndroid,Version=v1.0' in root path '/Library/Frameworks/Mono.framework/External/xbuild-frameworks'
	    Found framework definition list '/Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/RedistList/FrameworkList.xml' for framework 'MonoAndroid,Version=v1.0'
	  Done executing task "GetReferenceAssemblyPaths"
	  Done building target "_GetReferenceAssemblyPaths" in project "/Users/builder/jenkins/workspace/xamarin-android/xamarin-android/src/Xamarin.Android.NUnitLite/Xamarin.Android.NUnitLite.csproj".
	Done building target "_GetReferenceAssemblyPaths" in project "/Users/builder/jenkins/workspace/xamarin-android/xamarin-android/src/Xamarin.Android.NUnitLite/Xamarin.Android.NUnitLite.csproj" ("/Users/builder/jenkins/workspace/xamarin-android/xamarin-android/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/Xamarin.Android.Common.targets"); "_SetLatestTargetFrameworkVersion" depends on it.
	  Target _SetLatestTargetFrameworkVersion:
	  Task "ResolveSdks"
	    ReferenceAssemblyPaths:
	      /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/

Note the use of the path
`/Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0`.

This *was* "fine" -- if undesirable -- but with the introduction of
`AndroidVersions` and `AndroidApiInfo.xml` files within the frameworks
directory, everything falls apart, becuase the system install
*does not have* the `AndroidApiInfo.xml` files, so
*NO API LEVELS ARE FOUND*.

Oops.

The only way to fix this is to use `$XBUILD_FRAMEWORK_FOLDERS_PATH`,
and the sanest way to do *that* is to use `tools/scripts/xabuild` for
the primary build.

Unfortunately, using `xabuild` for the primary build breaks the
`msbuild`-based build, as it can't resolve the
`.NETFramework,Version=v4.6.1` framework.

Context: dotnet#599 (comment)

Split the difference here by introducing `$(_SLN_BUILD)`: use
`xabuild` when building with `xbuild`, and continue using `msbuild`
when building with `msbuild`.
  • Loading branch information
jonpryor authored Aug 23, 2017
1 parent 9aeacdd commit 8942eca
Show file tree
Hide file tree
Showing 20 changed files with 439 additions and 539 deletions.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ export MONO_OPTIONS
endif

include build-tools/scripts/msbuild.mk

ifeq ($(USE_MSBUILD),1)
_SLN_BUILD = $(MSBUILD)
else # $(MSBUILD) != 1
_SLN_BUILD = MSBUILD="$(MSBUILD)" tools/scripts/xabuild
endif # $(USE_MSBUILD) == 1

all::
$(MSBUILD) $(MSBUILD_FLAGS) $(SOLUTION)
$(_SLN_BUILD) $(MSBUILD_FLAGS) $(SOLUTION)

all-tests::
MSBUILD="$(MSBUILD)" tools/scripts/xabuild $(MSBUILD_FLAGS) Xamarin.Android-Tests.sln
Expand Down
137 changes: 137 additions & 0 deletions src/Mono.Android/Mono.Android.projitems
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<AndroidApiInfo Include="v1.6">
<Name>Donut</Name>
<Level>4</Level>
<Id>4</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v2.0">
<Name>Eclair</Name>
<Level>5</Level>
<Id>5</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v2.0.1">
<Name>Eclair</Name>
<Level>6</Level>
<Id>6</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v2.1">
<Name>Eclair</Name>
<Level>7</Level>
<Id>7</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v2.2">
<Name>Froyo</Name>
<Level>8</Level>
<Id>8</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v2.3">
<Name>Gingerbread</Name>
<Level>10</Level>
<Id>10</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v3.0">
<Name>Honeycomb</Name>
<Level>11</Level>
<Id>11</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v3.1">
<Name>Honeycomb</Name>
<Level>12</Level>
<Id>12</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v3.2">
<Name>Honeycomb</Name>
<Level>13</Level>
<Id>13</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v4.0">
<Name>Ice Cream Sandwich</Name>
<Level>14</Level>
<Id>14</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v4.0.3">
<Name>Ice Cream Sandwich</Name>
<Level>15</Level>
<Id>15</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v4.1">
<Name>Jelly Bean</Name>
<Level>16</Level>
<Id>16</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v4.2">
<Name>Jelly Bean</Name>
<Level>17</Level>
<Id>17</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v4.3">
<Name>Jelly Bean</Name>
<Level>18</Level>
<Id>18</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v4.4">
<Name>Kit Kat</Name>
<Level>19</Level>
<Id>19</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v4.4.87">
<Name>Kit Kat + Wear support</Name>
<Level>20</Level>
<Id>20</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v5.0">
<Name>Lollipop</Name>
<Level>21</Level>
<Id>21</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v5.1">
<Name>Lollipop</Name>
<Level>22</Level>
<Id>22</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v6.0">
<Name>Marshmallow</Name>
<Level>23</Level>
<Id>23</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v7.0">
<Name>Nougat</Name>
<Level>24</Level>
<Id>24</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v7.1">
<Name>Nougat</Name>
<Level>25</Level>
<Id>25</Id>
<Stable>True</Stable>
</AndroidApiInfo>
<AndroidApiInfo Include="v8.0">
<Name>Oreo</Name>
<Level>26</Level>
<Id>26</Id>
<Stable>True</Stable>
</AndroidApiInfo>
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions src/Mono.Android/Mono.Android.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="..\..\bin\Build$(Configuration)\xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.ReplaceFileContents" />
<Import Project="..\..\build-tools\scripts\XAVersionInfo.targets" />
<Import Project="Mono.Android.projitems" />
<ItemGroup>
<Compile Include="$(IntermediateOutputPath)AssemblyInfo.cs" />
</ItemGroup>
Expand Down Expand Up @@ -120,6 +121,30 @@
Overwrite="True"
/>
</Target>
<Target Name="_GenerateAndroidApiInfo"
BeforeTargets="_GenerateFrameworkList"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(OutputPath)AndroidApiInfo.xml">
<MakeDir Directories="$(OutputPath)" />
<ItemGroup>
<_ApiInfo
Condition=" '%(Identity)' == '$(AndroidFrameworkVersion)' "
Include="@(AndroidApiInfo)"
/>
<_Line Include="&lt;AndroidApiInfo&gt;" />
<_Line Include="@(_ApiInfo->' &lt;Id>%(Id)&lt;/Id>')" />
<_Line Include="@(_ApiInfo->' &lt;Level>%(Level)&lt;/Level>')" />
<_Line Include="@(_ApiInfo->' &lt;Name>%(Name)&lt;/Name>')" />
<_Line Include="@(_ApiInfo->' &lt;Version>%(Identity)&lt;/Version>')" />
<_Line Include="@(_ApiInfo->' &lt;Stable>%(Stable)&lt;/Stable>')" />
<_Line Include="&lt;/AndroidApiInfo&gt;" />
</ItemGroup>
<WriteLinesToFile
File="$(OutputPath)AndroidApiInfo.xml"
Lines="@(_Line)"
Overwrite="True"
/>
</Target>
<Target Name="_CleanBinding"
AfterTargets="Clean">
<RemoveDir Directories="$(IntermediateOutputPath)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int ExtractApiLevel(DirectoryAssemblyResolver res, ITaskItem ass)
var value = p.Value.ToString ();
if (value.StartsWith ("MonoAndroid")) {
var values = value.Split ('=');
return AndroidVersion.TryOSVersionToApiLevel (values[1]);
return MonoAndroidHelper.SupportedVersions.GetApiLevelFromFrameworkVersion (values [1]) ?? 0;
}
}
break;
Expand All @@ -61,9 +61,9 @@ public override bool Execute ()
}
}

var mainapiLevel = AndroidVersion.TryOSVersionToApiLevel (TargetFrameworkVersion);
var mainapiLevel = MonoAndroidHelper.SupportedVersions.GetApiLevelFromFrameworkVersion (TargetFrameworkVersion);
foreach (var item in apiLevels.Where (x => mainapiLevel < x.Value)) {
var itemOSVersion = AndroidVersion.TryApiLevelToOSVersion (item.Value);
var itemOSVersion = MonoAndroidHelper.SupportedVersions.GetFrameworkVersionFromApiLevel (item.Value);
Log.LogWarning (null, "XA0105", null, ProjectFile, 0, 0, 0, 0,
"The $(TargetFrameworkVersion) for {0} (v{1}) is greater than the $(TargetFrameworkVersion) for your project ({2}). " +
"You need to increase the $(TargetFrameworkVersion) for your project.", Path.GetFileName (item.Key.ItemSpec), itemOSVersion, TargetFrameworkVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override bool Execute ()
Log.LogDebugTaskItems (" ResolvedUserAssemblies:", ResolvedUserAssemblies);

var shared_runtime = string.Compare (UseSharedRuntime, "true", true) == 0;
var doc = AndroidAppManifest.Load (Manifest);
var doc = AndroidAppManifest.Load (Manifest, MonoAndroidHelper.SupportedVersions);
int minApiVersion = doc.MinSdkVersion == null ? 4 : (int) doc.MinSdkVersion;
// We need to include any special assemblies in the Assemblies list
var assemblies = ResolvedUserAssemblies.Select (p => p.ItemSpec)
Expand Down Expand Up @@ -93,7 +93,7 @@ public override bool Execute ()
// Write the platform api apk we need
pkgmgr.WriteLine ("\tpublic static final String ApiPackageName = {0};", shared_runtime
? string.Format ("\"Mono.Android.Platform.ApiLevel_{0}\"",
MonoDroidSdk.GetApiLevelForFrameworkVersion (TargetFrameworkVersion))
MonoAndroidHelper.SupportedVersions.GetApiLevelFromFrameworkVersion (TargetFrameworkVersion))
: "null");
pkgmgr.WriteLine ("}");
}
Expand Down
10 changes: 5 additions & 5 deletions src/Xamarin.Android.Build.Tasks/Tasks/GetJavaPlatformJar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public override bool Execute ()
}

platform = GetTargetSdkVersion (platform, target_sdk);
JavaPlatformJarPath = Path.Combine (AndroidSdkDirectory, "platforms", "android-" + MonoAndroidHelper.GetPlatformApiLevelName (platform), "android.jar");
JavaPlatformJarPath = Path.Combine (AndroidSdk.GetPlatformDirectoryFromApiLevel (platform, MonoAndroidHelper.SupportedVersions), "android.jar");

if (!File.Exists (JavaPlatformJarPath)) {
Log.LogError ("Could not find android.jar for API Level {0}. " +
Expand All @@ -92,8 +92,8 @@ public override bool Execute ()

string GetTargetSdkVersion (string target, XAttribute target_sdk)
{
string targetFrameworkVersion = MonoAndroidHelper.GetPlatformApiLevel (AndroidSdkPlatform);
string targetSdkVersion = MonoAndroidHelper.GetPlatformApiLevel (target);
string targetFrameworkVersion = MonoAndroidHelper.SupportedVersions.GetIdFromApiLevel (AndroidSdkPlatform);
string targetSdkVersion = MonoAndroidHelper.SupportedVersions.GetIdFromApiLevel (target);

int frameworkSdk, targetSdk;
if (int.TryParse (targetFrameworkVersion, out frameworkSdk) &&
Expand All @@ -118,8 +118,8 @@ string GetTargetSdkVersion (string target, XAttribute target_sdk)
message: "AndroidManifest.xml //uses-sdk/@android:targetSdkVersion '{0}' is less than $(TargetFrameworkVersion) '{1}'. Using API-{2} for ACW compilation.",
messageArgs: new[]{
targetSdkVersion,
MonoDroidSdk.GetFrameworkVersionForApiLevel (targetFrameworkVersion),
MonoAndroidHelper.GetPlatformApiLevelName (targetFrameworkVersion),
MonoAndroidHelper.SupportedVersions.GetIdFromFrameworkVersion (targetFrameworkVersion),
MonoAndroidHelper.SupportedVersions.GetIdFromApiLevel (targetFrameworkVersion),
}
);
return targetFrameworkVersion;
Expand Down
5 changes: 2 additions & 3 deletions src/Xamarin.Android.Build.Tasks/Tasks/JarToXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public override bool Execute ()
Log.LogDebugMessage (" Java7DocPaths: {0}", Java7DocPaths);
Log.LogDebugMessage (" Java8DocPaths: {0}", Java8DocPaths);
Log.LogDebugTaskItems (" JavaDocs: {0}", JavaDocs);
Log.LogDebugMessage (" AndroidApiLevel: {0}", AndroidApiLevel);
Log.LogDebugTaskItems (" LibraryProjectJars:", LibraryProjectJars);
Log.LogDebugTaskItems (" SourceJars:", SourceJars);
Log.LogDebugTaskItems (" ReferenceJars:", ReferenceJars);
Expand All @@ -69,7 +68,7 @@ public override bool Execute ()
}

// Ensure that the user has the platform they are targeting installed
var jarpath = Path.Combine (AndroidSdkDirectory, "platforms", "android-" + MonoAndroidHelper.GetPlatformApiLevelName (AndroidApiLevel), "android.jar");
var jarpath = Path.Combine (AndroidSdk.GetPlatformDirectoryFromApiLevel (AndroidApiLevel, MonoAndroidHelper.SupportedVersions), "android.jar");

if (!File.Exists (jarpath)) {
Log.LogError ("Could not find android.jar for API Level {0}. This means the Android SDK platform for API Level {0} is not installed. Either install it in the Android SDK Manager, or change your Android Bindings project to target an API version that is installed. ({1} missing.)", AndroidApiLevel, jarpath);
Expand Down Expand Up @@ -128,7 +127,7 @@ protected override string GenerateCommandLineCommands ()
}

// Arguments sent to jar2xml
var jarpath = Path.Combine (AndroidSdkDirectory, "platforms", "android-" + MonoAndroidHelper.GetPlatformApiLevelName (AndroidApiLevel), "android.jar");
var jarpath = Path.Combine (AndroidSdk.GetPlatformDirectoryFromApiLevel (AndroidApiLevel, MonoAndroidHelper.SupportedVersions), "android.jar");
cmd.AppendSwitchIfNotNull ("--ref=", Path.GetFullPath (jarpath));

cmd.AppendSwitchIfNotNull ("--out=", Path.GetFullPath (OutputFile));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public bool RunTask ()

MonoAndroidHelper.TargetFrameworkDirectories = ReferenceAssemblyPaths;

MonoAndroidHelper.RefreshMonoDroidSdk (MonoAndroidToolsPath, MonoAndroidBinPath, ReferenceAssemblyPaths);
MonoAndroidHelper.RefreshSupportedVersions (ReferenceAssemblyPaths);
MonoAndroidHelper.RefreshAndroidSdk (AndroidSdkPath, AndroidNdkPath, JavaSdkPath);

return !Log.HasLoggedErrors;
Expand Down
19 changes: 9 additions & 10 deletions src/Xamarin.Android.Build.Tasks/Tasks/ResolveSdksTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public bool RunTask ()
}
MonoAndroidBinPath = MonoAndroidHelper.GetOSBinPath () + Path.DirectorySeparatorChar;

MonoAndroidHelper.RefreshMonoDroidSdk (MonoAndroidToolsPath, null, ReferenceAssemblyPaths);
MonoAndroidHelper.RefreshSupportedVersions (ReferenceAssemblyPaths);
MonoAndroidHelper.RefreshAndroidSdk (AndroidSdkPath, AndroidNdkPath, JavaSdkPath);

this.AndroidNdkPath = AndroidSdk.AndroidNdkPath;
Expand Down Expand Up @@ -237,8 +237,7 @@ public bool RunTask ()
if (!ValidateApiLevels ())
return false;

string frameworksPath = Path.GetDirectoryName (MonoDroidSdk.FrameworkPath);
if (!Directory.Exists (Path.Combine (frameworksPath, TargetFrameworkVersion))) {
if (!MonoAndroidHelper.SupportedVersions.FrameworkDirectories.Any (p => Directory.Exists (Path.Combine (p, TargetFrameworkVersion)))) {
Log.LogError (
subcategory: string.Empty,
errorCode: "XA0001",
Expand All @@ -263,7 +262,7 @@ public bool RunTask ()

MonoAndroidHelper.TargetFrameworkDirectories = ReferenceAssemblyPaths;

AndroidApiLevelName = MonoAndroidHelper.GetPlatformApiLevelName (AndroidApiLevel);
AndroidApiLevelName = MonoAndroidHelper.SupportedVersions.GetIdFromApiLevel (AndroidApiLevel);

Log.LogDebugMessage ("ResolveSdksTask Outputs:");
Log.LogDebugMessage (" AndroidApiLevel: {0}", AndroidApiLevel);
Expand Down Expand Up @@ -317,7 +316,7 @@ public bool RunTask ()

Version GetJavaVersionForFramework (string targetFrameworkVersion)
{
var apiLevel = AndroidVersion.TryOSVersionToApiLevel (targetFrameworkVersion);
var apiLevel = MonoAndroidHelper.SupportedVersions.GetApiLevelFromFrameworkVersion (targetFrameworkVersion);
if (apiLevel >= 24)
return new Version (1, 8);
else if (apiLevel == 23)
Expand Down Expand Up @@ -418,7 +417,7 @@ bool ValidateApiLevels ()

if (!string.IsNullOrWhiteSpace (TargetFrameworkVersion)) {
TargetFrameworkVersion = TargetFrameworkVersion.Trim ();
string apiLevel = MonoDroidSdk.GetApiLevelForFrameworkVersion (TargetFrameworkVersion);
string apiLevel = MonoAndroidHelper.SupportedVersions.GetIdFromFrameworkVersion (TargetFrameworkVersion);
if (apiLevel == null) {
Log.LogCodedError ("XA0000",
"Could not determine API level for $(TargetFrameworkVersion) of '{0}'.",
Expand All @@ -440,7 +439,7 @@ int GetMaxInstalledApiLevel ()
.Select (platformDir => Path.GetFileName (platformDir))
.Where (dir => dir.StartsWith ("android-", StringComparison.OrdinalIgnoreCase))
.Select (dir => dir.Substring ("android-".Length))
.Select (apiName => MonoAndroidHelper.GetPlatformApiLevel (apiName));
.Select (apiName => MonoAndroidHelper.SupportedVersions.GetIdFromApiLevel (apiName));
int maxApiLevel = int.MinValue;
foreach (var level in apiLevels) {
int v;
Expand All @@ -465,7 +464,7 @@ string GetMaxSupportedApiLevel (string apiLevel)
foreach (string versionedDir in ReferenceAssemblyPaths) {
string parent = Path.GetDirectoryName (versionedDir.TrimEnd (Path.DirectorySeparatorChar));
for ( int l = level ; l > 0; l--) {
string tfv = MonoDroidSdk.GetFrameworkVersionForApiLevel (l.ToString ());
string tfv = MonoAndroidHelper.SupportedVersions.GetFrameworkVersionFromApiLevel (l);
if (tfv == null)
continue;
string dir = Path.Combine (parent, tfv);
Expand All @@ -478,8 +477,8 @@ string GetMaxSupportedApiLevel (string apiLevel)

string GetTargetFrameworkVersionFromApiLevel ()
{
string targetFramework = MonoDroidSdk.GetFrameworkVersionForApiLevel (SupportedApiLevel) ??
MonoDroidSdk.GetFrameworkVersionForApiLevel (AndroidApiLevel);
string targetFramework = MonoAndroidHelper.SupportedVersions.GetFrameworkVersionFromId (SupportedApiLevel) ??
MonoAndroidHelper.SupportedVersions.GetFrameworkVersionFromId (AndroidApiLevel);
if (targetFramework != null)
return targetFramework;
Log.LogCodedError ("XA0000",
Expand Down
7 changes: 4 additions & 3 deletions src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public ManifestDocument (string templateFilename, TaskLoggingHelper log) : base
}

string SdkVersionName {
get { return MonoAndroidHelper.GetPlatformApiLevelName (SdkVersion); }
get { return MonoAndroidHelper.SupportedVersions.GetIdFromApiLevel (SdkVersion); }
}

string ToFullyQualifiedName (string typeName)
Expand Down Expand Up @@ -265,9 +265,10 @@ public IList<string> Merge (List<TypeDefinition> subclasses, List<string> select
uses.AddBeforeSelf (new XComment ("suppress UsesMinSdkAttributes"));
}

int targetSdkVersionValue;
if (!int.TryParse (MonoAndroidHelper.GetPlatformApiLevel (targetSdkVersion), out targetSdkVersionValue))
int? tryTargetSdkVersion = MonoAndroidHelper.SupportedVersions.GetApiLevelFromId (targetSdkVersion);
if (!tryTargetSdkVersion.HasValue)
throw new InvalidOperationException (string.Format ("The targetSdkVersion ({0}) is not a valid API level", targetSdkVersion));
int targetSdkVersionValue = tryTargetSdkVersion.Value;

foreach (var t in subclasses) {
if (t.IsAbstract)
Expand Down
Loading

0 comments on commit 8942eca

Please sign in to comment.