| 
									
										
										
										
											2021-11-24 12:51:52 +00:00
										 |  |  |  | using System; | 
					
						
							|  |  |  |  | using System.Collections.Generic; | 
					
						
							| 
									
										
										
										
											2020-07-06 01:41:21 +00:00
										 |  |  |  | using UnityEditor; | 
					
						
							| 
									
										
										
										
											2023-02-12 12:18:35 +00:00
										 |  |  |  | using System.Reflection; | 
					
						
							| 
									
										
										
										
											2020-07-06 01:41:21 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | namespace UnityBuilderAction.Input | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   public class AndroidSettings | 
					
						
							|  |  |  |  |   { | 
					
						
							|  |  |  |  |     public static void Apply(Dictionary<string, string> options) | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-10-15 18:52:15 +00:00
										 |  |  |  | #if UNITY_2019_1_OR_NEWER | 
					
						
							| 
									
										
										
										
											2020-07-06 01:41:21 +00:00
										 |  |  |  |       if (options.TryGetValue("androidKeystoreName", out string keystoreName) && !string.IsNullOrEmpty(keystoreName)) | 
					
						
							| 
									
										
										
										
											2022-05-20 23:40:23 +00:00
										 |  |  |  |       { | 
					
						
							|  |  |  |  |         PlayerSettings.Android.useCustomKeystore = true; | 
					
						
							| 
									
										
										
										
											2020-07-06 01:41:21 +00:00
										 |  |  |  |         PlayerSettings.Android.keystoreName = keystoreName; | 
					
						
							| 
									
										
										
										
											2022-05-20 23:40:23 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2022-10-15 18:52:15 +00:00
										 |  |  |  | #endif | 
					
						
							| 
									
										
										
										
											2023-02-12 11:45:54 +00:00
										 |  |  |  |       // Can't use out variable declaration as Unity 2018 doesn't support it | 
					
						
							|  |  |  |  |       string keystorePass; | 
					
						
							|  |  |  |  |       if (options.TryGetValue("androidKeystorePass", out keystorePass) && !string.IsNullOrEmpty(keystorePass)) | 
					
						
							| 
									
										
										
										
											2020-07-06 01:41:21 +00:00
										 |  |  |  |         PlayerSettings.Android.keystorePass = keystorePass; | 
					
						
							| 
									
										
										
										
											2023-02-12 11:45:54 +00:00
										 |  |  |  |        | 
					
						
							| 
									
										
										
										
											2023-02-12 12:02:50 +00:00
										 |  |  |  |       string keyaliasName; | 
					
						
							| 
									
										
										
										
											2023-02-12 11:45:54 +00:00
										 |  |  |  |       if (options.TryGetValue("androidKeyaliasName", out keyaliasName) && !string.IsNullOrEmpty(keyaliasName)) | 
					
						
							| 
									
										
										
										
											2020-07-06 01:41:21 +00:00
										 |  |  |  |         PlayerSettings.Android.keyaliasName = keyaliasName; | 
					
						
							| 
									
										
										
										
											2023-02-12 11:45:54 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |       string keyaliasPass; | 
					
						
							|  |  |  |  |       if (options.TryGetValue("androidKeyaliasPass", out keyaliasPass) && !string.IsNullOrEmpty(keyaliasPass)) | 
					
						
							| 
									
										
										
										
											2020-07-06 01:41:21 +00:00
										 |  |  |  |         PlayerSettings.Android.keyaliasPass = keyaliasPass; | 
					
						
							| 
									
										
										
										
											2023-02-12 11:45:54 +00:00
										 |  |  |  |        | 
					
						
							|  |  |  |  |       string androidTargetSdkVersion; | 
					
						
							|  |  |  |  |       if (options.TryGetValue("androidTargetSdkVersion", out androidTargetSdkVersion) && !string.IsNullOrEmpty(androidTargetSdkVersion)) | 
					
						
							| 
									
										
										
										
											2022-08-11 12:35:01 +00:00
										 |  |  |  |       { | 
					
						
							|  |  |  |  |           var targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto; | 
					
						
							|  |  |  |  |           try | 
					
						
							|  |  |  |  |           { | 
					
						
							|  |  |  |  |               targetSdkVersion = | 
					
						
							|  |  |  |  |                   (AndroidSdkVersions) Enum.Parse(typeof(AndroidSdkVersions), androidTargetSdkVersion); | 
					
						
							|  |  |  |  |           } | 
					
						
							|  |  |  |  |           catch | 
					
						
							|  |  |  |  |           { | 
					
						
							|  |  |  |  |               UnityEngine.Debug.Log("Failed to parse androidTargetSdkVersion! Fallback to AndroidApiLevelAuto"); | 
					
						
							|  |  |  |  |           } | 
					
						
							|  |  |  |  |           PlayerSettings.Android.targetSdkVersion = targetSdkVersion; | 
					
						
							|  |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2023-02-11 10:45:03 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-12 11:45:54 +00:00
										 |  |  |  |       string androidExportType; | 
					
						
							|  |  |  |  |       if (options.TryGetValue("androidExportType", out androidExportType) && !string.IsNullOrEmpty(androidExportType)) | 
					
						
							| 
									
										
										
										
											2023-02-11 08:17:43 +00:00
										 |  |  |  |       { | 
					
						
							| 
									
										
										
										
											2023-02-12 12:02:50 +00:00
										 |  |  |  |         // Only exists in 2018.3 and above | 
					
						
							|  |  |  |  |         FieldInfo buildAppBundle = typeof(EditorUserBuildSettings) | 
					
						
							|  |  |  |  |               .GetField("buildAppBundle", System.Reflection.BindingFlags.Public | BindingFlags.Instance); | 
					
						
							| 
									
										
										
										
											2023-02-11 10:45:03 +00:00
										 |  |  |  |         switch (androidExportType) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |           case "androidStudioProject": | 
					
						
							|  |  |  |  |             EditorUserBuildSettings.exportAsGoogleAndroidProject = true; | 
					
						
							| 
									
										
										
										
											2023-02-12 12:02:50 +00:00
										 |  |  |  |             if (buildAppBundle != null) | 
					
						
							|  |  |  |  |               buildAppBundle.SetValue(null, false); | 
					
						
							| 
									
										
										
										
											2023-02-11 10:45:03 +00:00
										 |  |  |  |             break; | 
					
						
							|  |  |  |  |           case "androidAppBundle": | 
					
						
							|  |  |  |  |             EditorUserBuildSettings.exportAsGoogleAndroidProject = false; | 
					
						
							| 
									
										
										
										
											2023-02-12 12:02:50 +00:00
										 |  |  |  |             if (buildAppBundle != null) | 
					
						
							|  |  |  |  |               buildAppBundle.SetValue(null, true); | 
					
						
							| 
									
										
										
										
											2023-02-11 10:45:03 +00:00
										 |  |  |  |             break; | 
					
						
							| 
									
										
										
										
											2023-02-12 12:02:50 +00:00
										 |  |  |  |           case "androidPackage": | 
					
						
							| 
									
										
										
										
											2023-02-11 10:45:03 +00:00
										 |  |  |  |             EditorUserBuildSettings.exportAsGoogleAndroidProject = false; | 
					
						
							| 
									
										
										
										
											2023-02-12 12:02:50 +00:00
										 |  |  |  |             if (buildAppBundle != null) | 
					
						
							|  |  |  |  |               buildAppBundle.SetValue(null, false); | 
					
						
							| 
									
										
										
										
											2023-02-11 10:45:03 +00:00
										 |  |  |  |             break; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-02-11 08:17:43 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2023-02-12 05:45:49 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-12 11:45:54 +00:00
										 |  |  |  |       string symbolType; | 
					
						
							|  |  |  |  |       if (options.TryGetValue("androidSymbolType", out symbolType) && !string.IsNullOrEmpty(symbolType)) | 
					
						
							| 
									
										
										
										
											2023-02-12 05:45:49 +00:00
										 |  |  |  |       { | 
					
						
							| 
									
										
										
										
											2023-02-12 11:11:53 +00:00
										 |  |  |  | #if UNITY_2021_1_OR_NEWER | 
					
						
							|  |  |  |  |         switch (symbolType) | 
					
						
							| 
									
										
										
										
											2023-02-12 05:45:49 +00:00
										 |  |  |  |         { | 
					
						
							|  |  |  |  |           case "public": | 
					
						
							|  |  |  |  |             EditorUserBuildSettings.androidCreateSymbols = AndroidCreateSymbols.Public; | 
					
						
							|  |  |  |  |             break; | 
					
						
							|  |  |  |  |           case "debugging": | 
					
						
							|  |  |  |  |             EditorUserBuildSettings.androidCreateSymbols = AndroidCreateSymbols.Debugging; | 
					
						
							|  |  |  |  |             break; | 
					
						
							|  |  |  |  |           case "none": | 
					
						
							|  |  |  |  |             EditorUserBuildSettings.androidCreateSymbols = AndroidCreateSymbols.Disabled; | 
					
						
							|  |  |  |  |             break; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-02-12 11:11:53 +00:00
										 |  |  |  | #elif UNITY_2019_2_OR_NEWER | 
					
						
							|  |  |  |  |         switch (symbolType) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |           case "public": | 
					
						
							|  |  |  |  |           case "debugging": | 
					
						
							|  |  |  |  |             EditorUserBuildSettings.androidCreateSymbolsZip = true; | 
					
						
							|  |  |  |  |             break; | 
					
						
							|  |  |  |  |           case "none": | 
					
						
							|  |  |  |  |             EditorUserBuildSettings.androidCreateSymbolsZip = false; | 
					
						
							|  |  |  |  |             break; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | #endif | 
					
						
							| 
									
										
										
										
											2023-02-12 05:45:49 +00:00
										 |  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-07-06 01:41:21 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | } |