Revert "update: AppBuilder 打包脚本的优化, code review"
This reverts commit 8fe25996e7.
			
			
			
		
							parent
							
								
									8fe25996e7
								
							
						
					
					
						commit
						ae3d3764d8
					
				|  | @ -32,10 +32,6 @@ namespace Guru.Editor | ||||||
|         public string AndroidKeystorePass = ""; // Android KeyStore 文件名 |         public string AndroidKeystorePass = ""; // Android KeyStore 文件名 | ||||||
|         public string AndroidAlias = ""; // Android KeyStore 文件名 |         public string AndroidAlias = ""; // Android KeyStore 文件名 | ||||||
|         public string AndroidAliasPass = ""; // Android KeyStore 文件名 |         public string AndroidAliasPass = ""; // Android KeyStore 文件名 | ||||||
|         public string CustomGradlePath = ""; // 自定义 Gradle 路径 |  | ||||||
|         public string CustomJDKRoot = ""; // 自定义 JDK 路径  |  | ||||||
|         public string CustomNDKRoot = ""; // 自定义 NDK 路径  |  | ||||||
|         public string CustomAndroidSDKRoot = ""; // 自定义 AndroidSDK 路径  |  | ||||||
|         //------------ iOS ---------------- |         //------------ iOS ---------------- | ||||||
|         public string IOSTargetVersion = ""; // IOS SDK 版本设置 ( iOS 发布专用 ) |         public string IOSTargetVersion = ""; // IOS SDK 版本设置 ( iOS 发布专用 ) | ||||||
|         public string IOSTeamId = ""; // IOS 打包 TeamId ( iOS 使用专用的开发证书后开启 ) |         public string IOSTeamId = ""; // IOS 打包 TeamId ( iOS 使用专用的开发证书后开启 ) | ||||||
|  |  | ||||||
|  | @ -1,13 +1,16 @@ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| namespace Guru.Editor | namespace Guru.Editor | ||||||
| { | { | ||||||
| 	using System.Linq; | 	using System.Linq; | ||||||
| 	using System; | 	using System; | ||||||
|  |     using System.Collections; | ||||||
|     using System.Collections.Generic; |     using System.Collections.Generic; | ||||||
|     using UnityEngine; |     using UnityEngine; | ||||||
|     using UnityEditor; |     using UnityEditor; | ||||||
|     using System.IO; |     using System.IO; | ||||||
| 	using NUnit.Framework; | 	using NUnit.Framework; | ||||||
| 	 | 
 | ||||||
| 	/// <summary> | 	/// <summary> | ||||||
| 	/// 构建工具 | 	/// 构建工具 | ||||||
| 	/// </summary> | 	/// </summary> | ||||||
|  | @ -21,14 +24,8 @@ namespace Guru.Editor | ||||||
| 	    private const string GuruAliasName = "guru"; | 	    private const string GuruAliasName = "guru"; | ||||||
| 	    private const string GuruAliasPass = "guru0622"; | 	    private const string GuruAliasPass = "guru0622"; | ||||||
| 
 | 
 | ||||||
| 	    private const string DEFAULT_GRADLE_PATH_MAC_2021_3_41 = | 	    private const string UnityGradlePath_2021_3_41 = | ||||||
| 		    "/Applications/Unity/Hub/Editor/2021.3.41f1/PlaybackEngines/AndroidPlayer/Tools/gradle"; | 		    "/Applications/Unity/Hub/Editor/2021.3.41f1/PlaybackEngines/AndroidPlayer/Tools/gradle"; | ||||||
| 	    private const string DEFAULT_JDK_PATH_MAC_2021_3_41 = |  | ||||||
| 		    "/Applications/Unity/Hub/Editor/2021.3.41f1/PlaybackEngines/AndroidPlayer/OpenJDK"; |  | ||||||
| 	    private const string DEFAULT_NDK_PATH_MAC_2021_3_41 = |  | ||||||
| 		    "/Applications/Unity/Hub/Editor/2021.3.41f1/PlaybackEngines/AndroidPlayer/NDK"; |  | ||||||
| 	    private const string DEFAULT_ANDROID_SDK_MAC_2021_3_41 = |  | ||||||
| 		    "/Applications/Unity/Hub/Editor/2021.3.41f1/PlaybackEngines/AndroidPlayer/SDK"; |  | ||||||
| 	     | 	     | ||||||
| 	    private static string GuruKeystorePath => Application.dataPath + $"/Plugins/Android/{GuruKeystoreName}"; | 	    private static string GuruKeystorePath => Application.dataPath + $"/Plugins/Android/{GuruKeystoreName}"; | ||||||
| 	    private static string ProguardName => "proguard-user.txt"; | 	    private static string ProguardName => "proguard-user.txt"; | ||||||
|  | @ -79,11 +76,8 @@ namespace Guru.Editor | ||||||
| 		    SwitchBuildPlatform(BuildTarget.Android); | 		    SwitchBuildPlatform(BuildTarget.Android); | ||||||
| 		    // 打包通用设置 | 		    // 打包通用设置 | ||||||
| 		    ChangeBuildPlayerCommonSetting(buildParam, BuildTargetGroup.Android); | 		    ChangeBuildPlayerCommonSetting(buildParam, BuildTargetGroup.Android); | ||||||
| 		    // 设置打包环境 | 		    // Set GradlePath | ||||||
| 		    SetGradlePath(buildParam.CustomGradlePath); | 		    SetGradlePath(); | ||||||
| 		    SetJDKRoot(buildParam.CustomJDKRoot); |  | ||||||
| 		    SetNDKRoot(buildParam.CustomNDKRoot); |  | ||||||
| 		    SetAndroidSDKRoot(buildParam.CustomAndroidSDKRoot); |  | ||||||
| 		     | 		     | ||||||
| 		    var isDebug = !buildParam.IsBuildRelease; | 		    var isDebug = !buildParam.IsBuildRelease; | ||||||
| 		    var useMinify = buildParam.AndroidUseMinify; | 		    var useMinify = buildParam.AndroidUseMinify; | ||||||
|  | @ -127,17 +121,18 @@ namespace Guru.Editor | ||||||
| 			    PlayerSettings.Android.keyaliasPass = buildParam.AndroidAliasPass; | 			    PlayerSettings.Android.keyaliasPass = buildParam.AndroidAliasPass; | ||||||
| 		    } | 		    } | ||||||
| 
 | 
 | ||||||
| 		    PlayerSettings.Android.targetArchitectures = AndroidArchitecture.ARMv7 | AndroidArchitecture.ARM64; // 构建 armV7, arm64 | 		    PlayerSettings.Android.targetArchitectures = AndroidArchitecture.ARMv7 | AndroidArchitecture.ARM64; // 构建 armv7, arm64 | ||||||
| 	        PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel22; | 	        PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel22; | ||||||
| 	        PlayerSettings.Android.targetSdkVersion = (AndroidSdkVersions)androidTargetVersion;  // 设置 API Version | 	        PlayerSettings.Android.targetSdkVersion = (AndroidSdkVersions)androidTargetVersion;  // 设置 API Version | ||||||
| 	         | 	         | ||||||
| 	        //打包 | 	        //打包 | ||||||
| 	        string symbolDefine = buildParam.IsBuildRelease ? GameDefine.MACRO_RELEASE : GameDefine.MACRO_DEBUG; | 	        string symbolDefine = buildParam.IsBuildRelease ? GameDefine.MACRO_RELEASE : GameDefine.MACRO_DEBUG; | ||||||
|  | 	        string apkPath = string.Empty; | ||||||
| 	        string version = Application.version; | 	        string version = Application.version; | ||||||
| 	        string extension = buildParam.IsBuildAAB ? ".aab" : ".apk"; | 	        string extension = buildParam.IsBuildAAB ? ".aab" : ".apk"; | ||||||
| 	        if (EditorUserBuildSettings.exportAsGoogleAndroidProject) extension = ""; // 输出工程 | 	        if (EditorUserBuildSettings.exportAsGoogleAndroidProject) extension = ""; // 输出工程 | ||||||
| 		    string outputDir = Path.GetFullPath($"{Application.dataPath }/../{OutputDirName}/Android"); | 		    string outputDir = Path.GetFullPath($"{Application.dataPath }/../{OutputDirName}/Android"); | ||||||
| 	        var apkPath = $"{outputDir}/{Application.productName.Replace(" ","_")}_{symbolDefine}_{version}_{buildNumber}{extension}"; | 	        apkPath = $"{outputDir}/{Application.productName.Replace(" ","_")}_{symbolDefine}_{version}_{buildNumber}{extension}"; | ||||||
| 	        if (!Directory.Exists(outputDir)) Directory.CreateDirectory(outputDir); | 	        if (!Directory.Exists(outputDir)) Directory.CreateDirectory(outputDir); | ||||||
| 
 | 
 | ||||||
| 	        BuildOptions opts = isDebug ? BuildOptions.Development : BuildOptions.None; | 	        BuildOptions opts = isDebug ? BuildOptions.Development : BuildOptions.None; | ||||||
|  | @ -153,88 +148,13 @@ namespace Guru.Editor | ||||||
| 	        } | 	        } | ||||||
| 	        return apkPath; | 	        return apkPath; | ||||||
| 	    } | 	    } | ||||||
| 		 | 
 | ||||||
|         /// <summary> | 	    private static void SetGradlePath() | ||||||
|         /// 设置 GradlePath |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="gradlePath"></param> |  | ||||||
| 	    private static void SetGradlePath(string gradlePath = "") |  | ||||||
| 	    { | 	    { | ||||||
| 		    if (!string.IsNullOrEmpty(gradlePath)) | #if UNITY_ANDROID && UNITY_2021_3_41 | ||||||
|  | 		    if (Directory.Exists(UnityGradlePath_2021_3_41)) | ||||||
| 		    { | 		    { | ||||||
| 			    UnityEditor.Android.AndroidExternalToolsSettings.gradlePath = gradlePath; | 			    UnityEditor.Android.AndroidExternalToolsSettings.gradlePath = UnityGradlePath_2021_3_41; | ||||||
| 			    return; |  | ||||||
| 		    } |  | ||||||
| 		     |  | ||||||
| #if UNITY_2021_3_41 && UNITY_EDITOR_OSX |  | ||||||
| 		    // 针对 2021.3.41 MAC 版本,直接强制走Unity 自带的 Gradle 库 |  | ||||||
| 		    if (Directory.Exists(DEFAULT_GRADLE_PATH_MAC_2021_3_41)) |  | ||||||
| 		    { |  | ||||||
| 			    UnityEditor.Android.AndroidExternalToolsSettings.gradlePath = DEFAULT_GRADLE_PATH_MAC_2021_3_41; |  | ||||||
| 		    } |  | ||||||
| #endif |  | ||||||
| 	    } |  | ||||||
| 		 |  | ||||||
|         /// <summary> |  | ||||||
|         /// 设置自定义的JDK 路径 |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="jdkRoot"></param> |  | ||||||
| 	    private static void SetJDKRoot(string jdkRoot) |  | ||||||
| 	    { |  | ||||||
| 		    if (!string.IsNullOrEmpty(jdkRoot)) |  | ||||||
| 		    { |  | ||||||
| 			    UnityEditor.Android.AndroidExternalToolsSettings.jdkRootPath = jdkRoot; |  | ||||||
| 			    return; |  | ||||||
| 		    } |  | ||||||
| 		     |  | ||||||
| #if UNITY_2021_3_41 && UNITY_EDITOR_OSX |  | ||||||
| 		    // 针对 2021.3.41 MAC 版本,直接强制走Unity 自带的 JDK 库 |  | ||||||
| 		    if (Directory.Exists(DEFAULT_JDK_PATH_MAC_2021_3_41)) |  | ||||||
| 		    { |  | ||||||
| 			    UnityEditor.Android.AndroidExternalToolsSettings.jdkRootPath = DEFAULT_JDK_PATH_MAC_2021_3_41; |  | ||||||
| 		    } |  | ||||||
| #endif |  | ||||||
| 	    } |  | ||||||
|          |  | ||||||
| 	    /// <summary> |  | ||||||
| 	    /// 设置自定义的 NDK 路径 |  | ||||||
| 	    /// </summary> |  | ||||||
| 	    /// <param name="ndkRoot"></param> |  | ||||||
| 	    private static void SetNDKRoot(string ndkRoot) |  | ||||||
| 	    { |  | ||||||
| 		    if (!string.IsNullOrEmpty(ndkRoot)) |  | ||||||
| 		    { |  | ||||||
| 			    UnityEditor.Android.AndroidExternalToolsSettings.ndkRootPath = ndkRoot; |  | ||||||
| 			    return; |  | ||||||
| 		    } |  | ||||||
| 		     |  | ||||||
| #if UNITY_2021_3_41 && UNITY_EDITOR_OSX |  | ||||||
| 		    // 针对 2021.3.41 MAC 版本,直接强制走Unity 自带的 JDK 库 |  | ||||||
| 		    if (Directory.Exists(DEFAULT_JDK_PATH_MAC_2021_3_41)) |  | ||||||
| 		    { |  | ||||||
| 			    UnityEditor.Android.AndroidExternalToolsSettings.ndkRootPath = DEFAULT_NDK_PATH_MAC_2021_3_41; |  | ||||||
| 		    } |  | ||||||
| #endif |  | ||||||
| 	    } |  | ||||||
| 	     |  | ||||||
| 	     |  | ||||||
| 	    /// <summary> |  | ||||||
| 	    /// 设置自定义的 NDK 路径 |  | ||||||
| 	    /// </summary> |  | ||||||
| 	    /// <param name="sdkRoot"></param> |  | ||||||
| 	    private static void SetAndroidSDKRoot(string sdkRoot) |  | ||||||
| 	    { |  | ||||||
| 		    if (!string.IsNullOrEmpty(sdkRoot)) |  | ||||||
| 		    { |  | ||||||
| 			    UnityEditor.Android.AndroidExternalToolsSettings.sdkRootPath = sdkRoot; |  | ||||||
| 			    return; |  | ||||||
| 		    } |  | ||||||
| 		     |  | ||||||
| #if UNITY_2021_3_41 && UNITY_EDITOR_OSX |  | ||||||
| 		    // 针对 2021.3.41 MAC 版本,直接强制走Unity 自带的 JDK 库 |  | ||||||
| 		    if (Directory.Exists(DEFAULT_JDK_PATH_MAC_2021_3_41)) |  | ||||||
| 		    { |  | ||||||
| 			    UnityEditor.Android.AndroidExternalToolsSettings.sdkRootPath = DEFAULT_ANDROID_SDK_MAC_2021_3_41; |  | ||||||
| 		    } | 		    } | ||||||
| #endif | #endif | ||||||
| 	    } | 	    } | ||||||
|  | @ -332,7 +252,7 @@ namespace Guru.Editor | ||||||
| 	        try | 	        try | ||||||
| 	        { | 	        { | ||||||
| 		        BuildOptions opts = isDebug ? BuildOptions.Development : BuildOptions.None; | 		        BuildOptions opts = isDebug ? BuildOptions.Development : BuildOptions.None; | ||||||
| 		        BuildPipeline.BuildPlayer(GetBuildScenes(), outputDir, BuildTarget.iOS, opts); | 		        BuildPipeline.BuildPlayer(GetBuildScenes(), outputDir, BuildTarget.iOS, BuildOptions.None); | ||||||
| 		        if (buildParam.BuilderType == AppBuilderType.Editor) | 		        if (buildParam.BuilderType == AppBuilderType.Editor) | ||||||
| 		        { | 		        { | ||||||
| 			        Open(outputDir); | 			        Open(outputDir); | ||||||
|  | @ -359,9 +279,10 @@ namespace Guru.Editor | ||||||
| 	        var guids = AssetDatabase.FindAssets($"{nameof(AppBuilder)} t:Script"); | 	        var guids = AssetDatabase.FindAssets($"{nameof(AppBuilder)} t:Script"); | ||||||
| 	        if (guids.Length > 0) | 	        if (guids.Length > 0) | ||||||
| 	        { | 	        { | ||||||
|  | 		        var path = ""; | ||||||
| 		        foreach (var guid in guids) | 		        foreach (var guid in guids) | ||||||
| 		        { | 		        { | ||||||
| 			        var path = AssetDatabase.GUIDToAssetPath(guid); | 			        path = AssetDatabase.GUIDToAssetPath(guids[0]); | ||||||
| 			        if (path.Contains($"Editor/BuildTool/{nameof(AppBuilder)}")) | 			        if (path.Contains($"Editor/BuildTool/{nameof(AppBuilder)}")) | ||||||
| 			        { | 			        { | ||||||
| 				        return Directory.GetParent(path)!.FullName; | 				        return Directory.GetParent(path)!.FullName; | ||||||
|  | @ -437,6 +358,7 @@ namespace Guru.Editor | ||||||
| 	    /// 修改打包版本号 | 	    /// 修改打包版本号 | ||||||
| 	    /// </summary> | 	    /// </summary> | ||||||
| 	    /// <param name="buildTarget"></param> | 	    /// <param name="buildTarget"></param> | ||||||
|  | 	    /// <param name="isRelease"></param> | ||||||
| 	    private static string ChangeBuildNumber(BuildTarget buildTarget) | 	    private static string ChangeBuildNumber(BuildTarget buildTarget) | ||||||
| 	    { | 	    { | ||||||
| 		    var nowDate = DateTime.Now; | 		    var nowDate = DateTime.Now; | ||||||
|  | @ -481,7 +403,7 @@ namespace Guru.Editor | ||||||
| 	    /// 获取打包场景 | 	    /// 获取打包场景 | ||||||
| 	    /// </summary> | 	    /// </summary> | ||||||
| 	    /// <returns></returns> | 	    /// <returns></returns> | ||||||
| 	    private static string[] GetBuildScenes() | 	    public static string[] GetBuildScenes() | ||||||
| 	    { | 	    { | ||||||
| 		    List<string> names = new List<string>(); | 		    List<string> names = new List<string>(); | ||||||
| 		    foreach (var e in EditorBuildSettings.scenes) | 		    foreach (var e in EditorBuildSettings.scenes) | ||||||
|  | @ -498,7 +420,7 @@ namespace Guru.Editor | ||||||
| 		/// 打开路径 | 		/// 打开路径 | ||||||
| 		/// </summary> | 		/// </summary> | ||||||
| 		/// <param name="path"></param> | 		/// <param name="path"></param> | ||||||
| 		private static void Open(string path) | 	    public static void Open(string path) | ||||||
| 	    { | 	    { | ||||||
| #if UNITY_EDITOR_OSX | #if UNITY_EDITOR_OSX | ||||||
| 		    EditorUtility.RevealInFinder(path); | 		    EditorUtility.RevealInFinder(path); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue