Exemplo n.º 1
0
    private static bool CheckADBDevices()
    {
        // Check if there are any ADB devices connected before starting the build process
        var adbTool = new OVRADBTool(OVRConfig.Instance.GetAndroidSDKPath());

        if (adbTool.isReady)
        {
            List <string> devices = adbTool.GetDevices();
            if (devices.Count == 0)
            {
                OVRPlugin.SendEvent("no_adb_devices", "", "ovrbuild");
                UnityEngine.Debug.LogError("No ADB devices connected. Cannot perform OVR Build and Run.");
                return(false);
            }
            else if (devices.Count > 1)
            {
                OVRPlugin.SendEvent("multiple_adb_devices", "", "ovrbuild");
                UnityEngine.Debug.LogError("Multiple ADB devices connected. Cannot perform OVR Build and Run.");
                return(false);
            }
        }
        else
        {
            OVRPlugin.SendEvent("ovr_adbtool_initialize_failure", "", "ovrbuild");
            UnityEngine.Debug.LogError("OVR ADB Tool failed to initialize. Check the Android SDK path in [Edit -> Preferences -> External Tools]");
            return(false);
        }
        return(true);
    }
Exemplo n.º 2
0
    private static bool CheckADBDevices(out string connectedDeviceName)
    {
        // Check if there are any ADB devices connected before starting the build process
        var adbTool = new OVRADBTool(OVRConfig.Instance.GetAndroidSDKPath());

        connectedDeviceName = null;

        if (adbTool.isReady)
        {
            List <string> devices = adbTool.GetDevices();
            if (devices.Count == 0)
            {
                UnityEngine.Debug.LogError("No ADB devices connected. Connect a device to this computer to run APK.");
                return(false);
            }
            else if (devices.Count > 1)
            {
                UnityEngine.Debug.LogError("Multiple ADB devices connected. Disconnect extra devices from this computer to run APK.");
                return(false);
            }
            else
            {
                connectedDeviceName = devices[0];
                return(true);
            }
        }
        else
        {
            UnityEngine.Debug.LogError("OVR ADB Tool failed to initialize. Check the Android SDK path in [Edit -> Preferences -> External Tools]");
            return(false);
        }
    }
Exemplo n.º 3
0
    public void OnPostprocessBuild(BuildReport report)
    {
#if UNITY_ANDROID
        if (autoIncrementVersion)
        {
            if ((report.summary.options & BuildOptions.Development) == 0)
            {
                PlayerSettings.Android.bundleVersionCode++;
                UnityEngine.Debug.Log("Incrementing version code to " + PlayerSettings.Android.bundleVersionCode);
            }
        }

        bool isExporting = true;
        foreach (var step in report.steps)
        {
            if (step.name.Contains("Compile scripts") ||
                step.name.Contains("Building scenes") ||
                step.name.Contains("Writing asset files") ||
                step.name.Contains("Preparing APK resources") ||
                step.name.Contains("Creating Android manifest") ||
                step.name.Contains("Processing plugins") ||
                step.name.Contains("Exporting project") ||
                step.name.Contains("Building Gradle project"))
            {
                OVRPlugin.SendEvent("build_step_" + step.name.ToLower().Replace(' ', '_'),
                                    step.duration.TotalSeconds.ToString(), "ovrbuild");
#if BUILDSESSION
                UnityEngine.Debug.LogFormat("build_step_" + step.name.ToLower().Replace(' ', '_') + ": {0}", step.duration.TotalSeconds.ToString());
#endif
                if (step.name.Contains("Building Gradle project"))
                {
                    isExporting = false;
                }
            }
        }
        OVRPlugin.AddCustomMetadata("build_step_count", report.steps.Length.ToString());
        if (report.summary.outputPath.Contains("apk"))         // Exclude Gradle Project Output
        {
            var fileInfo = new System.IO.FileInfo(report.summary.outputPath);
            OVRPlugin.AddCustomMetadata("build_output_size", fileInfo.Length.ToString());
        }
#endif
        if (!report.summary.outputPath.Contains("OVRGradleTempExport"))
        {
            OVRPlugin.SendEvent("build_complete", (System.DateTime.Now - buildStartTime).TotalSeconds.ToString(), "ovrbuild");
#if BUILDSESSION
            UnityEngine.Debug.LogFormat("build_complete: {0}", (System.DateTime.Now - buildStartTime).TotalSeconds.ToString());
#endif
        }

#if UNITY_ANDROID
        if (!isExporting)
        {
            // Get the hosts path to Android SDK
            if (adbTool == null)
            {
                adbTool = new OVRADBTool(OVRConfig.Instance.GetAndroidSDKPath(false));
            }

            if (adbTool.isReady)
            {
                // Check to see if there are any ADB devices connected before continuing.
                List <string> devices = adbTool.GetDevices();
                if (devices.Count == 0)
                {
                    return;
                }

                // Clear current logs on device
                Process adbClearProcess;
                adbClearProcess = adbTool.RunCommandAsync(new string[] { "logcat --clear" }, null);

                // Add a timeout if we cannot get a response from adb logcat --clear in time.
                Stopwatch timeout = new Stopwatch();
                timeout.Start();
                while (!adbClearProcess.WaitForExit(100))
                {
                    if (timeout.ElapsedMilliseconds > 2000)
                    {
                        adbClearProcess.Kill();
                        return;
                    }
                }

                // Check if existing ADB process is still running, kill if needed
                if (adbProcess != null && !adbProcess.HasExited)
                {
                    adbProcess.Kill();
                }

                // Begin thread to time upload and install
                var thread = new Thread(delegate()
                {
                    TimeDeploy();
                });
                thread.Start();
            }
        }
#endif
    }