@@ -55,11 +55,20 @@ private static int AndroidPlatformVersionFallback {
55
55
}
56
56
57
57
// Parses a UnityEditor.AndroidSDKVersion enum for a value.
58
- private static int VersionFromAndroidSDKVersionsEnum ( string enumName , string fallbackPrefKey ,
58
+ private static int VersionFromAndroidSDKVersionsEnum ( object enumValue , string fallbackPrefKey ,
59
59
int fallbackValue ) {
60
- // If the enum property has no name it's not possible to parse the version so fallback to
61
- // auto-selection.
62
- if ( String . IsNullOrEmpty ( enumName ) ) return - 1 ;
60
+ string enumName = null ;
61
+ try {
62
+ enumName = Enum . GetName ( typeof ( AndroidSdkVersions ) , enumValue ) ;
63
+ } catch ( ArgumentException ) {
64
+ //Fall back on auto if the enum value is not parsable
65
+ return - 1 ;
66
+ }
67
+
68
+ // If the enumName is empty then enumValue was not represented in the enum,
69
+ // most likely because Unity has not yet added the new version,
70
+ // fall back on the raw enumValue
71
+ if ( String . IsNullOrEmpty ( enumName ) ) return ( int ) enumValue ;
63
72
64
73
if ( enumName . StartsWith ( UNITY_ANDROID_VERSION_ENUM_PREFIX ) ) {
65
74
enumName = enumName . Substring ( UNITY_ANDROID_VERSION_ENUM_PREFIX . Length ) ;
@@ -91,7 +100,7 @@ private static int VersionFromAndroidSDKVersionsEnum(string enumName, string fal
91
100
/// <returns>the sdk value (ie. 24 for Android 7.0 Nouget)</returns>
92
101
public static int GetAndroidMinSDKVersion ( ) {
93
102
int minSdkVersion = VersionFromAndroidSDKVersionsEnum (
94
- PlayerSettings . Android . minSdkVersion . ToString ( ) ,
103
+ ( object ) PlayerSettings . Android . minSdkVersion ,
95
104
ANDROID_MIN_SDK_FALLBACK_KEY , MinSDKVersionFallback ) ;
96
105
if ( minSdkVersion == - 1 )
97
106
return MinSDKVersionFallback ;
@@ -121,7 +130,7 @@ public static int GetAndroidTargetSDKVersion() {
121
130
var property = typeof ( UnityEditor . PlayerSettings . Android ) . GetProperty ( "targetSdkVersion" ) ;
122
131
int apiLevel = property == null ? - 1 :
123
132
VersionFromAndroidSDKVersionsEnum (
124
- Enum . GetName ( property . PropertyType , property . GetValue ( null , null ) ) ,
133
+ property . GetValue ( null , null ) ,
125
134
ANDROID_PLATFORM_FALLBACK_KEY , AndroidPlatformVersionFallback ) ;
126
135
if ( apiLevel >= 0 ) return apiLevel ;
127
136
return FindNewestInstalledAndroidSDKVersion ( ) ;
0 commit comments