static AndroidAddOn GetAddOn(List <AndroidAddOnManifest> manifests, string sdkVersionName, string libraryName) { // try exact match AndroidAddOn addon = manifests.SelectMany(manifest => manifest.Libraries) .Where(ao => ao.Name == libraryName && ao.ApiLevel == sdkVersionName) .FirstOrDefault(); if (addon != null) { return(addon); } // Try to grab an addon with level <= sdkVersion // Requires that sdkVersion & AndroidAddOn.ApiLevel be convertible to System.Int32. // // So far preview L does not come up with google add-on, so it's OK to leave it unsupported. int targetLevel; if (!int.TryParse(sdkVersionName, out targetLevel)) { return(null); } int curLevel = int.MinValue; foreach (AndroidAddOn attempt in manifests.SelectMany(manifest => manifest.Libraries) .Where(ao => ao.Name == libraryName)) { int level; if (!int.TryParse(attempt.ApiLevel, out level)) { continue; } if (curLevel > level) { continue; } if (level > targetLevel) { continue; } curLevel = level; addon = attempt; } return(addon); }
internal static void AddAddOns(XElement app, string sdkDir, string sdkVersionName, IList <string> addonList) { List <AndroidAddOnManifest> manifests = AndroidAddOnManifest.GetAddOnManifests(sdkDir).ToList(); foreach (string library in app.Elements("uses-library") .Select(ul => { var n = (string)ul.Attribute(androidNs + "name"); return(n != null ? n.Trim() : n); }) .Where(ul => !string.IsNullOrEmpty(ul))) { AndroidAddOn addOn = GetAddOn(manifests, sdkVersionName, library); // uses-library could be used to specify such library that does not exist in // application or even on the host (even if "required" is true). The target // may contain that library. "android.test.runner" is such an example. if (addOn != null) { addonList.Add(addOn.JarPath); } } }