(
apktoolYmlPath: string,
apktoolArgs: string[],
)
| 97 | * @param apktoolArgs array of additional args passed to **Apktool** |
| 98 | */ |
| 99 | export async function rebuildAPK( |
| 100 | apktoolYmlPath: string, |
| 101 | apktoolArgs: string[], |
| 102 | ): Promise<void> { |
| 103 | if (!apktoolYmlPath || !fs.existsSync(apktoolYmlPath)) { |
| 104 | vscode.window.showErrorMessage( |
| 105 | `APKLab: apktool.yml file not found: ${apktoolYmlPath}`, |
| 106 | ); |
| 107 | return; |
| 108 | } |
| 109 | |
| 110 | const extensionConfig = |
| 111 | vscode.workspace.getConfiguration(extensionConfigName); |
| 112 | const apktoolPath = extensionConfig.get("apktoolPath"); |
| 113 | |
| 114 | if (!apktoolPath || !fs.existsSync(String(apktoolPath))) { |
| 115 | vscode.window.showErrorMessage( |
| 116 | "APKLab: Apktool not found. Please check your configuration.", |
| 117 | ); |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | const apkFileName = getApkNameFromApkToolYaml(apktoolYmlPath); |
| 122 | if (!apkFileName) { |
| 123 | vscode.window.showErrorMessage( |
| 124 | "APKLab: Could not determine APK filename from apktool.yml", |
| 125 | ); |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | const projectDir = path.parse(apktoolYmlPath).dir; |
| 130 | const report = `Rebuilding ${apkFileName} into ${path.basename( |
| 131 | projectDir, |
| 132 | )}${path.sep}dist`; |
| 133 | let args = ["-jar", String(apktoolPath), "b", projectDir]; |
| 134 | if (apktoolArgs && apktoolArgs.length > 0) { |
| 135 | args = args.concat(apktoolArgs); |
| 136 | } |
| 137 | const outputApkFilePath = path.join(projectDir, DIST_DIR, apkFileName); |
| 138 | let canBeSigned = false; |
| 139 | await executeProcess({ |
| 140 | name: "Rebuilding", |
| 141 | report: report, |
| 142 | command: getJavaPath(), |
| 143 | args: args, |
| 144 | shouldExist: outputApkFilePath, |
| 145 | onSuccess: () => { |
| 146 | canBeSigned = true; |
| 147 | }, |
| 148 | }); |
| 149 | if (canBeSigned) await apkSigner.signAPK(outputApkFilePath); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Empty the **ApkTool** resource framework dir. |
nothing calls this directly
no test coverage detected