Skip to content

Commit fc63796

Browse files
committed
fix: re-signing android zip
1 parent 3b12651 commit fc63796

File tree

3 files changed

+103
-35
lines changed

3 files changed

+103
-35
lines changed

packages/platform-android/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"dependencies": {
1919
"@react-native-community/cli-config-android": "^16.0.2",
2020
"@rnef/tools": "^0.6.1",
21-
"adm-zip": "^0.5.16",
2221
"tslib": "^2.3.0"
2322
},
2423
"devDependencies": {

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}}`,

pnpm-lock.yaml

Lines changed: 83 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)