コード例 #1
0
        private void _PreprocessAndroidBuild()
        {
            // Get the Jdk path.
            var jdkPath = UnityEditor.EditorPrefs.GetString("JdkPath");

            if (string.IsNullOrEmpty(jdkPath))
            {
                Debug.Log(
                    "Unity 'Preferences > External Tools > Android JDK' path is not set. " +
                    "Falling back to JAVA_HOME environment variable.");
                jdkPath = System.Environment.GetEnvironmentVariable("JAVA_HOME");
            }

            if (string.IsNullOrEmpty(jdkPath))
            {
                throw new BuildFailedException(
                          "A JDK path needs to be specified for the Android build.");
            }

            bool cloudAnchorsEnabled =
                !string.IsNullOrEmpty(ARCoreProjectSettings.Instance.CloudServicesApiKey);

            var cachedCurrentDirectory = Directory.GetCurrentDirectory();
            var pluginsFolderPath      = Path.Combine(cachedCurrentDirectory,
                                                      AssetDatabase.GUIDToAssetPath(k_PluginsFolderGuid));
            string cloudAnchorsManifestAarPath =
                Path.Combine(pluginsFolderPath, "cloud_anchor_manifest.aar");
            var jarPath = Path.Combine(jdkPath, "bin/jar");

            if (cloudAnchorsEnabled)
            {
                // If the Api Key didn't change then do nothing.
                if (!_IsApiKeyDirty(jarPath, cloudAnchorsManifestAarPath,
                                    ARCoreProjectSettings.Instance.CloudServicesApiKey))
                {
                    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
                {
                    // Move to a temp directory.
                    Directory.CreateDirectory(tempDirectoryPath);
                    Directory.SetCurrentDirectory(tempDirectoryPath);

                    var manifestTemplatePath = Path.Combine(
                        cachedCurrentDirectory,
                        AssetDatabase.GUIDToAssetPath(k_ManifestTemplateGuid));

                    // 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}}",
                        ARCoreProjectSettings.Instance.CloudServicesApiKey);
                    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 cloud_anchor_manifest.aar {0}", fileListBuilder.ToString());

                    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, "cloud_anchor_manifest.aar"),
                              cloudAnchorsManifestAarPath, true);
                }
                finally
                {
                    // Cleanup.
                    Directory.SetCurrentDirectory(cachedCurrentDirectory);
                    Directory.Delete(tempDirectoryPath, true);

                    AssetDatabase.Refresh();
                }

                AssetHelper.GetPluginImporterByName("cloud_anchor_manifest.aar")
                .SetCompatibleWithPlatform(BuildTarget.Android, true);
            }
            else
            {
                Debug.Log(
                    "Cloud Anchor API key has not been set. Cloud Anchors will be disabled in " +
                    "this build.");
                File.Delete(cloudAnchorsManifestAarPath);
                AssetDatabase.Refresh();
            }
        }
コード例 #2
0
        private static void CaptureBugReport()
        {
            string desktopPath = Environment.GetFolderPath(
                Environment.SpecialFolder.Desktop);
            DateTime timeStamp         = DateTime.Now;
            string   fileNameTimestamp = timeStamp.ToString("yyyyMMdd_hhmmss");
            string   filePath          = Path.Combine(
                desktopPath, k_FileNamePrefix + fileNameTimestamp + ".txt");
            StreamWriter writer;

            // Operating system and hardware info have to be handled separately based on OS
            switch (SystemInfo.operatingSystemFamily)
            {
            case OperatingSystemFamily.MacOSX:
                writer = File.CreateText(filePath);

                writer.WriteLine("*** GOOGLE ARCORE SDK FOR UNITY OSX BUG REPORT ***");
                writer.WriteLine("Timestamp: " + timeStamp.ToString());

                writer.WriteLine();
                writer.WriteLine("*** OPERATING SYSTEM INFORMATION ***");
                WriteCommand("system_profiler", "SPSoftwareDataType", writer);

                writer.WriteLine("*** GRAPHICS INFORMATION ***");
                WriteCommand("system_profiler", "SPDisplaysDataType", writer);

                WriteOsIndependentFields(writer);

                string stdOut;
                string stdErr;

                // Get PATH directories to search for adb in.
                ShellHelper.RunCommand(
                    "/bin/bash", "-c -l \"echo $PATH\"", out stdOut, out stdErr);
                stdOut.Trim();

                writer.WriteLine("*** ADB VERSIONS ON PATH ***");
                WriteAdbPathVersions(stdOut.Split(':'), writer);

                writer.WriteLine("*** TYPE -A ADB ***");
                WriteCommand("/bin/bash", "-c -l \"type -a adb\"", writer);

                writer.WriteLine("*** RUNNING ADB PROCESSES ***");
                WriteCommand(
                    "/bin/bash", "-c -l \"ps -ef | grep -i adb | grep -v grep\"", writer);

                writer.WriteLine("*** RUNNING UNITY PROCESSES ***");
                WriteCommand(
                    "/bin/bash", "-c -l \"ps -ef | grep -i Unity | grep -v grep\"", writer);

                writer.Close();

                Debug.Log(
                    "ARCore bug report captured. File can be found here:\n" +
                    Path.GetFullPath(filePath));
                break;

            case OperatingSystemFamily.Windows:
                writer = File.CreateText(filePath);

                writer.WriteLine("*** GOOGLE ARCORE SDK FOR UNITY WINDOWS BUG REPORT ***");
                writer.WriteLine("Timestamp: " + timeStamp.ToString());

                writer.WriteLine("*** OPERATING SYSTEM INFORMATION ***");
                WriteCommand("cmd.exe", "/C systeminfo", writer);

                writer.WriteLine("*** GRAPHICS INFORMATION ***");
                WriteCommand(
                    "cmd.exe", "/C wmic path win32_VideoController get /format:list", writer);

                WriteOsIndependentFields(writer);

                string pathStr = Environment.GetEnvironmentVariable("PATH").Trim();

                writer.WriteLine("*** ADB VERSIONS ON PATH ***");
                WriteAdbPathVersions(pathStr.Split(';'), writer);

                writer.WriteLine("*** RUNNING ADB PROCESSES ***");
                WriteCommand("cmd.exe",
                             "/C TASKLIST | c:\\Windows\\System32\\findstr.exe \"adb\"", writer);

                writer.WriteLine("*** RUNNING UNITY PROCESSES ***");
                WriteCommand("cmd.exe",
                             "/C TASKLIST | c:\\Windows\\System32\\findstr.exe \"Unity\"", writer);

                writer.Close();

                Debug.Log(
                    "ARCore bug report captured. File can be found here:\n" +
                    Path.GetFullPath(filePath));
                break;

            default:
                string dialogMessage = "ARCore does not support capturing bug reports for " +
                                       SystemInfo.operatingSystemFamily + " at this time.";

                EditorUtility.DisplayDialog("ARCore Bug Report", dialogMessage, "OK");
                break;
            }
        }