Skip to content

Commit 703be76

Browse files
committed
fix: re-signing android zip
1 parent f91a900 commit 703be76

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

packages/platform-android/src/lib/commands/signAndroid/signAndroid.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
spawn,
1212
spinner,
1313
} from '@rnef/tools';
14-
import AdmZip from 'adm-zip';
1514
import { findAndroidBuildTool, getAndroidBuildToolsPath } from '../../paths.js';
1615
import { buildJsBundle } from './bundle.js';
1716

@@ -65,14 +64,12 @@ export async function signAndroid(options: SignAndroidOptions) {
6564

6665
loader.start('Initializing output APK...');
6766
try {
68-
const zip = new AdmZip(options.apkPath);
69-
// Remove old signature files
70-
zip.deleteFile('META-INF/*');
71-
zip.writeZip(tempApkPath);
67+
fs.mkdirSync(tempPath, { recursive: true });
68+
fs.copyFileSync(options.apkPath, tempApkPath);
7269
} catch (error) {
7370
throw new RnefError(
7471
`Failed to initialize output APK file: ${options.outputPath}`,
75-
{ cause: (error as SubprocessError).stderr }
72+
{ cause: error }
7673
);
7774
}
7875
loader.stop(`Initialized output APK.`);
@@ -141,11 +138,24 @@ async function replaceJsBundle({
141138
apkPath,
142139
jsBundlePath,
143140
}: ReplaceJsBundleOptions) {
141+
const tempPath = path.dirname(apkPath);
144142
try {
145-
const zip = new AdmZip(apkPath);
146-
zip.deleteFile('assets/index.android.bundle');
147-
zip.addLocalFile(jsBundlePath, 'assets', 'index.android.bundle');
148-
zip.writeZip(apkPath);
143+
fs.mkdirSync(path.join(tempPath, 'assets'), { recursive: true });
144+
145+
const tempBundlePath = path.join(
146+
tempPath,
147+
'assets',
148+
'index.android.bundle'
149+
);
150+
fs.copyFileSync(jsBundlePath, tempBundlePath);
151+
152+
// Delete the existing bundle
153+
await spawn('zip', ['-d', apkPath, 'assets/index.android.bundle']);
154+
155+
// Add the new bundle with the correct path structure
156+
await spawn('zip', ['-r', apkPath, 'assets'], {
157+
cwd: tempPath,
158+
});
149159
} catch (error) {
150160
throw new RnefError(
151161
`Failed to replace JS bundle in destination file: ${apkPath}}`,

0 commit comments

Comments
 (0)