private static string FindIOSDeploy()
        {
            var shellArgs = new ShellProcessArguments
            {
                Executable = "ls",
                Arguments  = new[]
                {
                    iOSDeployFolder
                },
                ThrowOnError = false
            };
            var output = ShellProcess.Run(shellArgs);

            var versionStr = "0.0.0";

            if (output.ExitCode == 0)
            {
                var versions = output.FullOutput.Split('\n');
                foreach (var v in versions)
                {
                    if (v.Length > 0 && (new System.Version(v)).CompareTo(new System.Version(versionStr)) > 0)
                    {
                        versionStr = v;
                    }
                }
            }
            if (versionStr == "0.0.0")
            {
                throw new Exception($"iOS deploy is required in order to install and launch the app, to install it simply run \"brew install ios-deploy\"");
            }
            return($"{iOSDeployFolder}/{versionStr}/bin/ios-deploy");
        }
        internal override ShellProcessOutput RunTestMode(string exeName, string workingDirPath, int timeout)
        {
            var app = $"{workingDirPath}/{exeName}{ExecutableExtension}";

            if (!Directory.Exists(app))
            {
                throw new Exception($"Couldn't find iOS app at: {app} ");
            }
            using (var progress = new BuildProgress("Running the iOS app", "Please wait..."))
            {
                var shellArgs = new ShellProcessArguments
                {
                    Executable = FindIOSDeploy(),
                    Arguments  = new[]
                    {
                        "--noninteractive",
                        "--debug",
                        "--uninstall",
                        "--bundle",
                        app
                    },
                    WorkingDirectory = new DirectoryInfo(workingDirPath)
                };
                if (timeout > 0)
                {
                    shellArgs.MaxIdleTimeInMilliseconds = timeout;
                    shellArgs.MaxIdleKillIsAnError      = false;
                }

                return(ShellProcess.Run(shellArgs));
            }
        }
示例#3
0
 private ShellProcessOutput InstallApk(string apkName, string buildDir)
 {
     return(ShellProcess.Run(new ShellProcessArguments()
     {
         ThrowOnError = false,
         Executable = AdbPath,
         Arguments = new string[] { "install", "\"" + apkName + "\"" },
         WorkingDirectory = new DirectoryInfo(buildDir)
     }));
 }
示例#4
0
        public static ShellProcess RunShellProcess(ShellProcess shProcess)
        {
            if (LOGGER.IsDebugEnabled)
            {
                LOGGER.DebugFormat("Running Command: {0} {1}",
                    shProcess.ProcStartInfo.FileName,
                    shProcess.ProcStartInfo.Arguments);
            }

            shProcess.Run();
            return shProcess;
        }
示例#5
0
        internal static ShellProcessOutput RunTestMode(ShellProcessArguments shellArgs, string workingDirPath, int timeout)
        {
            shellArgs.WorkingDirectory = new DirectoryInfo(workingDirPath);
            shellArgs.ThrowOnError     = false;

            // samples should be killed on timeout
            if (timeout > 0)
            {
                shellArgs.MaxIdleTimeInMilliseconds = timeout;
                shellArgs.MaxIdleKillIsAnError      = false;
            }

            return(ShellProcess.Run(shellArgs));
        }
示例#6
0
 private ShellProcessOutput LaunchApp(string buildDir)
 {
     return(ShellProcess.Run(new ShellProcessArguments()
     {
         ThrowOnError = false,
         Executable = AdbPath,
         Arguments = new string[] {
             "shell", "am", "start",
             "-a", "android.intent.action.MAIN",
             "-c", "android.intent.category.LAUNCHER",
             "-f", "0x10200000",
             "-S",
             "-n", $"{PackageName}/com.unity3d.tinyplayer.UnityTinyActivity"
         },
         WorkingDirectory = new DirectoryInfo(buildDir)
     }));
 }
示例#7
0
        public override bool Run(FileInfo buildTarget)
        {
            var buildDir = buildTarget.Directory.FullName;

            var result = UninstallApp(buildTarget.FullName, buildDir);

            if (ExportSettings?.TargetType == AndroidTargetType.AndroidAppBundle)
            {
                result = BuildApks(buildTarget.FullName, buildDir);
                // bundletool might write to stderr even if there are no errors
                if (result.ExitCode != 0)
                {
                    throw new Exception($"Cannot build APKS : {result.FullOutput}");
                }
                result = InstallApks(buildDir);
                if (result.ExitCode != 0)
                {
                    throw new Exception($"Cannot install APKS : {result.FullOutput}");
                }
            }
            else
            {
                result = InstallApk(buildTarget.FullName, buildDir);
                if (!result.FullOutput.Contains("Success"))
                {
                    throw new Exception($"Cannot install APK : {result.FullOutput}");
                }
            }
            result = LaunchApp(buildDir);
            // killing adb to unlock build folder
            ShellProcess.Run(new ShellProcessArguments()
            {
                ThrowOnError = false,
                Executable   = AdbPath,
                Arguments    = new string[] { "kill-server" }
            });
            if (result.Succeeded)
            {
                return(true);
            }
            else
            {
                throw new Exception($"Cannot launch APK : {result.FullOutput}");
            }
        }
示例#8
0
        private ShellProcessOutput InstallApks(string buildDir)
        {
            var apksName = GetApksName(buildDir);

            return(ShellProcess.Run(new ShellProcessArguments()
            {
                ThrowOnError = false,
                Executable = JavaPath,
                Arguments = new string[] {
                    "-jar",
                    $"\"{BundleToolJar}\"",
                    "install-apks",
                    $"--apks=\"{apksName}\"",
                    $"--adb=\"{AdbPath}\""
                },
                WorkingDirectory = new DirectoryInfo(buildDir)
            }));
        }
示例#9
0
        private ShellProcessOutput BuildApks(string aabName, string buildDir)
        {
            var apksName = GetApksName(buildDir);
            //TODO check for mutliple device installing

            string keystorePassFile = null;
            string keyaliasPassFile = null;

            if (UseKeystore)
            {
                keystorePassFile = Path.Combine(buildDir, "keystore.pass");
                keyaliasPassFile = Path.Combine(buildDir, "keyalias.pass");
                File.WriteAllText(keystorePassFile, Keystore.KeystorePass);
                File.WriteAllText(keyaliasPassFile, Keystore.KeyaliasPass);
            }
            var result = ShellProcess.Run(new ShellProcessArguments()
            {
                ThrowOnError = false,
                Executable   = JavaPath,
                Arguments    = new string[] {
                    "-jar",
                    $"\"{BundleToolJar}\"",
                    "build-apks",
                    $"--bundle=\"{aabName}\"",
                    $"--output=\"{apksName}\"",
                    "--overwrite",
                    (UseKeystore ? $"--ks=\"{Keystore.KeystoreFullPath}\" --ks-pass=file:\"{keystorePassFile}\" --ks-key-alias=\"{Keystore.KeyaliasName}\" --key-pass=file:\"{keyaliasPassFile}\"" : "")
                },
                WorkingDirectory = new DirectoryInfo(buildDir)
            });

            if (UseKeystore)
            {
                File.Delete(keystorePassFile);
                File.Delete(keyaliasPassFile);
            }
            return(result);
        }
示例#10
0
        private ShellProcessOutput UninstallApp(string apkName, string buildDir)
        {
            // checking that app is already installed
            var result = ShellProcess.Run(new ShellProcessArguments()
            {
                ThrowOnError     = false,
                Executable       = AdbPath,
                Arguments        = new string[] { "shell", "pm", "list", "packages", PackageName },
                WorkingDirectory = new DirectoryInfo(buildDir)
            });

            if (result.FullOutput.Contains(PackageName))
            {
                // uninstall previous version, it may be signed with different key, so re-installing is not possible
                result = ShellProcess.Run(new ShellProcessArguments()
                {
                    ThrowOnError     = false,
                    Executable       = AdbPath,
                    Arguments        = new string[] { "uninstall", PackageName },
                    WorkingDirectory = new DirectoryInfo(buildDir)
                });
            }
            return(result);
        }
示例#11
0
        internal override ShellProcessOutput RunTestMode(string exeName, string workingDirPath, int timeout)
        {
            var executable = $"{workingDirPath}/{exeName}{ExecutableExtension}";
            var output     = UninstallApp(executable, workingDirPath);

            if (ExportSettings?.TargetType == AndroidTargetType.AndroidAppBundle)
            {
                output = BuildApks(executable, workingDirPath);
                // bundletool might write to stderr even if there are no errors
                if (output.ExitCode != 0)
                {
                    return(output);
                }
                output = InstallApks(workingDirPath);
                if (output.ExitCode != 0)
                {
                    return(output);
                }
            }
            else
            {
                output = InstallApk(executable, workingDirPath);
                if (!output.FullOutput.Contains("Success"))
                {
                    return(output);
                }
            }

            // clear logcat
            ShellProcess.Run(new ShellProcessArguments()
            {
                ThrowOnError = false,
                Executable   = AdbPath,
                Arguments    = new string[] {
                    "logcat", "-c"
                },
                WorkingDirectory = new DirectoryInfo(workingDirPath)
            });

            output = LaunchApp(workingDirPath);

            System.Threading.Thread.Sleep(timeout == 0 ? 2000 : timeout); // to kill process anyway,
                                                                          // should be rewritten to support tests which quits after execution

            // killing on timeout
            ShellProcess.Run(new ShellProcessArguments()
            {
                ThrowOnError = false,
                Executable   = AdbPath,
                Arguments    = new string[] {
                    "shell", "am", "force-stop",
                    PackageName
                },
                WorkingDirectory = new DirectoryInfo(workingDirPath)
            });

            // get logcat
            output = ShellProcess.Run(new ShellProcessArguments()
            {
                ThrowOnError = false,
                Executable   = AdbPath,
                Arguments    = new string[] {
                    "logcat", "-d"
                },
                WorkingDirectory = new DirectoryInfo(workingDirPath)
            });
            if (timeout == 0) // non-sample test, TODO invent something better
            {
                output.Succeeded = output.FullOutput.Contains("Test suite: SUCCESS");
            }
            return(output);
        }