Ejemplo n.º 1
0
 private void ShowAndroidManifest(AndroidManifest am)
 {
     if (owner.InvokeRequired)
     {
         owner.Invoke(showAndroidManifest, am);
     }
     else
     {
         showAndroidManifest(am);
     }
 }
Ejemplo n.º 2
0
            private void DoPack(string baseName, string sourDir, AndroidManifest am, string channel, string destFilename)
            {
                OnProgress("准备打包:" + channel);
                string buildDir = Utils.MakeFilename(sourDir, "build");

                if (Directory.Exists(buildDir))
                {
                    Directory.Delete(buildDir, true);
                }
                am.Channel = channel;
                am.Save();
                ProcessInvoker.Execute(this, ProcessInvoker.BuildExeFullPath("java.exe"),
                                       String.Format("-jar tools\\apktool.jar b -f -o {0} {1}", destFilename, sourDir), true);
                OnProgress("打包完成");
            }
Ejemplo n.º 3
0
            private AndroidManifest DoUnpack(string apkName, string outputDir)
            {
                if (Directory.Exists(outputDir))
                {
                    OnProgress("删除临时目录……");
                    Directory.Delete(outputDir, true);
                }

                OnProgress("准备对APK进行解包……");
                ProcessInvoker.Execute(this, ProcessInvoker.BuildExeFullPath("java.exe"),
                                       String.Format("-jar tools\\apktool.jar d -f -s -o {0} {1}", outputDir, apkName), true);
                OnProgress("解包完成!");
                //
                OnProgress("解析AndroidManifest.xml……");
                AndroidManifest am = new AndroidManifest(outputDir);

                return(am);
            }
Ejemplo n.º 4
0
 private void ShowAndroidManifest(AndroidManifest am)
 {
     labelApkName.Text = string.Format("{0}\r\n{1}\r\nVersion Code: {2}\r\nVersion Name: {3}",
                                       am.AppLabel, am.PackageName,
                                       am.VersionCode, am.VersionName);
 }
Ejemplo n.º 5
0
            private void worker_DoWork(object sender, DoWorkEventArgs e)
            {
                string           srcBaseFileName = Path.GetFileNameWithoutExtension(owner.ApkFilename);
                FileNameElements elements        = FileNameElements.Parse(srcBaseFileName);

                if (elements == null)
                {
                    throw new Exception("原始文件名格式无效,无法解析。\r\nExpected: prefix-verName-verCode-time-channel-commitId.apk");
                }

                string outputDir = string.Format(@"output\{0}-{1}-{2}-{3}-{4}",
                                                 elements.Prefix, elements.VersionName, elements.VersionCode, elements.BuildTime, elements.CommitId);
                string workDir = "temp";

                AndroidManifest am = DoUnpack(owner.ApkFilename, workDir);

                ShowAndroidManifest(am);
                if (am.VersionCode != elements.VersionCode)
                {
                    throw new Exception("原始文件名中VersionCode与解包后实际值不符");
                }
                if (am.VersionName != elements.VersionName)
                {
                    throw new Exception("原始文件名中VersionName与解包后实际值不符");
                }
                if (am.Channel != elements.Channel)
                {
                    throw new Exception("原始文件名中渠道名称与解包后实际值不符");
                }

                //
                if (Directory.Exists(outputDir))
                {
                    Directory.Delete(outputDir, true);
                }
                Directory.CreateDirectory(outputDir);
                //
                for (int i = 0; i < project.Count; ++i)
                {
                    if (worker.CancellationPending)
                    {
                        break;
                    }
                    string channel     = project.GetChannel(i);
                    string newBaseName = elements.BuildWithNewChannel(channel);

                    SetListViewState(i, "打包");
                    string unsignedFilename = Utils.MakeFilename(outputDir, string.Format("{0}-unsigned.apk", newBaseName));
                    DoPack(srcBaseFileName, workDir, am, channel, unsignedFilename);
                    if (worker.CancellationPending)
                    {
                        break;
                    }
                    SetListViewState(i, "签名");
                    string signedFilename = Utils.MakeFilename(outputDir, string.Format("{0}-unaligned.apk", newBaseName));
                    DoSign(project, unsignedFilename, signedFilename);
                    File.Delete(unsignedFilename);
                    if (worker.CancellationPending)
                    {
                        break;
                    }
                    SetListViewState(i, "对齐");
                    string finalFilename = Utils.MakeFilename(outputDir, string.Format("{0}.apk", newBaseName));
                    DoAlign(signedFilename, finalFilename);
                    //
                    SetListViewState(i, "完成");
                }
                e.Cancel = worker.CancellationPending;
                if (!e.Cancel)
                {
                    e.Result = outputDir;
                }
            }