/// <summary>
        /// Manage the android dependecies based on the project settings.
        /// </summary>
        /// <param name="settings">The <see cref="ARCoreExtensionsProjectSettings"/> used by
        /// current build.</param>
        public void ManageAndroidDependencies(ARCoreExtensionsProjectSettings settings)
        {
            List <IDependentModule> featureModules = DependentModulesManager.GetModules();
            string folderPath =
                AssetDatabase.GUIDToAssetPath(_buildResourceFolderGUID) + _dependenciesDirectory;

            Directory.CreateDirectory(folderPath);
            foreach (IDependentModule module in featureModules)
            {
                if (module.IsEnabled(settings, UnityEditor.BuildTarget.Android))
                {
                    string dependenciesSnippet = module.GetAndroidDependenciesSnippet(settings);
                    if (!string.IsNullOrEmpty(dependenciesSnippet))
                    {
                        string fileName     = module.GetType().Name + _androidDependenciesFileSuffix;
                        string fullPath     = Path.Combine(folderPath, fileName);
                        string finalSnippet = XDocument.Parse(string.Format(
                                                                  _androidDependenciesFormat, dependenciesSnippet)).ToString();
                        File.WriteAllText(fullPath, finalSnippet);
                        Debug.LogFormat("Module {0} added Android library dependencies:\n{1}",
                                        module.GetType().Name, finalSnippet);
                        AssetDatabase.Refresh();
                        AndroidDependenciesHelper.DoPlayServicesResolve();
                    }
                }
            }
        }
 public static void OnPostprocessBuild(
     UnityEditor.BuildTarget target, string pathToBuiltProject)
 {
     if (!UnityEditorInternal.InternalEditorUtility.inBatchMode)
     {
         // Only clean up resolver in Batch Mode.
         return;
     }
     if (target == UnityEditor.BuildTarget.Android)
     {
         Debug.Log("ARCoreExtensions: Cleaning up Android library dependencies.");
         string folderPath = Application.dataPath + _dependenciesDirectory;
         Directory.Delete(folderPath, true);
         AssetDatabase.Refresh();
         AndroidDependenciesHelper.DoPlayServicesResolve();
     }
     else if (target == UnityEditor.BuildTarget.iOS)
     {
         foreach (string enabledTemplateFile in _enabledIOSTemplate)
         {
             Debug.LogFormat("ARCoreExtensions: Cleaning up {0} in PostprocessBuild.",
                             enabledTemplateFile);
             IOSSupportHelper.UpdateIOSPodDependencies(false, enabledTemplateFile);
         }
     }
 }
Esempio n. 3
0
        private static void PostprocessAndroidBuild()
        {
            Debug.Log("ARCoreExtensions: Cleaning up Keyless dependencies.");

            // Run the pre-process step with <c>Keyless</c> disabled so project files get reset.
            // Then run the PlayServicesResolver dependency resolution which will remove
            // the Keyless dependencies.
            PreprocessAndroidBuild(false);
            AndroidDependenciesHelper.DoPlayServicesResolve();
        }
Esempio n. 4
0
        /// <summary>
        /// Preprocess step for Android Build.
        /// </summary>
        /// <param name="enabledKeyless">Whether to enable or disable keyless.</param>
        public static void PreprocessAndroidBuild(bool enabledKeyless)
        {
            AndroidDependenciesHelper.UpdateAndroidDependencies(
                enabledKeyless, _androidKeylessDependenciesGuid);

            if (enabledKeyless)
            {
                Debug.Log("ARCoreExtensions: Including Keyless dependencies in this build.");
                AndroidDependenciesHelper.DoPlayServicesResolve();
            }
        }
Esempio n. 5
0
        private static bool IsCloudAnchorModeEnabled()
        {
            foreach (ARCoreExtensionsConfig config in
                     AndroidDependenciesHelper.GetAllSessionConfigs().Keys)
            {
                if (config.CloudAnchorMode != CloudAnchorMode.Disabled)
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Callback before the build is started.</para>
        /// </summary>
        /// <param name="report">A report containing information about the build,
        /// such as its target platform and output path.</param>
        public void OnPreprocessBuild(BuildReport report)
        {
            UnityEditor.BuildTarget buildTarget = report.summary.platform;
            if (DependentModulesManager.GetModules().Count == 0)
            {
                return;
            }

            CheckCompatibilityWithAllSessionConfigs(
                ARCoreExtensionsProjectSettings.Instance,
                AndroidDependenciesHelper.GetAllSessionConfigs(),
                buildTarget);
        }
Esempio n. 7
0
        /// <summary>
        /// Callback before the build is started.</para>
        /// </summary>
        /// <param name="report">A report containing information about the build,
        /// such as its target platform and output path.</param>
        public void OnPreprocessBuild(BuildReport report)
        {
            if (report.summary.platform == BuildTarget.Android)
            {
                if (GetModules().Count == 0)
                {
                    return;
                }

                CheckCompatibilityWithAllSesssionConfigs(
                    ARCoreExtensionsProjectSettings.Instance,
                    AndroidDependenciesHelper.GetAllSessionConfigs());
            }
        }
        private static void AddEarthDependecyOnAndroid(bool enabled)
        {
            Debug.LogFormat("ARCoreExtensions: {0} Earth Cloud Anchor dependencies.",
                            enabled ? "Adding" : "Removing");

            AndroidDependenciesHelper.UpdateAndroidDependencies(enabled, _locationDependencyGuid);

            // If we are in batch mode, ExternalDependencyManager won't auto-resolve so attempt to
            // resolve dependencies.
            if (enabled && UnityEditorInternal.InternalEditorUtility.inBatchMode)
            {
                AndroidDependenciesHelper.DoPlayServicesResolve();
            }
        }
        private static void CleanupEarthDependencyOnAndroid()
        {
            if (UnityEditorInternal.InternalEditorUtility.inBatchMode &&
                System.Environment.CommandLine.Contains("-earth_cleandeps"))
            {
                Debug.Log("ARCoreExtensions: Cleaning up Earth Cloud Anchor dependencies.");

                // Run the pre-process step with disabled so project files get reset.
                // Then run the ExternalDependencyManager dependency resolution which will remove
                // earth cloud anchor dependencies.
                AddEarthDependecyOnAndroid(false);
                AndroidDependenciesHelper.DoPlayServicesResolve();
            }
        }
 public static void OnPostprocessBuild(
     UnityEditor.BuildTarget target, string pathToBuiltProject)
 {
     if (target == UnityEditor.BuildTarget.Android)
     {
         Debug.Log("ARCoreExtensions: Cleaning up Android library dependencies.");
         string folderPath =
             AssetDatabase.GUIDToAssetPath(_buildResourceFolderGUID) +
             _dependenciesDirectory;
         Directory.Delete(folderPath, true);
         AssetDatabase.Refresh();
         AndroidDependenciesHelper.DoPlayServicesResolve();
     }
     else if (target == UnityEditor.BuildTarget.iOS)
     {
         foreach (string enabledTemplateFile in _enabledIOSTemplate)
         {
             Debug.LogFormat("ARCoreExtensions: Cleaning up {0} in PostprocessBuild.",
                             enabledTemplateFile);
             IOSSupportHelper.UpdateIOSPodDependencies(false, enabledTemplateFile);
         }
     }
 }
        private void SetApiKeyOnAndroid()
        {
            bool cloudAnchorsEnabled = !string.IsNullOrEmpty(
                ARCoreExtensionsProjectSettings.Instance.AndroidCloudServicesApiKey);

            var cachedCurrentDirectory      = Directory.GetCurrentDirectory();
            var cloudAnchorsManifestAARPath = Path.GetFullPath(
                Path.Combine(AssetDatabase.GUIDToAssetPath(_pluginsFolderGUID),
                             _cloudAnchorManifestFileName));

            if (cloudAnchorsEnabled)
            {
                string jarPath = AndroidDependenciesHelper.GetJdkPath();
                if (string.IsNullOrEmpty(jarPath))
                {
                    throw new BuildFailedException("Cannot find a valid JDK path in this build.");
                }

                jarPath = Path.Combine(jarPath, "bin/jar");

                // If the API Key didn't change then do nothing.
                if (!IsApiKeyDirty(jarPath, cloudAnchorsManifestAARPath,
                                   ARCoreExtensionsProjectSettings.Instance.AndroidCloudServicesApiKey))
                {
                    return;
                }

                // Replace the project's Cloud Anchor AAR with the newly generated AAR.
                Debug.Log("Enabling Cloud Anchors in this build.");

                var tempDirectoryPath =
                    Path.Combine(cachedCurrentDirectory, FileUtil.GetUniqueTempPathInProject());

                try
                {
                    // Locate cloud_anchor_manifest.aartemplate from the package cache.
                    var manifestTemplatePath = Path.GetFullPath(
                        Path.Combine(AssetDatabase.GUIDToAssetPath(_manifestTemplateFolderGUID),
                                     _cloudAnchorManifestFileName + "template"));

                    // Move to a temp directory.
                    Directory.CreateDirectory(tempDirectoryPath);
                    Directory.SetCurrentDirectory(tempDirectoryPath);

                    // Extract the "template AAR" and remove it.
                    string output;
                    string errors;
                    ShellHelper.RunCommand(
                        jarPath, string.Format("xf \"{0}\"", manifestTemplatePath), out output,
                        out errors);

                    // Replace API key template parameter in manifest file.
                    var manifestPath = Path.Combine(tempDirectoryPath, "AndroidManifest.xml");
                    var manifestText = File.ReadAllText(manifestPath);
                    manifestText = manifestText.Replace(
                        "{{CLOUD_ANCHOR_API_KEY}}",
                        ARCoreExtensionsProjectSettings.Instance.AndroidCloudServicesApiKey);
                    File.WriteAllText(manifestPath, manifestText);

                    // Compress the new AAR.
                    var fileListBuilder = new StringBuilder();
                    foreach (var filePath in Directory.GetFiles(tempDirectoryPath))
                    {
                        fileListBuilder.AppendFormat(" {0}", Path.GetFileName(filePath));
                    }

                    string command = string.Format(
                        "cf {0} {1}", _cloudAnchorManifestFileName, fileListBuilder);

                    ShellHelper.RunCommand(
                        jarPath,
                        command,
                        out output,
                        out errors);

                    if (!string.IsNullOrEmpty(errors))
                    {
                        throw new BuildFailedException(
                                  string.Format(
                                      "Error creating jar for Cloud Anchor manifest: {0}", errors));
                    }

                    File.Copy(Path.Combine(tempDirectoryPath, _cloudAnchorManifestFileName),
                              cloudAnchorsManifestAARPath, true);
                }
                finally
                {
                    // Cleanup.
                    Directory.SetCurrentDirectory(cachedCurrentDirectory);
                    Directory.Delete(tempDirectoryPath, true);

                    AssetDatabase.Refresh();
                }

                AssetHelper.GetPluginImporterByName(_cloudAnchorManifestFileName)
                .SetCompatibleWithPlatform(BuildTarget.Android, true);
            }
            else
            {
                Debug.Log(
                    "Cloud Anchor API key has not been set. API key authentication will " +
                    "be disabled in this build.");
                if (File.Exists(cloudAnchorsManifestAARPath))
                {
                    File.Delete(cloudAnchorsManifestAARPath);
                }

                AssetDatabase.Refresh();
            }
        }