예제 #1
0
            public void Repackage()
            {
                try
                {
                    for (int i = 0; i < channelList.Count; i++)
                    {
                        ChannelInfo channelInfo = channelList[i];

                        if (string.IsNullOrEmpty(EditorData.AndroidSdkPath))
                        {
                            throw new Exception("AndroidSdkPath 不能为空!");
                        }

                        if (string.IsNullOrEmpty(EditorData.SdkLibPath))
                        {
                            throw new Exception("SdkLibPath 不能为空!");
                        }

                        if (string.IsNullOrEmpty(EditorData.BuildToolVersion))
                        {
                            throw new Exception("BuildToolVersion 不能为空!");
                        }

                        if (string.IsNullOrEmpty(channelInfo.keyStorePath))
                        {
                            throw new Exception("keyStore 不能为空!");
                        }

                        if (string.IsNullOrEmpty(channelInfo.KeyStorePassWord))
                        {
                            throw new Exception("KeyStore PassWord 不能为空!");
                        }

                        if (string.IsNullOrEmpty(channelInfo.KeyStoreAlias))
                        {
                            throw new Exception("Alias 不能为空!");
                        }

                        if (string.IsNullOrEmpty(channelInfo.KeyStoreAliasPassWord))
                        {
                            throw new Exception("Alias PassWord 不能为空!");
                        }

                        string fileName  = FileTool.GetFileNameByPath(repackageInfo.apkPath);
                        string aimPath   = outPath + "\\" + FileTool.RemoveExpandName(fileName);
                        string apkPath   = aimPath + "\\dist\\" + fileName;
                        string finalPath = repackageInfo.exportPath + "\\" + FileTool.RemoveExpandName(fileName) + ".apk";

                        if (!string.IsNullOrEmpty(channelInfo.suffix))
                        {
                            finalPath = repackageInfo.exportPath + "\\" + FileTool.RemoveExpandName(fileName) + "_" + channelInfo.suffix + ".apk";
                        }

                        CmdService  cmd         = new CmdService(OutPutCallBack, ErrorCallBack);
                        ChannelTool channelTool = new ChannelTool(OutPutCallBack, ErrorCallBack);

                        string apktool_version = "apktool";

                        //反编译APK
                        MakeProgress("反编译APK ", i, channelList.Count, channelInfo.Name);
                        cmd.Execute("java -jar " + apktool_version + ".jar d -f " + repackageInfo.apkPath + " -o " + aimPath);

                        //执行对应的文件操作
                        MakeProgress("执行对应的文件操作", i, channelList.Count, channelInfo.Name);
                        channelTool.ChannelLogic(aimPath, channelInfo);

                        //移除过长的YML
                        MakeProgress("移除过长的YML", i, channelList.Count, channelInfo.Name);
                        channelTool.YMLLogic(aimPath);

                        //分包
                        MakeProgress("分包", i, channelList.Count, channelInfo.Name);
                        channelTool.SplitDex(aimPath);

                        ////混淆DLL
                        //MakeProgress("混淆DLL", i, channelList.Count, channelInfo.Name);
                        //channelTool.ConfusionDLL(aimPath);

                        //重新生成R表
                        MakeProgress("重新生成R表", i, channelList.Count, channelInfo.Name);
                        channelTool.Rebuild_R_Table(aimPath);

                        //重打包
                        MakeProgress("重打包", i, channelList.Count, channelInfo.Name);
                        cmd.Execute("java -jar " + apktool_version + ".jar b " + aimPath, true, true);

                        //进行签名
                        MakeProgress("进行签名", i, channelList.Count, channelInfo.Name);
                        cmd.Execute("jarsigner" // -verbose
                                                //+ " -tsa https://timestamp.geotrust.com/tsa"
                                    + " -digestalg SHA1 -sigalg MD5withRSA"
                                    + " -storepass " + channelInfo.KeyStorePassWord
                                    + " -keystore " + channelInfo.KeyStorePath
                                    + " -sigFile CERT" //强制将RSA文件更名为CERT
                                    + " " + apkPath
                                    + " " + channelInfo.KeyStoreAlias
                                    );

                        //进行字节对齐并导出到最终目录
                        MakeProgress("进行字节对齐并导出到最终目录", i, channelList.Count, channelInfo.Name);
                        cmd.Execute(EditorData.GetZipalignPath() + " -f  4 " + apkPath + " " + finalPath);

                        if (EditorData.IsAutoInstall)
                        {
                            //自动安装
                            MakeProgress("自动安装", i, channelList.Count, channelInfo.Name);
                            cmd.Execute("adb install -r " + finalPath, true, true);
                        }

                        if (channelInfo.IsDeleteTempPath)
                        {
                            //删除临时目录
                            MakeProgress("删除临时目录", i, channelList.Count, channelInfo.Name);
                            FileTool.SafeDeleteDirectory(aimPath);
                        }
                        else
                        {
                            //删除临时目录
                            MakeProgress("跳过删除临时目录", i, channelList.Count, channelInfo.Name);
                        }


                        MakeProgress("完成", i, channelList.Count, channelInfo.Name);
                    }
                }
                catch (Exception e)
                {
                    ErrorCallBack(e.ToString());
                }
            }
            public void Repackage()
            {
                try
                {
                    for (int i = 0; i < channelList.Count; i++)
                    {
                        ChannelInfo channelInfo = channelList[i];

                        if (string.IsNullOrEmpty(channelInfo.keyStorePath))
                        {
                            throw new Exception("keyStore 不能为空!");
                        }

                        if (string.IsNullOrEmpty(channelInfo.KeyStorePassWord))
                        {
                            throw new Exception("KeyStore PassWord 不能为空!");
                        }

                        if (string.IsNullOrEmpty(channelInfo.KeyStoreAlias))
                        {
                            throw new Exception("Alias 不能为空!");
                        }

                        if (string.IsNullOrEmpty(channelInfo.KeyStoreAliasPassWord))
                        {
                            throw new Exception("Alias PassWord 不能为空!");
                        }

                        string fileName  = FileTool.GetFileNameByPath(repackageInfo.apkPath);
                        string aimPath   = outPath + "\\" + FileTool.RemoveExpandName(fileName);
                        string apkPath   = aimPath + "\\dist\\" + fileName;
                        string finalPath = repackageInfo.exportPath + "\\" + FileTool.RemoveExpandName(fileName) + ".apk";

                        if (!string.IsNullOrEmpty(channelInfo.suffix))
                        {
                            finalPath = repackageInfo.exportPath + "\\" + FileTool.RemoveExpandName(fileName) + "_" + channelInfo.suffix + ".apk";
                        }

                        CmdService  cmd         = new CmdService(OutPutCallBack, ErrorCallBack);
                        ChannelTool channelTool = new ChannelTool(OutPutCallBack, ErrorCallBack);

                        string apktool_version = "apktool";

                        //MakeProgress("移除过长的YML", i, channelList.Count, channelInfo.Name);
                        //channelTool.YMLLogic(aimPath);

                        //反编译APK
                        MakeProgress("反编译APK ", i, channelList.Count, channelInfo.Name);
                        cmd.Execute("java -jar " + apktool_version + ".jar d -f " + repackageInfo.apkPath + " -o " + aimPath);

                        //执行对应的文件操作
                        MakeProgress("执行对应的文件操作", i, channelList.Count, channelInfo.Name);
                        channelTool.ChannelLogic(aimPath, channelInfo);

                        //移除过长的YML
                        MakeProgress("移除过长的YML", i, channelList.Count, channelInfo.Name);
                        channelTool.YMLLogic(aimPath);

                        ////混淆DLL
                        //MakeProgress("混淆DLL", i, channelList.Count, channelInfo.Name);
                        //channelTool.ConfusionDLL(aimPath);

                        //重打包
                        MakeProgress("重打包", i, channelList.Count, channelInfo.Name);
                        cmd.Execute("java -jar " + apktool_version + ".jar b " + aimPath);

                        //进行签名
                        MakeProgress("进行签名", i, channelList.Count, channelInfo.Name);
                        cmd.Execute("jarsigner" // -verbose
                                                //+ " -tsa https://timestamp.geotrust.com/tsa"
                                    + " -digestalg SHA1 -sigalg MD5withRSA"
                                    + " -storepass " + channelInfo.KeyStorePassWord
                                    + " -keystore " + channelInfo.KeyStorePath
                                    + " " + apkPath
                                    + " " + channelInfo.KeyStoreAlias
                                    );

                        //进行字节对齐并导出到最终目录
                        MakeProgress("进行字节对齐并导出到最终目录", i, channelList.Count, channelInfo.Name);
                        cmd.Execute("zipalign -f  4 " + apkPath + " " + finalPath);

                        //删除临时目录
                        MakeProgress("删除临时目录", i, channelList.Count, channelInfo.Name);

                        FileTool.SafeDeleteDirectory(aimPath);
                        Directory.Delete(aimPath);

                        MakeProgress("完成", i, channelList.Count, channelInfo.Name);
                    }
                }
                catch (Exception e)
                {
                    ErrorCallBack(e.ToString());
                }
            }