Skip to content

Fixes #322, Use the raw property value when the enum does not contain this value #399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
21 changes: 15 additions & 6 deletions source/AndroidResolver/src/UnityCompat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,20 @@ private static int AndroidPlatformVersionFallback {
}

// Parses a UnityEditor.AndroidSDKVersion enum for a value.
private static int VersionFromAndroidSDKVersionsEnum(string enumName, string fallbackPrefKey,
private static int VersionFromAndroidSDKVersionsEnum(object enumValue, string fallbackPrefKey,
int fallbackValue) {
// If the enum property has no name it's not possible to parse the version so fallback to
// auto-selection.
if (String.IsNullOrEmpty(enumName)) return -1;
string enumName = null;
try {
enumName = Enum.GetName(typeof(AndroidSdkVersions), enumValue);
} catch (ArgumentException) {
//Fall back on auto if the enum value is not parsable
return -1;
}

// If the enumName is empty then enumValue was not represented in the enum,
// most likely because Unity has not yet added the new version,
// fall back on the raw enumValue
if (String.IsNullOrEmpty(enumName)) return (int)enumValue;

if (enumName.StartsWith(UNITY_ANDROID_VERSION_ENUM_PREFIX)) {
enumName = enumName.Substring(UNITY_ANDROID_VERSION_ENUM_PREFIX.Length);
Expand Down Expand Up @@ -91,7 +100,7 @@ private static int VersionFromAndroidSDKVersionsEnum(string enumName, string fal
/// <returns>the sdk value (ie. 24 for Android 7.0 Nouget)</returns>
public static int GetAndroidMinSDKVersion() {
int minSdkVersion = VersionFromAndroidSDKVersionsEnum(
PlayerSettings.Android.minSdkVersion.ToString(),
(object)PlayerSettings.Android.minSdkVersion,
ANDROID_MIN_SDK_FALLBACK_KEY, MinSDKVersionFallback);
if (minSdkVersion == -1)
return MinSDKVersionFallback;
Expand Down Expand Up @@ -121,7 +130,7 @@ public static int GetAndroidTargetSDKVersion() {
var property = typeof(UnityEditor.PlayerSettings.Android).GetProperty("targetSdkVersion");
int apiLevel = property == null ? -1 :
VersionFromAndroidSDKVersionsEnum(
Enum.GetName(property.PropertyType, property.GetValue(null, null)),
property.GetValue(null, null),
ANDROID_PLATFORM_FALLBACK_KEY, AndroidPlatformVersionFallback);
if (apiLevel >= 0) return apiLevel;
return FindNewestInstalledAndroidSDKVersion();
Expand Down