コード例 #1
0
        /// <summary>
        /// Converts the specified app bundle into an apk set file,
        /// installs the proper apks,
        /// then runs the app on device.
        /// Note: This is designed to run in the main thread.
        /// TODO: Explore running this in a background thread.
        /// </summary>
        public void RunBundle(string aabFilePath, BundletoolBuildMode buildMode)
        {
            string apkSetFilePath;
            var    errorMessage = ConvertAabToApkSet(aabFilePath, buildMode, out apkSetFilePath);

            if (errorMessage != null)
            {
                DisplayRunError("Creating apk set", errorMessage);
                return;
            }

            errorMessage = _bundletool.InstallApkSet(apkSetFilePath, _adb.GetAdbPath());
            if (errorMessage != null)
            {
                DisplayRunError("Installing app bundle", errorMessage);
                return;
            }

            Debug.Log("Installing app bundle");

            // TODO: Check the number of devices before launching to display a nicer error message.
            errorMessage = _adb.LaunchApp(_packageName);
            if (errorMessage != null)
            {
                DisplayRunError("Launching app bundle", errorMessage);
            }

            Debug.Log("Launching app bundle");
        }
コード例 #2
0
        /// <summary>
        /// Returns the specified <see cref="BundletoolBuildMode"/> as an acceptable value for the "--mode" flag
        /// of "bundletool build-apks".
        /// </summary>
        public static string GetModeFlag(this BundletoolBuildMode buildMode)
        {
            if (buildMode == BundletoolBuildMode.SystemCompressed)
            {
                return("system_compressed");
            }

            return(buildMode.ToString().ToLower());
        }
コード例 #3
0
 /// <summary>
 /// Builds an APK Set file from the specified Android App Bundle file.
 /// </summary>
 /// <param name="bundleFile">The output file from <see cref="BuildBundle"/>.</param>
 /// <param name="apkSetFile">A ZIP file containing APKs.</param>
 /// <param name="buildMode">The type of APKs to produce, such as "persistent" or "instant".</param>
 /// <param name="enableLocalTesting">
 /// Whether or not the --local-testing flag is enabled. This will change the behaviour of Play Asset Delivery so
 /// that fast-follow and on-demand packs are fetched from storage rather than downloaded.
 /// </param>
 /// <returns>An error message if there was a problem running bundletool, or null if successful.</returns>
 public virtual string BuildApkSet(
     string bundleFile, string apkSetFile, BundletoolBuildMode buildMode, bool enableLocalTesting)
 {
     return(Run(
                "build-apks --bundle={0} --output={1} --mode={2}{3}",
                CommandLine.QuotePath(bundleFile),
                CommandLine.QuotePath(apkSetFile),
                buildMode.GetModeFlag(),
                enableLocalTesting ? " --local-testing" : ""));
 }
コード例 #4
0
ファイル: Bundletool.cs プロジェクト: tionyufa/Running
        /// <summary>
        /// Builds an APK Set (.apks) file from the specified Android App Bundle file (.aab).
        /// </summary>
        /// <param name="aabFilePath">An .aab file that was created by calling <see cref="BuildBundle"/>.</param>
        /// <param name="apksFilePath">An .apks output ZIP file containing APK files.</param>
        /// <param name="buildMode">The type of APKs to build from the Android App Bundle.</param>
        /// <param name="enableLocalTesting">
        /// If true, enables a testing mode where fast-follow and on-demand asset packs are fetched from storage
        /// rather than downloaded.
        /// </param>
        /// <returns>An error message if there was a problem running bundletool, or null if successful.</returns>
        public static string BuildApks(
            string aabFilePath,
            string apksFilePath,
            BundletoolBuildMode buildMode = BundletoolBuildMode.Default,
            bool enableLocalTesting       = false)
        {
            var bundletoolHelper = new BundletoolHelper(new JavaUtils());

            if (bundletoolHelper.Initialize(new BuildToolLogger()))
            {
                return(bundletoolHelper.BuildApkSet(aabFilePath, apksFilePath, buildMode, enableLocalTesting));
            }

            return("Failed to initialize bundletool.");
        }
コード例 #5
0
        /// <summary>
        /// Converts the specified app bundle into an apk set file.
        /// </summary>
        /// <returns>An error message if the operation failed and null otherwise.</returns>
        public string ConvertAabToApkSet(string aabFilePath, BundletoolBuildMode buildMode, out string apkSetFilePath)
        {
            var aabFileDirectory = Path.GetDirectoryName(aabFilePath);

            if (aabFileDirectory == null)
            {
                apkSetFilePath = null;
                return("App Bundle does not exist at path " + aabFilePath);
            }

            var apkSetFileName = Path.GetFileNameWithoutExtension(aabFilePath);

            apkSetFilePath = Path.Combine(aabFileDirectory, apkSetFileName + ".apks");
            File.Delete(apkSetFilePath);

            // TODO: Set this value to be true regardless of BuildMode once local testing works on instant.
            var enableLocalTesting = buildMode == BundletoolBuildMode.Persistent;

            return(_bundletool.BuildApkSet(aabFilePath, apkSetFilePath, buildMode, enableLocalTesting));
        }