/// <summary>
        /// Builds an Android App Bundle at the specified location. Assumes that all dependencies are already in-place,
        /// e.g. aapt2 and bundletool.
        /// </summary>
        /// <returns>True if the build succeeded, false if it failed or was cancelled.</returns>
        public static bool Build(string aabFilePath)
        {
            bool buildResult;

            Debug.LogFormat("Building app bundle: {0}", aabFilePath);
            // As of February 2019, every released version of Unity natively supporting AAB has used Android Gradle
            // Plugin 3.2.0 which includes bundletool 0.5.0. Bundletool 0.6.0+ is needed for uncompressNativeLibraries
            // and version 0.6.1+ is needed for uncompressNativeLibraries with instant apps.
            // One can #define PLAY_INSTANT_ENABLE_NATIVE_ANDROID_APP_BUNDLE to build using the native AAB builder.
#if PLAY_INSTANT_ENABLE_NATIVE_ANDROID_APP_BUNDLE
    #if PLAY_INSTANT_HAS_NATIVE_ANDROID_APP_BUNDLE
            EditorUserBuildSettings.buildAppBundle = true;
            var buildPlayerOptions = PlayInstantBuilder.CreateBuildPlayerOptions(aabFilePath, BuildOptions.None);
            buildResult = PlayInstantBuilder.Build(buildPlayerOptions);
    #else
            throw new System.Exception("Cannot enable native app bundle build on an unsupported Unity version.");
    #endif
#else
    #if PLAY_INSTANT_HAS_NATIVE_ANDROID_APP_BUNDLE
            // Disable Unity's built-in AAB build on newer Unity versions before performing the custom AAB build.
            EditorUserBuildSettings.buildAppBundle = false;
            // Note: fall through here to the actual build.
    #endif
            buildResult = AppBundleBuilder.Build(aabFilePath);
#endif
            if (buildResult)
            {
                // Do not log in case of failure. The method we called was responsible for logging.
                Debug.LogFormat("Finished building app bundle: {0}", aabFilePath);
            }

            return(buildResult);
        }
Пример #2
0
        /// <summary>
        /// Builds an Android App Bundle at the specified location. Assumes that all dependencies are already in-place,
        /// e.g. aapt2 and bundletool.
        /// </summary>
        /// <returns>True if the build succeeded, false if it failed or was cancelled.</returns>
        public static bool Build(string aabFilePath)
        {
            bool buildResult;

            Debug.LogFormat("Building app bundle: {0}", aabFilePath);
#if UNITY_2018_4_OR_NEWER
            EditorUserBuildSettings.buildAppBundle = true;
            var buildPlayerOptions = PlayInstantBuilder.CreateBuildPlayerOptions(aabFilePath, BuildOptions.None);
            buildResult = PlayInstantBuilder.Build(buildPlayerOptions);
#elif UNITY_2018_3_OR_NEWER
            EditorUserBuildSettings.buildAppBundle = false;
            buildResult = AppBundleBuilder.Build(aabFilePath);
#else
            buildResult = AppBundleBuilder.Build(aabFilePath);
#endif
            if (!buildResult)
            {
                // Do not log in case of failure. The method we called was responsible for logging.
                Debug.LogFormat("Finished building app bundle: {0}", aabFilePath);
            }

            return(buildResult);
        }