// Copyright 2019 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.Text.RegularExpressions; using Google.Android.AppBundle.Editor.Internal.Utils; using UnityEditor; namespace Google.Android.AppBundle.Editor { /// /// Provides utilities related to /// Android App Bundle. /// public static class AndroidAppBundle { /// /// Reserved name for the base module that contains the Unity game engine. /// public const string BaseModuleName = "base"; /// /// Reserved name for the module that separates the base module's assets into an install-time asset pack. /// public const string BaseAssetsModuleName = "base_assets"; /// /// Regex used to determine whether a module name is valid. /// See https://github.com/google/bundletool/blob/master/src/main/java/com/android/tools/build/bundletool/model/BundleModuleName.java#L38 /// private static readonly Regex NameRegex = RegexHelper.CreateCompiled(@"^[a-zA-Z][a-zA-Z0-9_]*$"); /// /// Returns true if the specified name is a valid Android App Bundle module name, false otherwise. /// Certain names like "base" are reserved, so also return false in those cases. /// public static bool IsValidModuleName(string name) { // TODO(b/131241163): enforce a name length limit if we make it much smaller than 65535. return name != null && NameRegex.IsMatch(name) && CheckReservedName(name, BaseModuleName) && CheckReservedName(name, BaseAssetsModuleName); } /// /// Always returns true. Previously indicated if this version of the Unity Editor has native support for /// building an Android App Bundle. /// // TODO(b/189958664): Needed for 1.x API compatibility. Should be removed with 2.x. [Obsolete("This is always true")] public static bool HasNativeBuildSupport() { return true; } /// /// Returns EditorUserBuildSettings.buildAppBundle if it is defined and false otherwise. /// // TODO(b/189958664): Needed for 1.x API compatibility. Should be removed with 2.x. [Obsolete("Use EditorUserBuildSettings.buildAppBundle directly instead")] public static bool IsNativeBuildEnabled() { return EditorUserBuildSettings.buildAppBundle; } /// /// Enable the EditorUserBuildSettings.buildAppBundle field if it is defined. /// // TODO(b/189958664): Needed for 1.x API compatibility. Should be removed with 2.x. [Obsolete("Use EditorUserBuildSettings.buildAppBundle directly instead")] public static void EnableNativeBuild() { EditorUserBuildSettings.buildAppBundle = true; } /// /// Disable the EditorUserBuildSettings.buildAppBundle field if it is defined. /// // TODO(b/189958664): Needed for 1.x API compatibility. Should be removed with 2.x. [Obsolete("Use EditorUserBuildSettings.buildAppBundle directly instead")] public static void DisableNativeBuild() { EditorUserBuildSettings.buildAppBundle = false; } private static bool CheckReservedName(string name, string reserved) { return !name.Equals(reserved, StringComparison.OrdinalIgnoreCase); } } }