/// <summary> /// Start an instance of the ADB server. /// </summary> public bool StartServer(int timeout) { var runner = new ProcessRunner(Locations.Adb, "start-server") { Logger = Logger }; return (runner.Run(timeout) == 0); }
/// <summary> /// Connect to a networked device. /// </summary> /// <returns>True on success, false otherwise</returns> public bool Connect(string host, string port, int timeout) { if (string.IsNullOrEmpty(host)) throw new ArgumentException("host empty"); var hostArg = host; if (!string.IsNullOrEmpty(port)) hostArg = hostArg + ":" + port; var runner = new ProcessRunner(Locations.Adb, "connect", hostArg) { Logger = Logger, LogCommand = true }; return (runner.Run(timeout) == 0); }
/// <summary> /// Wait for the android device to become ready. /// </summary> /// <returns>True on success, false otherwise</returns> public bool WaitForDevice(string serial, int timeout) { var runner = new ProcessRunner(Locations.Adb, AddSerial(serial, "wait-for-device")) { Logger = Logger }; return (runner.Run(timeout) == 0); }
/// <summary> /// Uninstall the APK from the device. /// Throws an exception when uninstallation fails. /// </summary> public void UninstallApk(string serial, string packageName, int timeout) { var runner = new ProcessRunner(Locations.Adb, AddSerial(serial, "uninstall", packageName)) { Logger = Logger }; var exitCode = runner.Run(timeout); if (exitCode != 0) { throw new AdbException(string.Format("Failed to uninstall because: {0}", runner.Output)); } }
/// <summary> /// Compile the given resources into a suitable output folder. /// </summary> internal bool Compile(List<Tuple<string, ResourceType>> resources, List<string> appWidgetProviderCodeFiles, List<string> references, List<string> referenceFolders, string baseApkPath) { // Remove temp folder if (Directory.Exists(tempFolder)) { Directory.Delete(tempFolder, true); } // Ensure temp\res folder exists var resFolder = Path.Combine(tempFolder, "res"); Directory.CreateDirectory(resFolder); var tempApkPath = Path.Combine(tempFolder, "temp.apk"); // Compile each resource foreach (var resource in resources.Where(x => x.Item2 != ResourceType.Manifest)) { CopyResourceToFolder(tempFolder, resource.Item1, resource.Item2); } // Extract resources out of library project references var resolver = new AssemblyResolver(referenceFolders, null, null); foreach (var path in references) { ExtractLibraryProjectResources(resFolder, path, resolver); } // Select manifest path var manifestPath = resources.Where(x => x.Item2 == ResourceType.Manifest).Select(x => x.Item1).FirstOrDefault(); // Ensure files exists for the appwidgetproviders CreateAppWidgetProviderFiles(tempFolder, manifestPath, appWidgetProviderCodeFiles); // Create system ID's resource CreateSystemIdsResource(tempFolder); // Run aapt var args = new[] { "p", "-f", "-S", resFolder, "-M", GetManifestPath(tempFolder, manifestPath, packageName), "-I", baseApkPath, "-F", tempApkPath }; var runner = new ProcessRunner(Locations.Aapt, args); var exitCode = runner.Run(); if (exitCode != 0) { ProcessAaptErrors(runner.Output, tempFolder, resources); return false; } // Unpack compiled resources to base folder. Table resourceTable = null; using (var apk = new ApkFile(tempApkPath)) { foreach (var name in apk.FileNames) { // Extract var data = apk.Load(name); // Save var path = Path.Combine(baseFolder, name); Directory.CreateDirectory(Path.GetDirectoryName(path)); File.WriteAllBytes(path, data); // Is resource table? yes -> load it if (name == "resources.arsc") { resourceTable = new Table(new MemoryStream(data)); } } } // Create R.cs if (!string.IsNullOrEmpty(generatedCodeFolder)) { var codeBuilder = new CreateResourceIdsCode(resourceTable, resources, valuesResourceProcessor.StyleableDeclarations); codeBuilder.Generate(generatedCodeFolder, packageName, generatedCodeNamespace, generatedCodeLanguage, lastModified); } // Create resource type usage info file if (!string.IsNullOrEmpty(resourceTypeUsageInformationPath)) { // Ensure folder exists var folder = Path.GetDirectoryName(resourceTypeUsageInformationPath); if (!Directory.Exists(folder)) Directory.CreateDirectory(folder); // Create file File.WriteAllLines(resourceTypeUsageInformationPath, layoutProcessor.CustomClassNames); } return true; }