update: 添加 Settings 文件构建管线修复器
Signed-off-by: huyufei <yufei.hu@castbox.fm>
							parent
							
								
									117703bf8a
								
							
						
					
					
						commit
						33da3f86a6
					
				|  | @ -0,0 +1,8 @@ | ||||||
|  | fileFormatVersion: 2 | ||||||
|  | guid: f0cef2fc19b2407381c7163d3a87ddec | ||||||
|  | folderAsset: yes | ||||||
|  | DefaultImporter: | ||||||
|  |   externalObjects: {} | ||||||
|  |   userData:  | ||||||
|  |   assetBundleName:  | ||||||
|  |   assetBundleVariant:  | ||||||
|  | @ -0,0 +1,56 @@ | ||||||
|  | #if UNITY_ANDROID | ||||||
|  | 
 | ||||||
|  | namespace Guru.BuildTool | ||||||
|  | { | ||||||
|  |     using System.IO; | ||||||
|  |     using UnityEditor.Android; | ||||||
|  |     using UnityEngine; | ||||||
|  |      | ||||||
|  |     public class AndroidSettingsGradleFixer: IPostGenerateGradleAndroidProject | ||||||
|  |     { | ||||||
|  |         private const string SettingsGradleName= "settings.gradle"; | ||||||
|  |         private const string K_LINE_UNITYPROJECT = "def unityProjectPath";  | ||||||
|  |          | ||||||
|  |         public int callbackOrder => 1; | ||||||
|  | 
 | ||||||
|  |         public void OnPostGenerateGradleAndroidProject(string buildPath) | ||||||
|  |         { | ||||||
|  |             FixSettingsInAndroidProject(buildPath); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         /// <summary> | ||||||
|  |         /// 设置项目中的 Settings 文件 | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="buildPath"></param> | ||||||
|  |         private void FixSettingsInAndroidProject(string buildPath) | ||||||
|  |         { | ||||||
|  |             var settingsPath = Path.GetFullPath($"{buildPath}/../{SettingsGradleName}"); | ||||||
|  | 
 | ||||||
|  |             if (File.Exists(settingsPath)) | ||||||
|  |             { | ||||||
|  |                 bool isDirty = false; | ||||||
|  |                 var lines = File.ReadAllLines(settingsPath); | ||||||
|  |                 string projectPath = Path.GetFullPath($"{Application.dataPath}/../").Replace("\\", "/"); // Unity project path | ||||||
|  |                 for (int i = 0; i < lines.Length; i++) | ||||||
|  |                 { | ||||||
|  |                     if (lines[i].Contains(K_LINE_UNITYPROJECT)) | ||||||
|  |                     { | ||||||
|  |                         lines[i] = $"        def unityProjectPath = $/file:////{projectPath}/$.replace(\"\\\\\", \"/\")"; | ||||||
|  |                         isDirty = true; | ||||||
|  |                         break; | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 if (isDirty) | ||||||
|  |                 { | ||||||
|  |                     File.WriteAllLines(settingsPath, lines); | ||||||
|  |                     Debug.Log($"[SDK] --- Fix Unity Project Path at:{settingsPath}"); | ||||||
|  |                 } | ||||||
|  |                  | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #endif | ||||||
|  | @ -0,0 +1,3 @@ | ||||||
|  | fileFormatVersion: 2 | ||||||
|  | guid: 125df18a1af243018be105c54ab9bb5b | ||||||
|  | timeCreated: 1722257677 | ||||||
		Loading…
	
		Reference in New Issue