//Backup Player Settings of original project and change the to loader APK settings before building loader APK private static void BackupAndChangePlayerSettings() { originalCompanyName = PlayerSettings.companyName; originalProductName = PlayerSettings.productName; originalPackageName = PlayerSettings.applicationIdentifier; originalVersion = PlayerSettings.bundleVersion; originalBundleVersionCode = PlayerSettings.Android.bundleVersionCode; originalScriptingBackEnd = PlayerSettings.GetScriptingBackend(BuildTargetGroup.Android); PlayerSettings.companyName = loaderCompanyName; PlayerSettings.productName = loaderProductName; PlayerSettings.applicationIdentifier = loaderPackageName; PlayerSettings.bundleVersion = loaderVersion; PlayerSettings.Android.bundleVersionCode = loaderBundleVersionCode; PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, loaderScriptingBackEnd); #if UNITY_2018_3_OR_NEWER originalManagedStrippingLevel = PlayerSettings.GetManagedStrippingLevel(BuildTargetGroup.Android); PlayerSettings.SetManagedStrippingLevel(BuildTargetGroup.Android, loaderManagedStrippingLevel); #else originalStrippingLevel = PlayerSettings.strippingLevel; PlayerSettings.strippingLevel = loaderStrippingLevel; #endif originalStripEngineCode = PlayerSettings.stripEngineCode; PlayerSettings.stripEngineCode = loaderStripEngineCode; }
static SetAndroid() { if (!PlayerSettings.Android.forceInternetPermission) { PlayerSettings.Android.forceInternetPermission = true; Debug.Log("Android: 'forceInternetPermission' set to true"); } BuildTarget target = EditorUserBuildSettings.activeBuildTarget; BuildTargetGroup group = BuildPipeline.GetBuildTargetGroup(target); #if UNITY_2018_3_OR_NEWER ManagedStrippingLevel level = ManagedStrippingLevel.Disabled; if (PlayerSettings.GetScriptingBackend(group) == ScriptingImplementation.Mono2x && PlayerSettings.GetManagedStrippingLevel(group) != level) { PlayerSettings.SetManagedStrippingLevel(group, level); Debug.Log("Android: stripping level changed to '" + level + "'"); } #else StrippingLevel level = StrippingLevel.Disabled; if (PlayerSettings.GetScriptingBackend(group) == ScriptingImplementation.Mono2x && PlayerSettings.strippingLevel != level) { PlayerSettings.strippingLevel = level; Debug.Log("Android: stripping level changed to '" + level + "'"); } #endif }
private void Init(Params buildParams) { InitBuildParams(buildParams); PlayerPrefs.SetInt("IgnoreExecuteInEditMode", 1); if (!Directory.Exists(TempAssetsPath)) { AssetDatabase.CreateFolder(Path.GetDirectoryName(TempAssetsPath), Path.GetFileName(TempAssetsPath)); } AssetDatabase.SaveAssets(); // To save the build state to disk, since entering playmode will destroy this class AssetDatabase.CreateAsset(this, BuilderTempPath); _scenes = BuildUtils.CollectBuildScenes(); _buildAssets = BuildUtils.CollectBuildAssets(); _lateProcessor = new LateReferenceProcessor(_buildAssets); _oldStrippingLevel = PlayerSettings.strippingLevel; _oldScene = EditorApplication.currentScene; _oldRunInBackground = Application.runInBackground; _oldRunInBackgroundSettings = PlayerSettings.runInBackground; _oldAndroidBuildSubtarget = EditorUserBuildSettings.androidBuildSubtarget; }
private static void PrebuildProjectSettingUpdate() { // Modify application identifier for transition APK projectDefaultAppIdentifier = PlayerSettings.applicationIdentifier; PlayerSettings.applicationIdentifier = projectDefaultAppIdentifier + transitionApkOptionalIdentifier; // Set VersionCode as a unique identifier for transition APK projectDefaultVersion = PlayerSettings.bundleVersion; PlayerSettings.bundleVersion = TRANSITION_APK_VERSION_NAME; // Modify IL2CPP option as it strips script symbols that are necessary for the scenes at runtime projectScriptImplementation = PlayerSettings.GetScriptingBackend(EditorUserBuildSettings.selectedBuildTargetGroup); if (projectScriptImplementation != ScriptingImplementation.Mono2x) { // Show message in console to make it more clear to developers OVRBundleTool.PrintLog("Build will use Mono as scripting backend."); PlayerSettings.SetScriptingBackend(EditorUserBuildSettings.selectedBuildTargetGroup, ScriptingImplementation.Mono2x); } // Avoid stripping managed code that are necessary for the scenes at runtime #if UNITY_2018_3_OR_NEWER projectManagedStrippingLevel = PlayerSettings.GetManagedStrippingLevel(BuildTargetGroup.Android); if (projectManagedStrippingLevel != ManagedStrippingLevel.Disabled) { OVRBundleTool.PrintLog("Build will set Managed Stripping Level to Disabled."); PlayerSettings.SetManagedStrippingLevel(BuildTargetGroup.Android, ManagedStrippingLevel.Disabled); } #else projectStrippingLevel = PlayerSettings.strippingLevel; if (projectStrippingLevel != StrippingLevel.Disabled) { OVRBundleTool.PrintLog("Build will set Stripping Level to Disabled."); PlayerSettings.strippingLevel = StrippingLevel.Disabled; } #endif projectStripEngineCode = PlayerSettings.stripEngineCode; if (projectStripEngineCode) { PlayerSettings.stripEngineCode = false; } }
static SetAndroid() { if (!PlayerSettings.Android.forceInternetPermission) { PlayerSettings.Android.forceInternetPermission = true; Debug.Log("Android: 'forceInternetPermission' set to true"); } StrippingLevel level = StrippingLevel.Disabled; BuildTarget target = EditorUserBuildSettings.activeBuildTarget; BuildTargetGroup group = BuildPipeline.GetBuildTargetGroup(target); //Debug.Log("Stripping level: " + PlayerSettings.strippingLevel + " (" + PlayerSettings.GetScriptingBackend(group) + ")"); if (PlayerSettings.GetScriptingBackend(group).ToString().CTEquals("Mono2x") && PlayerSettings.strippingLevel != level) { PlayerSettings.strippingLevel = level; Debug.Log("Android: stripping level changed to '" + level + "'"); } }
void DrawMapInfo(){ GUILayout.Label(TidyMessages.MAP_CREATOR_CURRENT_MAP_CATEGORY,EditorStyles.boldLabel); GUILayout.Space(10.0f); if(currentBehaviour != MapPaintBehaviour.Disabled){ GUI.enabled = false; } string mapName = TidyMessages.MAP_CREATOR_NO_MAP_SELECTED; int width = 0, height = 0; if(focusMap != null){ mapName = focusMap.name; width = focusMap.currentWidth; height = focusMap.currentHeight; } GUILayout.Label(TidyMessages.MAP_CREATOR_SELECTED_MAP_LABEL + mapName); GUILayout.Label(TidyMessages.MAP_CREATOR_CHUNK_WIDTH + width + TidyMessages.MAP_CREATOR_CHUNK_WIDTH_SUFFIX); GUILayout.Label(TidyMessages.MAP_CREATOR_CHUNK_HEIGHT + height + TidyMessages.MAP_CREATOR_CHUNK_HEIGHT_SUFFIX); if(focusMap == null){ GUI.enabled = false; } selectedStrippingLevel = (StrippingLevel)EditorGUILayout.EnumPopup(TidyMessages.MAP_CREATOR_STRIPPING_LEVEL,selectedStrippingLevel); EditorGUILayout.BeginHorizontal(); if(GUILayout.Button("Refresh")){ RefreshAllMaps(); SetEntireMapDirty(focusMap); } GUILayout.FlexibleSpace(); if(GUILayout.Button(new GUIContent(TidyMessages.MAP_CREATOR_PUBLISH_MAP,TidyTooltips.MAP_CREATOR_PUBLISH_MAP))){ PrePublishMap(focusMap); } GUILayout.Space(20.0f); EditorGUILayout.EndHorizontal(); if(focusMap == null){ GUI.enabled = true; } GUILayout.Label(mapPublishStatus,italicStyle); if(currentBehaviour != MapPaintBehaviour.Disabled){ GUI.enabled = true; } }
public static bool AttemptGetUnityFolderMonoDLLs(bool wasWebBuild, bool wasAndroidApkBuild, string editorAppContentsPath, ApiCompatibilityLevel monoLevel, StrippingLevel codeStrippingLevel, out string path, out string higherPriorityPath) { bool success = false; // more hackery // attempt to get DLL size info // from Unity install folder // // this only happens in: // 1. Web build // 2. Android build // 3. Custom builders // string[] pathTries = new string[] { editorAppContentsPath + "/Frameworks/Mono/lib/mono", editorAppContentsPath + "/Mono/lib/mono", "/Applications/Unity/Unity.app/Contents/Frameworks/Mono/lib/mono", "C:/Program Files (x86)/Unity/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity/Editor/Data/Mono/lib/mono", #if UNITY_3_5 "/Applications/Unity3/Unity.app/Contents/Frameworks/Mono/lib/mono", "/Applications/Unity 3/Unity.app/Contents/Frameworks/Mono/lib/mono", "/Applications/Unity3.5/Unity.app/Contents/Frameworks/Mono/lib/mono", "/Applications/Unity 3.5/Unity.app/Contents/Frameworks/Mono/lib/mono", "C:/Program Files (x86)/Unity3/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity 3/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity3.5/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity 3.5/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity3/Editor/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity 3/Editor/Data/Mono/lib/mono", #endif #if UNITY_4_AND_GREATER "/Applications/Unity4/Unity.app/Contents/Frameworks/Mono/lib/mono", "/Applications/Unity 4/Unity.app/Contents/Frameworks/Mono/lib/mono", "C:/Program Files (x86)/Unity4/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity 4/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity4/Editor/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity 4/Editor/Data/Mono/lib/mono", #endif }; string tryPath = ""; for (int n = 0, len = pathTries.Length; n < len; ++n) { tryPath = pathTries[n]; if (Directory.Exists(tryPath)) { break; } tryPath = ""; } if (!string.IsNullOrEmpty(tryPath)) { success = true; // "unity_web" is obviously for the web build. Presumably, this one has DLLs removed that can compromise web security. // "2.0" is likely the full featured Mono libraries // "unity" is most likely the one used when selecting 2.0 subset in the player settings. this is the setting by default. // "micro" is probably the one used in StrippingLevel.UseMicroMSCorlib. only makes sense to be here when building on Android. // since in iOS, we already have the DLL files. No need for this hackery in iOS. But since in Android we do not have a project folder, // we resort to this. if (wasWebBuild) { path = tryPath + "/unity_web/"; } else if (monoLevel == ApiCompatibilityLevel.NET_2_0_Subset) { path = tryPath + "/unity/"; } else { path = tryPath + "/2.0/"; } if (wasAndroidApkBuild && codeStrippingLevel == StrippingLevel.UseMicroMSCorlib) { higherPriorityPath = tryPath + "/micro/"; } else { higherPriorityPath = ""; } } else { path = ""; higherPriorityPath = ""; } return(success); }
public static bool AttemptGetUnityFolderMonoDLLs(bool wasWebBuild, bool wasAndroidApkBuild, string editorAppContentsPath, ApiCompatibilityLevel monoLevel, StrippingLevel codeStrippingLevel, out string path, out string higherPriorityPath) { bool success = false; // more hackery // attempt to get DLL size info // from Unity install folder // // this only happens in: // 1. Web build // 2. Android build // 3. Custom builders // string[] pathTries = new string[] { editorAppContentsPath + "/Frameworks/Mono/lib/mono", editorAppContentsPath + "/Mono/lib/mono", "/Applications/Unity/Unity.app/Contents/Frameworks/Mono/lib/mono", "C:/Program Files (x86)/Unity/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity/Editor/Data/Mono/lib/mono", #if UNITY_3_5 "/Applications/Unity3/Unity.app/Contents/Frameworks/Mono/lib/mono", "/Applications/Unity 3/Unity.app/Contents/Frameworks/Mono/lib/mono", "/Applications/Unity3.5/Unity.app/Contents/Frameworks/Mono/lib/mono", "/Applications/Unity 3.5/Unity.app/Contents/Frameworks/Mono/lib/mono", "C:/Program Files (x86)/Unity3/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity 3/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity3.5/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity 3.5/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity3/Editor/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity 3/Editor/Data/Mono/lib/mono", #endif #if UNITY_4_AND_GREATER "/Applications/Unity4/Unity.app/Contents/Frameworks/Mono/lib/mono", "/Applications/Unity 4/Unity.app/Contents/Frameworks/Mono/lib/mono", "C:/Program Files (x86)/Unity4/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity 4/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity4/Editor/Data/Mono/lib/mono", "C:/Program Files (x86)/Unity 4/Editor/Data/Mono/lib/mono", #endif }; string tryPath = ""; for (int n = 0, len = pathTries.Length; n < len; ++n) { tryPath = pathTries[n]; if (Directory.Exists(tryPath)) { break; } tryPath = ""; } if (!string.IsNullOrEmpty(tryPath)) { success = true; // "unity_web" is obviously for the web build. Presumably, this one has DLLs removed that can compromise web security. // "2.0" is likely the full featured Mono libraries // "unity" is most likely the one used when selecting 2.0 subset in the player settings. this is the setting by default. // "micro" is probably the one used in StrippingLevel.UseMicroMSCorlib. only makes sense to be here when building on Android. // since in iOS, we already have the DLL files. No need for this hackery in iOS. But since in Android we do not have a project folder, // we resort to this. if (wasWebBuild) { path = tryPath + "/unity_web/"; } else if (monoLevel == ApiCompatibilityLevel.NET_2_0_Subset) { path = tryPath + "/unity/"; } else { path = tryPath + "/2.0/"; } if (wasAndroidApkBuild && codeStrippingLevel == StrippingLevel.UseMicroMSCorlib) { higherPriorityPath = tryPath + "/micro/"; } else { higherPriorityPath = ""; } } else { path = ""; higherPriorityPath = ""; } return success; }
static void ParseDLLs(string editorLogPath, bool wasWebBuild, string buildFilePath, string projectAssetsPath, string editorAppContentsPath, ApiCompatibilityLevel monoLevel, StrippingLevel codeStrippingLevel, out BuildReportTool.SizePart[] includedDLLs, out BuildReportTool.SizePart[] scriptDLLs) { List<BuildReportTool.SizePart> includedDLLsList = new List<BuildReportTool.SizePart>(); List<BuildReportTool.SizePart> scriptDLLsList = new List<BuildReportTool.SizePart>(); string buildManagedDLLsFolder = BuildReportTool.Util.GetBuildManagedFolder(buildFilePath); string buildScriptDLLsFolder = buildManagedDLLsFolder; string buildManagedDLLsFolderHigherPriority = ""; bool wasAndroidApkBuild = buildFilePath.EndsWith(".apk"); if (wasWebBuild) { string tryPath; bool success = BuildReportTool.Util.AttemptGetWebTempStagingArea(projectAssetsPath, out tryPath); if (success) { buildManagedDLLsFolder = tryPath; buildScriptDLLsFolder = tryPath; } } else if (wasAndroidApkBuild) { string tryPath; bool success = BuildReportTool.Util.AttemptGetAndroidTempStagingArea(projectAssetsPath, out tryPath); if (success) { buildManagedDLLsFolder = tryPath; buildScriptDLLsFolder = tryPath; } } string unityFolderManagedDLLs; bool unityfoldersSuccess = BuildReportTool.Util.AttemptGetUnityFolderMonoDLLs(wasWebBuild, wasAndroidApkBuild, editorAppContentsPath, monoLevel, codeStrippingLevel, out unityFolderManagedDLLs, out buildManagedDLLsFolderHigherPriority); //Debug.Log("buildManagedDLLsFolder: " + buildManagedDLLsFolder); //Debug.Log("Application.dataPath: " + Application.dataPath); if (unityfoldersSuccess && (string.IsNullOrEmpty(buildManagedDLLsFolder) || !Directory.Exists(buildManagedDLLsFolder))) { #if BRT_SHOW_MINOR_WARNINGS Debug.LogWarning("Could not find build folder. Using Unity install folder instead for getting mono DLL file sizes."); #endif buildManagedDLLsFolder = unityFolderManagedDLLs; } #if BRT_SHOW_MINOR_WARNINGS if (!Directory.Exists(buildManagedDLLsFolder)) { Debug.LogWarning("Could not find folder for getting DLL file sizes. Got: \"" + buildManagedDLLsFolder + "\""); } #endif const string PREFIX_REMOVE = "Dependency assembly - "; BuildReportTool.SizePart inPart; const string MONO_DLL_KEY = "Mono dependencies included in the build"; foreach (string line in DldUtil.BigFileReader.ReadFile(editorLogPath, MONO_DLL_KEY)) { // blank line signifies end of dll list if (string.IsNullOrEmpty(line) || line == "\n" || line == "\r\n") { break; } if (line.IndexOf(MONO_DLL_KEY) != -1) { continue; } string filename = line; filename = BuildReportTool.Util.RemovePrefix(PREFIX_REMOVE, filename); string filepath; if (BuildReportTool.Util.IsAScriptDLL(filename)) { filepath = buildScriptDLLsFolder + filename; //Debug.LogWarning("Script \"" + filepath + "\"."); } else { filepath = buildManagedDLLsFolder + filename; if (!File.Exists(filepath) && unityfoldersSuccess && (buildManagedDLLsFolder != unityFolderManagedDLLs)) { #if BRT_SHOW_MINOR_WARNINGS Debug.LogWarning("Failed to find file \"" + filepath + "\". Attempting to get from Unity folders."); #endif filepath = unityFolderManagedDLLs + filename; if (!string.IsNullOrEmpty(buildManagedDLLsFolderHigherPriority) && File.Exists(buildManagedDLLsFolderHigherPriority + filename)) { filepath = buildManagedDLLsFolderHigherPriority + filename; } } } if ((buildManagedDLLsFolder == unityFolderManagedDLLs) && !string.IsNullOrEmpty(buildManagedDLLsFolderHigherPriority) && File.Exists(buildManagedDLLsFolderHigherPriority + filename)) { filepath = buildManagedDLLsFolderHigherPriority + filename; } //Debug.Log(filename + " " + filepath); inPart = BuildReportTool.Util.CreateSizePartFromFile(filename, filepath); //gotTotalSizeBytes += inPart.SizeBytes; bool shouldGoInScriptDLLList = BuildReportTool.Util.IsAScriptDLL(filename); if (!File.Exists(unityFolderManagedDLLs + filename)) { shouldGoInScriptDLLList = true; } if (shouldGoInScriptDLLList) { //gotScriptTotalSizeBytes += inPart.SizeBytes; scriptDLLsList.Add(inPart); } else { includedDLLsList.Add(inPart); } } // somehow, the editor logfile // doesn't include UnityEngine.dll // even though it gets included in the final build (for desktop builds) // // for web builds though, it makes sense not to put UnityEngine.dll in the build. and it isn't. // Instead, it's likely residing in the browser plugin to save bandwidth. // // begs the question though, why not have the whole Mono Web Subset DLLs be // installed alongside the Unity web browser plugin? // no need to bundle Mono DLLs in the web build itself. // would have shaved 1 whole MB when a game uses System.Xml.dll for example // //if (!wasWebBuild) { string filename = "UnityEngine.dll"; string filepath = buildManagedDLLsFolder + filename; if (File.Exists(filepath)) { inPart = BuildReportTool.Util.CreateSizePartFromFile(filename, filepath); //gotTotalSizeBytes += inPart.SizeBytes; includedDLLsList.Add(inPart); } } //Debug.Log("total size: " + EditorUtility.FormatBytes(gotTotalSizeBytes) + " (" + gotTotalSizeBytes + " bytes)"); //Debug.Log("total assembly size: " + EditorUtility.FormatBytes(gotScriptTotalSizeBytes) + " (" + gotScriptTotalSizeBytes + " bytes)"); //Debug.Log("total size without assembly: " + EditorUtility.FormatBytes(gotTotalSizeBytes - gotScriptTotalSizeBytes) + " (" + (gotTotalSizeBytes-gotScriptTotalSizeBytes) + " bytes)"); includedDLLs = includedDLLsList.ToArray(); scriptDLLs = scriptDLLsList.ToArray(); }