From 703be76d403d30158e1aebe2e6fb19ef8b943f17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Fri, 18 Apr 2025 18:01:36 +0200 Subject: [PATCH 1/2] fix: re-signing android zip --- .../lib/commands/signAndroid/signAndroid.ts | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/packages/platform-android/src/lib/commands/signAndroid/signAndroid.ts b/packages/platform-android/src/lib/commands/signAndroid/signAndroid.ts index be9526d35..37c1bbfae 100644 --- a/packages/platform-android/src/lib/commands/signAndroid/signAndroid.ts +++ b/packages/platform-android/src/lib/commands/signAndroid/signAndroid.ts @@ -11,7 +11,6 @@ import { spawn, spinner, } from '@rnef/tools'; -import AdmZip from 'adm-zip'; import { findAndroidBuildTool, getAndroidBuildToolsPath } from '../../paths.js'; import { buildJsBundle } from './bundle.js'; @@ -65,14 +64,12 @@ export async function signAndroid(options: SignAndroidOptions) { loader.start('Initializing output APK...'); try { - const zip = new AdmZip(options.apkPath); - // Remove old signature files - zip.deleteFile('META-INF/*'); - zip.writeZip(tempApkPath); + fs.mkdirSync(tempPath, { recursive: true }); + fs.copyFileSync(options.apkPath, tempApkPath); } catch (error) { throw new RnefError( `Failed to initialize output APK file: ${options.outputPath}`, - { cause: (error as SubprocessError).stderr } + { cause: error } ); } loader.stop(`Initialized output APK.`); @@ -141,11 +138,24 @@ async function replaceJsBundle({ apkPath, jsBundlePath, }: ReplaceJsBundleOptions) { + const tempPath = path.dirname(apkPath); try { - const zip = new AdmZip(apkPath); - zip.deleteFile('assets/index.android.bundle'); - zip.addLocalFile(jsBundlePath, 'assets', 'index.android.bundle'); - zip.writeZip(apkPath); + fs.mkdirSync(path.join(tempPath, 'assets'), { recursive: true }); + + const tempBundlePath = path.join( + tempPath, + 'assets', + 'index.android.bundle' + ); + fs.copyFileSync(jsBundlePath, tempBundlePath); + + // Delete the existing bundle + await spawn('zip', ['-d', apkPath, 'assets/index.android.bundle']); + + // Add the new bundle with the correct path structure + await spawn('zip', ['-r', apkPath, 'assets'], { + cwd: tempPath, + }); } catch (error) { throw new RnefError( `Failed to replace JS bundle in destination file: ${apkPath}}`, From 902c384d797fefc67cb391eb1b0ecbf7265a83d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Fri, 18 Apr 2025 18:06:06 +0200 Subject: [PATCH 2/2] remove adm-zip for now --- packages/platform-android/package.json | 1 - pnpm-lock.yaml | 3 --- 2 files changed, 4 deletions(-) diff --git a/packages/platform-android/package.json b/packages/platform-android/package.json index 3b062ffa8..f37c333d9 100644 --- a/packages/platform-android/package.json +++ b/packages/platform-android/package.json @@ -18,7 +18,6 @@ "dependencies": { "@react-native-community/cli-config-android": "^16.0.2", "@rnef/tools": "^0.6.2", - "adm-zip": "^0.5.16", "tslib": "^2.3.0" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 484086abe..a9d884d21 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -189,9 +189,6 @@ importers: '@rnef/tools': specifier: ^0.6.2 version: link:../tools - adm-zip: - specifier: ^0.5.16 - version: 0.5.16 tslib: specifier: ^2.3.0 version: 2.8.1