From 6aab001c4983fb267ed0e903a93f4f6c10b5313e Mon Sep 17 00:00:00 2001 From: Google Play Team Date: Mon, 15 Nov 2021 18:56:31 -0800 Subject: [PATCH] Remove "Compression Method" support "Separate base APK Assets" was producing broken app bundles if the Compression Method was not set to "Default". PiperOrigin-RevId: 410134883 --- .../com.google.android.appbundle/CHANGELOG.md | 1 - .../Editor/Scripts/AndroidBuildHelper.cs | 24 +--- .../Internal/UnityBuildSettingsHelper.cs | 122 ------------------ .../Internal/UnityBuildSettingsHelper.cs.meta | 3 - 4 files changed, 3 insertions(+), 147 deletions(-) delete mode 100644 GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/UnityBuildSettingsHelper.cs delete mode 100644 GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/UnityBuildSettingsHelper.cs.meta diff --git a/GooglePlayPlugins/com.google.android.appbundle/CHANGELOG.md b/GooglePlayPlugins/com.google.android.appbundle/CHANGELOG.md index ea5ec1dd..e47bd0a3 100644 --- a/GooglePlayPlugins/com.google.android.appbundle/CHANGELOG.md +++ b/GooglePlayPlugins/com.google.android.appbundle/CHANGELOG.md @@ -7,7 +7,6 @@ - Fixed issue #127: crash with IL2CPP and "Separate base APK asset" enabled - Fixed issue #143: handle AssetBundle files that have file extensions - Fixed issue #145: AAB upload to Play Console fails due to BundleConfig.pb file size - - Fixed issue #154: App Bundle build doesn't compress the app - Fixed issue when installing Android APIs using the plugin ### Other - Update minimum Target SDK version to 30 diff --git a/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/AndroidBuildHelper.cs b/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/AndroidBuildHelper.cs index a151dac6..37dd1ada 100644 --- a/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/AndroidBuildHelper.cs +++ b/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/AndroidBuildHelper.cs @@ -15,10 +15,8 @@ using System; using System.Collections.Generic; using System.Linq; -using Google.Android.AppBundle.Editor.Internal; using Google.Android.AppBundle.Editor.Internal.Config; using UnityEditor; -using UnityEngine; namespace Google.Android.AppBundle.Editor { @@ -28,7 +26,7 @@ namespace Google.Android.AppBundle.Editor public static class AndroidBuildHelper { // Allowed characters for splitting PlayerSettings.GetScriptingDefineSymbolsForGroup(). - private static readonly char[] ScriptingDefineSymbolsSplitChars = { ';', ',', ' ' }; + private static readonly char[] ScriptingDefineSymbolsSplitChars = {';', ',', ' '}; /// /// Returns an array of enabled scenes from the "Scenes In Build" section of Unity's Build Settings window. @@ -51,27 +49,11 @@ public static string[] GetEditorBuildEnabledScenes() /// A new object. public static BuildPlayerOptions CreateBuildPlayerOptions(string locationPathName) { - var buildOptions = EditorUserBuildSettings.development ? BuildOptions.Development : BuildOptions.None; - - try - { - var compressionBuildOption = UnityBuildSettingsHelper.GetCompressionBuildOption(); - if (compressionBuildOption.HasValue) - { - buildOptions |= compressionBuildOption.Value; - } - } - catch (UnityBuildSettingsHelper.ReflectionException) - { - Debug.LogWarning( - "Failed to detect the compression method specified in the editor Build Settings window. Using Default."); - } - return new BuildPlayerOptions { assetBundleManifestPath = AndroidBuildConfiguration.AssetBundleManifestPath, locationPathName = locationPathName, - options = buildOptions, + options = EditorUserBuildSettings.development ? BuildOptions.Development : BuildOptions.None, scenes = GetEditorBuildEnabledScenes(), target = BuildTarget.Android, targetGroup = BuildTargetGroup.Android @@ -86,7 +68,7 @@ public static void AddScriptingDefineSymbol(string symbol) var scriptingDefineSymbols = GetScriptingDefineSymbols(); if (!IsScriptingSymbolDefined(scriptingDefineSymbols, symbol)) { - SetScriptingDefineSymbols(scriptingDefineSymbols.Concat(new[] { symbol })); + SetScriptingDefineSymbols(scriptingDefineSymbols.Concat(new[] {symbol})); } } diff --git a/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/UnityBuildSettingsHelper.cs b/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/UnityBuildSettingsHelper.cs deleted file mode 100644 index 598979c0..00000000 --- a/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/UnityBuildSettingsHelper.cs +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System; -using System.Collections.Generic; -using System.Reflection; -using UnityEditor; - -namespace Google.Android.AppBundle.Editor.Internal -{ - /// - /// Helper class for retrieving values set in Unity's build settings window. - /// - public static class UnityBuildSettingsHelper - { - /// - /// An exception indicating that something went wrong while calling methods via reflection. - /// - public class ReflectionException : Exception - { - public ReflectionException(string message) : base(message) - { - } - - public ReflectionException(string message, Exception innerException) : base(message, innerException) - { - } - } - - /// - /// The options specified in Unity's build settings window under "Compression Method". - /// The values match the values returned by EditorUserBuildSettings.GetCompressionType(). - /// - private enum UnityCompressionType - { - Default = 0, - Lz4 = 2, - Lz4Hc = 3 - } - - /// - /// A list of expected Exceptions that may occur while using Type.GetMethod and MethodInfo.Invoke to call - /// methods via reflection. - /// - private static readonly HashSet ExpectedReflectionExceptions = new HashSet - { - typeof(ArgumentException), - typeof(AmbiguousMatchException), - typeof(TargetInvocationException), - typeof(TargetParameterCountException), - typeof(MethodAccessException), - typeof(InvalidOperationException), - typeof(NotSupportedException) - }; - - /// - /// Gets the BuildOptions value corresponding to the compression specified in build settings, - /// or null if "Default" is selected. - /// - public static BuildOptions? GetCompressionBuildOption() - { - switch (GetCompressionType()) - { - case UnityCompressionType.Default: - return null; - case UnityCompressionType.Lz4: - return BuildOptions.CompressWithLz4; - case UnityCompressionType.Lz4Hc: - return BuildOptions.CompressWithLz4HC; - default: - return null; - } - } - - /// - /// Returns the current compression specified in Unity's build settings window. - /// - /// - /// Thrown if any of the ExpectedReflectionExceptions are encountered while getting the compression type. - /// - private static UnityCompressionType GetCompressionType() - { - try - { - var getCompressionMethod = typeof(EditorUserBuildSettings).GetMethod("GetCompressionType", - BindingFlags.NonPublic | BindingFlags.Static); - - if (getCompressionMethod == null) - { - throw new ReflectionException("GetCompressionType method could not be found."); - } - - object result = getCompressionMethod.Invoke(null, new object[] - { - BuildTargetGroup.Android, - }); - - return (UnityCompressionType)result; - } - catch (Exception e) - { - if (ExpectedReflectionExceptions.Contains(e.GetType())) - { - throw new ReflectionException("Failed to call GetCompressionType.", e); - } - - throw; - } - } - } -} \ No newline at end of file diff --git a/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/UnityBuildSettingsHelper.cs.meta b/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/UnityBuildSettingsHelper.cs.meta deleted file mode 100644 index 31c29795..00000000 --- a/GooglePlayPlugins/com.google.android.appbundle/Editor/Scripts/Internal/UnityBuildSettingsHelper.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 1c0b514a63e34695a9ab71f276e5baa9 -timeCreated: 1636499374 \ No newline at end of file