public bool Initialize(BuildToolLogger buildToolLogger)
 {
     _initialized = true;
     // Cache IsInstantBuildType because IsInstantBuildType can only be called on the main thread.
     _isInstant = PlayInstantBuildSettings.IsInstantBuildType();
     return(_buildHelper.Initialize(buildToolLogger));
 }
        void IBuildAndRunExtension.BuildAndRun()
        {
            var buildToolLogger = new BuildToolLogger();

            // TODO Build an app bundle once bundletool supports locally testing asset packs on instant.
            BuildAndRunApk(buildToolLogger);
        }
Esempio n. 3
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);
        }
        public void OnPostGenerateGradleAndroidProject(string path)
        {
            if (!BuiltInPadHelper.ProjectUsesBuiltInPad())
            {
                return;
            }

            if (BuiltInPadHelper.ProjectUsesGradleTemplate())
            {
                return;
            }

            var projectPath     = Path.GetDirectoryName(Application.dataPath);
            var gradleLibFolder = Path.Combine(projectPath, path, "libs");

            if (!Directory.Exists(gradleLibFolder))
            {
                return;
            }

            if (!Directory.EnumerateFiles(gradleLibFolder, PlayCoreAarSearchPattern).Any())
            {
                return;
            }

            var logger = new BuildToolLogger();

            logger.DisplayErrorDialog(
                "Detected Play Core library conflict. To resolve the conflict, enable \"Custom Main Gradle Template\" in " +
                "\"Android Player > Publishing Settings\" and enable \"Patch mainTemplate.gradle\" in \"Assets > External " +
                "Dependency Manager > Android Resolver > Settings\"");
        }
Esempio n. 5
0
        private void DetectAar(BuildTarget target)
        {
            if (target != BuildTarget.Android)
            {
                return;
            }

            var playCorePath = AssetDatabase.GUIDToAssetPath(PlayCoreAarGuid);

            if (string.IsNullOrEmpty(playCorePath))
            {
                return;
            }

            // Even after calling AssetDatabase.DeleteAsset, AssetDatabase.GUIDToAssetPath may return
            // the path of the asset before it was deleted. So we check here to make sure the file exists.
            if (!File.Exists(Path.GetFullPath(playCorePath)))
            {
                return;
            }

            var logger  = new BuildToolLogger();
            var message =
                string.Format(
                    "Detected an outdated playcore.aar left over from a previous version at path:\n\n{0}.\n\nPress OK to delete it.",
                    playCorePath);

            var clickedOk = logger.DisplayActionableErrorDialog(message);

            if (clickedOk)
            {
                AssetDatabase.DeleteAsset(playCorePath);
            }
        }
        private static void RunBundle(string aabFile)
        {
            var buildToolLogger = new BuildToolLogger();
            var appBundleRunner = CreateAppBundleRunner();

            if (!appBundleRunner.Initialize(buildToolLogger))
            {
                buildToolLogger.DisplayErrorDialog("Failed to initialize AppBundleRunner.");
                return;
            }

            appBundleRunner.RunBundle(aabFile, GetBuildMode());
        }
Esempio n. 7
0
        public virtual bool Initialize(BuildToolLogger buildToolLogger)
        {
            IsInstantBuild = PlayInstantBuildSettings.IsInstantBuildType();
            if (!IsInstantBuild)
            {
                if (!_isInstantRequired)
                {
                    // Check passed: this is a persistent app build invoked by a builder that supports persistent apps.
                    return(true);
                }

                // This builder only works for instant apps, however the build isn't currently set to instant.
                Debug.LogError("Build halted since selected build type is \"Installed\"");
                var instantRequiredMessage = string.Format(
                    "The currently selected Android build type is \"Installed\".\n\n" +
                    "Click \"{0}\" to open the \"{1}\" window where the build type can be changed to \"Instant\".",
                    WindowUtils.OkButtonText, BuildSettingsWindow.WindowTitle);
                if (buildToolLogger.DisplayActionableErrorDialog(instantRequiredMessage))
                {
                    BuildSettingsWindow.ShowWindow();
                }

                return(false);
            }

            // This is an instant app build. Verify that instant-specific required policies are enabled.
            var failedPolicies = PlayInstantSettingPolicy.GetRequiredPolicies()
                                 .Where(policy => !policy.IsCorrectState())
                                 .Select(policy => policy.Name).ToArray();

            if (failedPolicies.Length == 0)
            {
                return(true);
            }

            Debug.LogErrorFormat(
                "Build halted due to incompatible settings: {0}", string.Join(", ", failedPolicies));
            var failedPoliciesMessage = string.Format(
                "{0}\n\nClick \"{1}\" to open the settings window and make required changes.",
                string.Join("\n\n", failedPolicies),
                WindowUtils.OkButtonText);

            if (buildToolLogger.DisplayActionableErrorDialog(failedPoliciesMessage))
            {
                PlayerSettingsWindow.ShowWindow();
            }

            return(false);
        }
            public override void RunPostBuildTask()
            {
                var buildToolLogger  = new BuildToolLogger();
                var appBundleBuilder = CreateAppBundleBuilder(workingDirectoryPath);

                if (!appBundleBuilder.Initialize(buildToolLogger))
                {
                    buildToolLogger.DisplayErrorDialog("Failed to initialize AppBundleBuilder in post-build task.");
                    return;
                }

                var assetPackConfig = SerializationHelper.Deserialize(serializableAssetPackConfig);

                CreateBundleAsync(appBundleBuilder, aabFilePath, assetPackConfig, runOnDevice);
            }
Esempio n. 9
0
            public override void RunPostBuildTask()
            {
                var buildToolLogger  = new BuildToolLogger();
                var assetPackConfig  = SerializationHelper.Deserialize(serializableAssetPackConfig);
                var appBundleBuilder = CreateAppBundleBuilder(workingDirectoryPath);

                if (appBundleBuilder.Initialize(buildToolLogger))
                {
                    CreateBundleAsync(appBundleBuilder, buildSettings, assetPackConfig);
                }
                else
                {
                    buildToolLogger.DisplayErrorDialog("Failed to initialize AppBundleBuilder in post-build task.");
                }
            }
Esempio n. 10
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 androidBuilder     = new AndroidBuilder(androidSdkPlatform);
            var buildToolLogger    = new BuildToolLogger();

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

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

            buildPlayerOptions.options |= BuildOptions.AutoRunPlayer;
            androidBuilder.Build(buildPlayerOptions);
        }
        /// <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);
        }
        private static string GetInstantAppJarPath(AndroidSdk androidSdk, BuildToolLogger buildToolLogger)
        {
            var jarPath = Path.Combine(androidSdk.RootPath, InstantAppsJarPath);

            if (File.Exists(jarPath))
            {
                return(jarPath);
            }

            Debug.LogErrorFormat("Build and Run failed to locate ia.jar file at: {0}", jarPath);
            var message =
                string.Format(
                    "Failed to locate version 1.2 or later of the {0}.\n\nClick \"OK\" to install the {0}.",
                    InstantAppsSdkDisplayName);

            if (buildToolLogger.DisplayActionableErrorDialog(message))
            {
                AndroidSdkPackageInstaller.InstallPackage(InstantAppsSdkPackageName, InstantAppsSdkDisplayName);
            }

            return(null);
        }
Esempio n. 13
0
 public virtual bool Initialize(BuildToolLogger buildToolLogger)
 {
     return(true);
 }