private async void TxtPath_TextChanged(object sender, TextChangedEventArgs e) { if (!(sender is TextBox tb)) { return; } txtLabel.Text = ". . . ."; txtLabel.ToolTip = null; txtPackage.Text = ". . . ."; txtPackage.ToolTip = null; txtVersion.Text = ". . . ."; txtVersion.ToolTip = null; txtAbi.Text = ". . . ."; txtAbi.ToolTip = null; txtSdk.Text = ". . . ."; imgIcon.Source = App.GetPlaystoreImageFromResources(); gbAction.IsEnabled = false; if (string.IsNullOrWhiteSpace(tb.Text)) { return; } if (loadedApk == null || loadedApk.FilePath != tb.Text) { ShowLoading(); var aapt = await Aapt.DumbBadging(tb.Text); if (aapt.Success) { loadedApk = aapt.Apk; txtLabel.Text = loadedApk.Label; txtLabel.ToolTip = txtLabel.Text; txtPackage.Text = loadedApk.PackageName; txtPackage.ToolTip = txtPackage.Text; txtVersion.Text = string.Format("{0} ( {1} )", loadedApk.VersionName, loadedApk.VersionCode); txtVersion.ToolTip = txtVersion.Text; txtAbi.Text = loadedApk.AbiList; txtAbi.ToolTip = txtAbi.Text; txtSdk.Text = loadedApk.SdkVersion.ToString(); imgIcon.Source = loadedApk.Icon; gbAction.IsEnabled = true; } // file corrupt or error else { txtLabel.Text = "file corrupt?"; txtPackage.Text = "not an apk file? unusual file path?"; } ShowLoading(false); } }
public void parseApk() { Aapt.DecodeApk(apkPath, mTempFolder); mDeApkStruct = new DecodedApkStruct(mTempFolder).parseAxml(); end(mDeApkStruct != null? true:false); }
public override void BuildUnsignedApk(string channel) { Aapt.EditorAXML(COPY_AXML, WORK_SPACE, channel); string output = Path.Combine(WORK_SPACE, string.Format("axml_{0}.xml", channel)); File.Copy(output, ORIGIN_AXML, true); Aapt.ZipApk(ORIGIN_APK, GetUnsignedApk()); }
public override void BuildUnsignedApk() { string tempFolder = GetTempFolder(); if (!Directory.Exists(tempFolder)) { throw new Exception(string.Format("Can't find decoded folder at {0}", tempFolder)); } Aapt.BuildApk(tempFolder, GetUnsignedApk()); }
public override void SetProjectEnvironmet() { DirectoryInfo di = new DirectoryInfo(WORK_SPACE); if (di.Exists) { di.Delete(true); } Aapt.UpzipApk(mPathToApk, ORIGIN_APK); File.Copy(ORIGIN_AXML, COPY_AXML, true); }
public void ZipAlign(string channel) { string unzipAlignedApk = GetUnzipAlignedApk(); string finalApk = GetFinalApk(channel); if (!File.Exists(unzipAlignedApk)) { throw new Exception(string.Format("签名错误,没有生成中间文件:{0}", unzipAlignedApk)); } if (File.Exists(finalApk)) { File.Delete(finalApk); } Aapt.ZipAlign(unzipAlignedApk, finalApk); }
/// <summary> /// cmd: ApkSigner keystore storepw alias password input output /// </summary> /// <param name="channel"></param> public void SignAPK(string channel) { string unSignedApk = GetUnsignedApk(); string unzipAlignedApk = GetUnzipAlignedApk(); if (!File.Exists(unSignedApk)) { throw new Exception(string.Format("打包错误,没有生成中间文件:{1}", unSignedApk)); } if (File.Exists(unzipAlignedApk)) { File.Delete(unzipAlignedApk); } Aapt.SignAPK(Config.KeystoreFilePath, Config.KeystorePassword, Config.Alias, Config.AliasPassword, unSignedApk, unzipAlignedApk); }
public override void BuildUnsignedApk(string channel) { Aapt.EditorAXML(COPY_AXML, WORK_SPACE, channel); string output = Path.Combine(WORK_SPACE, string.Format("axml_{0}.xml", channel)); //rename *.xml to AndroidManifest.xml File.Delete(CANDINATE_AXML); File.Move(output, CANDINATE_AXML); //copy copy.apk to copy1.apk File.Copy(CANDINATE_APK, CANDINATE_APK1, true); //aapt r copy1.apk AndroidManifest.xml removeAXML(CANDINATE_APK1); //aapt a copy1.apk AndroidManifest.xml addAXML(CANDINATE_APK1); //copy copy1.apk to unsigned apk File.Copy(CANDINATE_APK1, GetUnsignedApk(), true); }
public bool AddDexClasses() { bool isEverProcessed = false; foreach (var dexFile in Directory.GetFiles(ApkDirectory, "*.dex")) { File.Delete(dexFile); } if (Directory.GetFiles(ApkContentPath, "*_x.dex").Length > 0) // Not cleaned up { foreach (var dexFile in Directory.GetFiles(ApkContentPath, "*_x.dex")) { File.Copy(dexFile, Path.Combine(ApkDirectory, Path.GetFileName(dexFile).Replace("_x.dex", ".dex"))); } } else // Cleaned up { foreach (var dexFile in Directory.GetFiles(ApkContentPath, "*.dex")) { File.Copy(dexFile, Path.Combine(ApkDirectory, Path.GetFileName(dexFile))); } } foreach (var dexFile in Directory.GetFiles(ApkDirectory, "*.dex")) { Aapt.Remove(Path.GetFileName(ApkPath), Path.GetFileName(dexFile), ApkDirectory); Aapt.Add(Path.GetFileName(ApkPath), Path.GetFileName(dexFile), ApkDirectory); ConsoleWrapper.WriteInfo("AAPT", true, $"Readd DEX file {Path.GetFileName(dexFile)}"); isEverProcessed = true; File.Delete(dexFile); } return(isEverProcessed); }
public void CompareAaptAndManagedParserOutputWithCustomIds() { var path = Path.Combine("temp", TestName); CreateResourceDirectory(path); File.WriteAllText(Path.Combine(Root, path, "res", "layout", "custom.xml"), CustomId); File.WriteAllText(Path.Combine(Root, path, "foo.map"), @"a\nb"); Directory.CreateDirectory(Path.Combine(Root, path, "java")); string resPath = Path.Combine(Root, path, "res"); int platform = 0; using (var b = new Builder()) { platform = b.GetMaxInstalledPlatform(); } IBuildEngine engine = new MockBuildEngine(TestContext.Out); var aapt = new Aapt() { BuildEngine = engine, ToolPath = GetPathToAapt(), ResourceDirectory = resPath, ManifestFiles = new ITaskItem [] { new TaskItem(Path.Combine(Root, path, "AndroidManifest.xml")) }, ResourceOutputFile = Path.Combine(Root, path, "foo.apk"), AssemblyIdentityMapFile = Path.Combine(Root, path, "foo.map"), JavaPlatformJarPath = Path.Combine(AndroidSdkDirectory, "platforms", $"android-{platform}", "android.jar"), JavaDesignerOutputDirectory = Path.Combine(Root, path, "java"), ResourceSymbolsTextFileDirectory = Path.Combine(Root, path), AdditionalResourceDirectories = new ITaskItem [] { new TaskItem(Path.Combine(Root, path, "lp", "res")) }, AndroidUseLatestPlatformSdk = true, ApiLevel = $"{platform}", }; Assert.IsTrue(aapt.Execute(), "Aapt should have succeeded."); string rTxt = Path.Combine(Root, path, "R.txt"); FileAssert.Exists(rTxt, $"{rTxt} should have been created."); var task = new GenerateResourceDesigner { BuildEngine = engine }; task.UseManagedResourceGenerator = true; task.DesignTimeBuild = false; task.Namespace = "MonoAndroidApplication4.MonoAndroidApplication4"; task.NetResgenOutputFile = Path.Combine(Root, path, "Resource.designer.aapt.cs"); task.ProjectDir = Path.Combine(Root, path); task.ResourceDirectory = Path.Combine(Root, path, "res") + Path.DirectorySeparatorChar; task.Resources = new TaskItem [] { new TaskItem(Path.Combine(Root, path, "res", "values", "strings.xml"), new Dictionary <string, string> () { { "LogicalName", "values\\strings.xml" }, }), }; task.AdditionalResourceDirectories = new TaskItem [] { new TaskItem(Path.Combine(Root, path, "lp", "res")), }; task.ResourceFlagFile = Path.Combine(Root, path, "AndroidResgen.flag"); task.IsApplication = true; task.JavaPlatformJarPath = aapt.JavaPlatformJarPath; Assert.IsTrue(task.Execute(), "Task should have executed successfully."); string aaptDesigner = Path.Combine(Root, path, "Resource.designer.aapt.cs"); var aaptDesignerText = File.ReadAllText(aaptDesigner); StringAssert.Contains("MyCustomID", aaptDesignerText, ""); StringAssert.Contains("HelloWorldTextView", aaptDesignerText, ""); StringAssert.Contains("ACustomID", aaptDesignerText, ""); StringAssert.Contains("foo1", aaptDesignerText, ""); task.UseManagedResourceGenerator = true; task.DesignTimeBuild = true; task.NetResgenOutputFile = Path.Combine(Root, path, "Resource.designer.managedrtxt.cs"); Assert.IsTrue(task.Execute(), "Task should have executed successfully."); string managedDesignerRtxt = Path.Combine(Root, path, "Resource.designer.managedrtxt.cs"); CompareFilesIgnoreRuntimeInfoString(managedDesignerRtxt, aaptDesigner); File.WriteAllText(task.ResourceFlagFile, string.Empty); File.Delete(Path.Combine(Root, path, "R.txt.bak")); File.Move(rTxt, Path.Combine(Root, path, "R.txt.bak")); task.UseManagedResourceGenerator = true; task.DesignTimeBuild = true; task.NetResgenOutputFile = Path.Combine(Root, path, "Resource.designer.managed.cs"); Assert.IsTrue(task.Execute(), "Task should have executed successfully."); string managedDesigner = Path.Combine(Root, path, "Resource.designer.managed.cs"); var managedDesignerText = File.ReadAllText(managedDesigner); StringAssert.Contains("MyCustomID", managedDesignerText, ""); StringAssert.Contains("HelloWorldTextView", managedDesignerText, ""); StringAssert.Contains("ACustomID", managedDesignerText, ""); StringAssert.Contains("foo1", managedDesignerText, ""); Directory.Delete(Path.Combine(Root, path), recursive: true); }
private bool CheckInput() { //keystore if (string.IsNullOrEmpty(KeystoreFilePath)) { throw new Exception("没有设置 keystore"); } //keystore pw if (string.IsNullOrEmpty(KeyStorePw)) { throw new Exception("没有设置 keystore password"); } //alias if (string.IsNullOrEmpty(Alias)) { throw new Exception("没有设置 keystore entry (alias)"); } //entry pw if (string.IsNullOrEmpty(AliasPw)) { throw new Exception("没有设置 keystore entry password"); } int resultCode = Aapt.checkStoreAndAlias(KeystoreFilePath, KeyStorePw, Alias, AliasPw); switch (resultCode) { case 1: throw new Exception("Keystore Password 不正确"); case 2: throw new Exception("Alias 不正确"); case 3: throw new Exception("Alias Password 不正确"); case 0: default: break; } //channel if (Candinate == null || Candinate.Count == 0) { throw new Exception("没有设置 渠道 "); } //uncommit channel if (Candinate.Count == 1 && (Candinate[0] as EditItem).State == EditState.Editable) { throw new Exception("请编辑渠道(回车输入)"); } //setting file name if (string.IsNullOrEmpty(SettingFile)) { throw new Exception("亲,起个名呗 ^_^ "); } return(true); }
public static void Build(string dstApk) { Aapt.BuildApk(TEMP, dstApk); }
public static DecodedApkStruct Decode(string apk) { Aapt.DecodeApkWithSource(apk, TEMP); return(new DecodedApkStruct(TEMP).parseAxml()); }
public ApkFile() { this.fileInfo = OpenFile(); this.aaptDump = Aapt.Dump(this.fileInfo); this.iconPath = TempPath + @"\" + this.aaptDump.application.icon.Replace('/', '\\'); }