/// <summary> /// Builds an Android App Bundle given the specified configuration. /// </summary> public static async Task <AndroidBuildReport> BuildTask(AndroidBuildOptions androidBuildOptions) { var appBundleBuilder = CreateAppBundleBuilder(); if (!appBundleBuilder.Initialize(new BuildToolLogger())) { throw new Exception("Failed to initialize AppBundleBuilder"); } return(await appBundleBuilder.CreateBundleWithTask(androidBuildOptions, IsBatchMode)); }
/// <summary> /// Synchronously builds an Android Player and then produces a final AAB synchronously or asynchronously, /// as specified. /// </summary> /// <param name="androidBuildOptions">Options indicating how to build the AAB, including asset packs.</param> /// <returns>An async task that provides an AndroidBuildReport.</returns> public async Task <AndroidBuildReport> CreateBundleWithTask(AndroidBuildOptions androidBuildOptions) { var taskCompletionSource = new TaskCompletionSource <AndroidBuildReport>(); var androidBuildResult = BuildAndroidPlayer(androidBuildOptions.BuildPlayerOptions); if (androidBuildResult.Cancelled) { taskCompletionSource.SetCanceled(); return(await taskCompletionSource.Task); } var androidBuildReport = new AndroidBuildReport(androidBuildResult.Report); if (androidBuildResult.ErrorMessage != null) { taskCompletionSource.SetException( new AndroidBuildException(androidBuildResult.ErrorMessage, androidBuildReport)); return(await taskCompletionSource.Task); } var createBundleOptions = new CreateBundleOptions { AabFilePath = androidBuildOptions.BuildPlayerOptions.locationPathName, AssetPackConfig = androidBuildOptions.AssetPackConfig ?? new AssetPackConfig(), CompressionOptions = androidBuildOptions.CompressionOptions }; if (androidBuildOptions.ForceSingleThreadedBuild || Application.isBatchMode) { CreateBundleInternal( taskCompletionSource, () => CreateBundle(createBundleOptions), androidBuildReport, androidBuildReport); } else { // Copy the AssetPackConfig while still on the main thread in case the original is modified later. createBundleOptions.AssetPackConfig = SerializationHelper.DeepCopy(createBundleOptions.AssetPackConfig); StartCreateBundleAsync(() => { CreateBundleInternal( taskCompletionSource, () => CreateBundle(createBundleOptions), androidBuildReport, androidBuildReport); }); } return(await taskCompletionSource.Task); }
/// <summary> /// Synchronously builds an Android Player and then produces a final AAB synchronously or asynchronously, /// as specified. /// </summary> /// <param name="androidBuildOptions">Options indicating how to build the AAB, including asset packs.</param> /// <param name="buildSynchronously"> /// Indicates whether to perform the build only on the main thread or to execute some steps asynchronously. /// </param> /// <returns>An async task that provides an AndroidBuildReport.</returns> public async Task <AndroidBuildReport> CreateBundleWithTask( AndroidBuildOptions androidBuildOptions, bool buildSynchronously) { var taskCompletionSource = new TaskCompletionSource <AndroidBuildReport>(); var androidBuildResult = BuildAndroidPlayer(androidBuildOptions.BuildPlayerOptions); if (androidBuildResult.Cancelled) { taskCompletionSource.SetCanceled(); return(await taskCompletionSource.Task); } var androidBuildReport = new AndroidBuildReport(androidBuildResult.Report); if (androidBuildResult.ErrorMessage != null) { taskCompletionSource.SetException( new AndroidBuildException(androidBuildResult.ErrorMessage, androidBuildReport)); return(await taskCompletionSource.Task); } var aabFilePath = androidBuildOptions.BuildPlayerOptions.locationPathName; var assetPackConfig = androidBuildOptions.AssetPackConfig ?? new AssetPackConfig(); if (buildSynchronously) { CreateBundleInternal(taskCompletionSource, aabFilePath, assetPackConfig, androidBuildReport); } else { // Copy the AssetPackConfig while still on the main thread in case the original is modified later. var copiedAssetPackConfig = SerializationHelper.DeepCopy(assetPackConfig); StartCreateBundleAsync(() => { CreateBundleInternal( taskCompletionSource, aabFilePath, copiedAssetPackConfig, androidBuildReport); }); } return(await taskCompletionSource.Task); }