示例#1
0
        /// <summary>
        /// Creates a new <see cref="AssetBundleVariant"/>. Evaluates some conditions and may set <see cref="Errors"/>.
        /// </summary>
        /// <param name="assetBundleName">Name of the AssetBundle represented by this variant.</param>
        /// <param name="fileSizeBytes">Size of the file in bytes, or <see cref="FileSizeIfMissing"/>.</param>
        /// <param name="directDependencies">AssetBundles that are direct dependencies of this one.</param>
        /// <param name="allDependencies">AssetBundles that are direct or transitive dependencies of this one.</param>
        /// <param name="path">The path to the AssetBundle represented by this variant.</param>
        public static AssetBundleVariant CreateVariant(
            string assetBundleName,
            long fileSizeBytes,
            string[] directDependencies,
            string[] allDependencies,
            string path)
        {
            var variant = new AssetBundleVariant
            {
                DirectDependencies = directDependencies ?? EmptyStringArray,
                AllDependencies    = allDependencies ?? EmptyStringArray,
                FileSizeBytes      = fileSizeBytes,
                Path = path,
            };

            if (fileSizeBytes == FileSizeIfMissing)
            {
                variant.Errors.Add(AssetPackError.FileMissing);
            }

            if (!AndroidAppBundle.IsValidModuleName(assetBundleName))
            {
                variant.Errors.Add(AssetPackError.InvalidName);
            }

            return(variant);
        }
示例#2
0
        /// <summary>
        /// Emulates Unity's File -> Build And Run menu option.
        /// </summary>
        private static void EmulateUnityBuildAndRun()
        {
            var androidSdk         = new AndroidSdk();
            var androidSdkPlatform = new AndroidSdkPlatform(androidSdk);
            var androidBuildTools  = new AndroidBuildTools(androidSdk);
            var javaUtils          = new JavaUtils();
            var apkSigner          = new ApkSigner(androidBuildTools, javaUtils);
            var androidBuilder     = new AndroidBuilder(androidSdkPlatform, apkSigner);
            var buildToolLogger    = new BuildToolLogger();

            if (!androidBuilder.Initialize(buildToolLogger))
            {
                return;
            }

            if (EditorUserBuildSettings.androidBuildSystem == AndroidBuildSystem.Gradle)
            {
                EditorUserBuildSettings.exportAsGoogleAndroidProject = false;
            }

            var artifactName       = AndroidAppBundle.IsNativeBuildEnabled() ? "temp.aab" : "temp.apk";
            var artifactPath       = Path.Combine(Path.GetTempPath(), artifactName);
            var buildPlayerOptions = AndroidBuildHelper.CreateBuildPlayerOptions(artifactPath);

            buildPlayerOptions.options |= BuildOptions.AutoRunPlayer;
            androidBuilder.Build(buildPlayerOptions);
        }
示例#3
0
        /// <summary>
        /// Builds an Android Player with the specified options.
        /// Note: the specified <see cref="BuildPlayerOptions.locationPathName"/> field is ignored and the
        /// Android Player is written to a temporary file whose path is returned as a string.
        /// </summary>
        /// <returns>The path to the file if the build succeeded, or null if it failed or was cancelled.</returns>
        public virtual string BuildAndroidPlayer(BuildPlayerOptions buildPlayerOptions)
        {
            var workingDirectory = new DirectoryInfo(_workingDirectoryPath);

            if (workingDirectory.Exists)
            {
                workingDirectory.Delete(true);
            }

            workingDirectory.Create();

            if (UseNativeAppBundleSupport)
            {
                AndroidAppBundle.EnableNativeBuild();
            }

            var androidPlayerFilePath = Path.Combine(workingDirectory.FullName, "tmp.aab");

            Debug.LogFormat("Building Android Player: {0}", androidPlayerFilePath);
            // This Android Player is an intermediate build artifact, so use a temporary path for the output file path.
            var updatedBuildPlayerOptions = new BuildPlayerOptions
            {
                assetBundleManifestPath = buildPlayerOptions.assetBundleManifestPath,
                locationPathName        = androidPlayerFilePath,
                options     = buildPlayerOptions.options,
                scenes      = buildPlayerOptions.scenes,
                target      = buildPlayerOptions.target,
                targetGroup = buildPlayerOptions.targetGroup
            };

            // Do not use BuildAndSign since this signature won't be used.
            return(_androidBuilder.Build(updatedBuildPlayerOptions) ? androidPlayerFilePath : null);
        }
示例#4
0
        /// <summary>
        /// Builds an Android Player with the specified options.
        /// Note: the specified <see cref="BuildPlayerOptions.locationPathName"/> field is ignored and the
        /// Android Player is written to a temporary file whose path is returned as a string.
        /// </summary>
        /// <returns>True if the build succeeded, or false if it failed or was cancelled.</returns>
        public virtual bool BuildAndroidPlayer(BuildPlayerOptions buildPlayerOptions)
        {
            var workingDirectory = new DirectoryInfo(_workingDirectoryPath);

            if (workingDirectory.Exists)
            {
                workingDirectory.Delete(true);
            }

            workingDirectory.Create();

            if (UseNativeAppBundleSupport)
            {
                AndroidAppBundle.EnableNativeBuild();
            }

            Debug.LogFormat("Building Android Player: {0}", AndroidPlayerFilePath);
            // This Android Player is an intermediate build artifact, so use a temporary path for the output file path.
            var updatedBuildPlayerOptions = new BuildPlayerOptions
            {
                assetBundleManifestPath = buildPlayerOptions.assetBundleManifestPath,
                locationPathName        = AndroidPlayerFilePath,
                options     = buildPlayerOptions.options,
                scenes      = buildPlayerOptions.scenes,
                target      = buildPlayerOptions.target,
                targetGroup = buildPlayerOptions.targetGroup
            };

            if (EditorUserBuildSettings.androidBuildSystem == AndroidBuildSystem.Gradle)
            {
                EditorUserBuildSettings.exportAsGoogleAndroidProject = false;
            }

            // Do not use BuildAndSign since this signature won't be used.
            var buildSucceeded = _androidBuilder.Build(updatedBuildPlayerOptions);

            if (!buildSucceeded)
            {
                return(false);
            }

            if (!File.Exists(AndroidPlayerFilePath))
            {
                // If the build is canceled late, sometimes the build "succeeds" but the file is missing.
                // Since this may be intentional, don't display an onscreen error dialog. However, just
                // in case the build wasn't canceled, print a warning instead of silently failing.
                Debug.LogWarningFormat(
                    "The Android Player file \"{0}\"is missing, possibly because of a late build cancellation.",
                    AndroidPlayerFilePath);
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Builds an APK to a temporary location, then installs and runs it using ia.jar
        /// </summary>
        private static void BuildAndRunApk(BuildToolLogger buildToolLogger)
        {
            var androidSdk             = new AndroidSdk();
            var androidSdkPlatform     = new AndroidSdkPlatform(androidSdk);
            var androidBuildTools      = new AndroidBuildTools(androidSdk);
            var javaUtils              = new JavaUtils();
            var apkSigner              = new ApkSigner(androidBuildTools, javaUtils);
            var androidBuilder         = new AndroidBuilder(androidSdkPlatform, apkSigner);
            var playInstantBuildHelper = new PlayInstantBuildHelper(isInstantRequired: true);

            if (!androidBuilder.Initialize(buildToolLogger) ||
                !playInstantBuildHelper.Initialize(buildToolLogger) ||
                !javaUtils.Initialize(buildToolLogger))
            {
                return;
            }

            var jarPath = IaJarPath;

            if (jarPath == null)
            {
                buildToolLogger.DisplayErrorDialog("Build and Run failed to locate ia.jar file");
                return;
            }

            AndroidAppBundle.DisableNativeBuild();

            var apkPath = Path.Combine(Path.GetTempPath(), "temp.apk");

            Debug.LogFormat("Build and Run package location: {0}", apkPath);

            var buildPlayerOptions = AndroidBuildHelper.CreateBuildPlayerOptions(apkPath);

            if (!androidBuilder.BuildAndSign(buildPlayerOptions))
            {
                // Do not log here. The method we called was responsible for logging.
                return;
            }

            InstallInstantApp(jarPath, apkPath, androidSdk, javaUtils);
        }
示例#6
0
        /// <summary>
        /// Builds an Android Player with the specified options.
        /// Note: the specified <see cref="BuildPlayerOptions.locationPathName"/> field is ignored and the
        /// Android Player is written to a temporary file.
        /// </summary>
        public virtual AndroidBuildResult BuildAndroidPlayer(BuildPlayerOptions buildPlayerOptions)
        {
            var workingDirectory = new DirectoryInfo(_workingDirectoryPath);

            if (workingDirectory.Exists)
            {
                workingDirectory.Delete(true);
            }

            workingDirectory.Create();

            if (UseNativeAppBundleSupport)
            {
                AndroidAppBundle.EnableNativeBuild();
            }

            Debug.LogFormat("Building Android Player: {0}", AndroidPlayerFilePath);
            // This Android Player is an intermediate build artifact, so use a temporary path for the output file path.
            var updatedBuildPlayerOptions = new BuildPlayerOptions
            {
                assetBundleManifestPath = buildPlayerOptions.assetBundleManifestPath,
                locationPathName        = AndroidPlayerFilePath,
                options     = buildPlayerOptions.options,
                scenes      = buildPlayerOptions.scenes,
                target      = buildPlayerOptions.target,
                targetGroup = buildPlayerOptions.targetGroup
            };

            if (EditorUserBuildSettings.androidBuildSystem == AndroidBuildSystem.Gradle)
            {
                EditorUserBuildSettings.exportAsGoogleAndroidProject = false;
            }

            // Do not use BuildAndSign since this signature won't be used.
            return(_androidBuilder.Build(updatedBuildPlayerOptions));
        }