@@ -11,7 +11,6 @@ import {
11
11
spawn ,
12
12
spinner ,
13
13
} from '@rnef/tools' ;
14
- import AdmZip from 'adm-zip' ;
15
14
import { findAndroidBuildTool , getAndroidBuildToolsPath } from '../../paths.js' ;
16
15
import { buildJsBundle } from './bundle.js' ;
17
16
@@ -65,14 +64,12 @@ export async function signAndroid(options: SignAndroidOptions) {
65
64
66
65
loader . start ( 'Initializing output APK...' ) ;
67
66
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 ) ;
72
69
} catch ( error ) {
73
70
throw new RnefError (
74
71
`Failed to initialize output APK file: ${ options . outputPath } ` ,
75
- { cause : ( error as SubprocessError ) . stderr }
72
+ { cause : error }
76
73
) ;
77
74
}
78
75
loader . stop ( `Initialized output APK.` ) ;
@@ -141,11 +138,24 @@ async function replaceJsBundle({
141
138
apkPath,
142
139
jsBundlePath,
143
140
} : ReplaceJsBundleOptions ) {
141
+ const tempPath = path . dirname ( apkPath ) ;
144
142
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
+ } ) ;
149
159
} catch ( error ) {
150
160
throw new RnefError (
151
161
`Failed to replace JS bundle in destination file: ${ apkPath } }` ,
0 commit comments