private void OnEnable()
        {
            launchConfig = new MobileLaunchConfig();

#if UNITY_EDITOR_OSX
            deviceNames    = iOSLaunchUtils.RetrieveAvailableiOSDevices().Keys.ToArray();
            simulatorNames = iOSLaunchUtils.RetrieveAvailableiOSSimulators().Keys.ToArray();
#endif
        }
Beispiel #2
0
        public static void Launch(DeviceLaunchConfig deviceLaunchConfig, MobileLaunchConfig mobileLaunchConfig)
        {
            // Throw if device type is neither iOSDevice nor iOSSimulator
            if (deviceLaunchConfig.IsAndroid)
            {
                throw new ArgumentException($"Device must of be of type {DeviceType.iOSDevice} or {DeviceType.iOSSimulator}.");
            }

            try
            {
                var useEmulator = deviceLaunchConfig.DeviceType == DeviceType.iOSSimulator;

                EditorUtility.DisplayProgressBar("Preparing your Mobile Client", "Preparing launch arguments", 0.0f);

                if (!TryGetXCodeTestRunPath(useEmulator, out var xcTestRunPath))
                {
                    Debug.LogError(
                        "Unable to find a xctestrun file for the correct architecture. Did you build your client using the correct Target SDK? " +
                        "Go to Project Settings > Player > iOS > Other Settings > Target SDK to select the correct one before building your iOS worker.");
                    return;
                }

                var arguments = mobileLaunchConfig.ToLaunchArgs();

                if (!TryModifyEnvironmentVariables(xcTestRunPath, arguments))
                {
                    Debug.LogError($"Was unable to read and modify {xcTestRunPath}.");
                    return;
                }

                if (useEmulator)
                {
                    EditorUtility.DisplayProgressBar("Launching Mobile Client", "Start iOS Simulator", 0.5f);

                    // Need to start Simulator before launching application on it
                    // instruments -w <device id> -t <profiling template>
                    var result = RedirectedProcess.Command("xcrun")
                                 .WithArgs("instruments", "-w", deviceLaunchConfig.DeviceId, "-t", "Blank")
                                 .Run();

                    if (result.ExitCode != 0)
                    {
                        Debug.LogError($"Unable to start iOS Simulator:\n{string.Join("\n", result.Stderr)}");
                        return;
                    }
                }

                EditorUtility.DisplayProgressBar("Launching Mobile Client", "Installing your app", 0.7f);

                if (!TryLaunchApplication(deviceLaunchConfig.DeviceId, xcTestRunPath))
                {
                    Debug.LogError("Failed to start app on iOS device.");
                }

                EditorUtility.DisplayProgressBar("Launching Mobile Client", "Done", 1.0f);
            }
            finally
            {
                var traceDirectories = Directory
                                       .GetDirectories(Path.Combine(Application.dataPath, ".."), "*.trace")
                                       .Where(s => s.EndsWith(".trace"));
                foreach (var directory in traceDirectories)
                {
                    Directory.Delete(directory, true);
                }

                EditorUtility.ClearProgressBar();
            }
        }
Beispiel #3
0
        public static void Launch(DeviceLaunchConfig deviceLaunchConfig, MobileLaunchConfig mobileLaunchConfig)
        {
            // Throw if device type is neither AndroidDevice nor AndroidEmulator
            if (!deviceLaunchConfig.IsAndroid)
            {
                throw new ArgumentException($"Device must of be of type {DeviceType.AndroidDevice} or {DeviceType.AndroidEmulator}.");
            }

            try
            {
                // Find adb
                if (!TryGetAdbPath(out var adbPath))
                {
                    Debug.LogError(
                        $"Could not find Android SDK. Please set the SDK location in your editor preferences.");
                    return;
                }

                EditorUtility.DisplayProgressBar("Launching Mobile Client", "Installing APK", 0.3f);

                // Find apk to install
                if (!TryGetApkPath(Common.BuildScratchDirectory, out var apkPath))
                {
                    Debug.LogError($"Could not find a built out Android binary in \"{Common.BuildScratchDirectory}\" to launch.");
                    return;
                }

                // Check if chosen emulator/device is connected
                // adb -s <device id> get-state
                if (RedirectedProcess.Command(adbPath)
                    .InDirectory(Path.GetFullPath(Path.Combine(Application.dataPath, "..")))
                    .WithArgs($"-s {deviceLaunchConfig.DeviceId}", "get-state").Run().ExitCode != 0)
                {
                    Debug.LogError($"Chosen {deviceLaunchConfig.PrettyDeviceType} ({deviceLaunchConfig.DeviceId}) not found.");
                    return;
                }

                // Install apk on chosen emulator/device
                // adb -s <device id> install -r <apk>
                if (RedirectedProcess.Command(adbPath)
                    .InDirectory(Path.GetFullPath(Path.Combine(Application.dataPath, "..")))
                    .WithArgs($"-s {deviceLaunchConfig.DeviceId}", "install", "-r", $"\"{apkPath}\"").Run().ExitCode != 0)
                {
                    Debug.LogError(
                        $"Failed to install the apk on the {deviceLaunchConfig.PrettyDeviceType}. " +
                        $"If the application is already installed on your {deviceLaunchConfig.PrettyDeviceType}, " +
                        "try uninstalling it before launching the mobile client.");
                    return;
                }

                EditorUtility.DisplayProgressBar("Launching Mobile Client", "Launching Client", 0.9f);

                // Get GDK-related mobile launch arguments
                var arguments = mobileLaunchConfig.ToLaunchArgs();

                // Get bundle identifier
                var bundleId = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.Android);

                // Launch the bundle on chosen device
                // Use -S force stops target app before launching again
                // adb -s <device id>
                //    shell am start -S -n <unity package path> -e arguments <mobile launch arguments>
                RedirectedProcess.Command(adbPath)
                .WithArgs($"-s {deviceLaunchConfig.DeviceId}", "shell", "am", "start", "-S",
                          "-n", $"{bundleId}/com.unity3d.player.UnityPlayerActivity",
                          "-e", "\"arguments\"", $"\\\"{arguments}\\\"")
                .InDirectory(Path.GetFullPath(Path.Combine(Application.dataPath, "..")))
                .Run();

                EditorUtility.DisplayProgressBar("Launching Mobile Client", "Done", 1.0f);
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
        }
Beispiel #4
0
 public void Launch(MobileLaunchConfig mobileLaunchConfig) => launchAction(this, mobileLaunchConfig);