Skip to content

Commit fc1d5e4

Browse files
authored
Add a pack-api shortcut for building an unsigned APK (#75)
1 parent 09e1fd6 commit fc1d5e4

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

pack-api/src/lib.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,17 @@ pub struct Package {
6565
pub resources: Vec<FileResource>
6666
}
6767

68-
/// Performs all the steps in packaging an APK.
68+
/// Performs all the steps in packaging an APK, without signing it.
6969
///
7070
/// This includes:
7171
///
7272
/// - Compiling resources into `aapt2`'s ResourceChunk format
7373
/// - Constructing a 4-byte aligned Zip file with the right compression settings
74-
/// - Signing the resultant APK with APK Signature Scheme v2 & v3
7574
///
76-
/// Returns: A vector of bytes representing the final APK zip file. For example,
77-
/// you could flush these to disk or download them from a webpage if called from WASM.
75+
/// Returns: A vector of bytes representing the final unsigned APK zip file.
7876
///
79-
/// The APK is built and signed in-memory without using the local filesystem.
80-
pub fn compile_and_sign_apk(package: &Package, keys: &Keys) -> Result<Vec<u8>> {
77+
/// The APK is built in-memory without using the local filesystem.
78+
pub fn compile_apk(package: &Package) -> Result<Vec<u8>> {
8179
let mut resources = vec![];
8280
// Look for strings.xml and parse it if present
8381
for res in &package.resources {
@@ -123,6 +121,23 @@ pub fn compile_and_sign_apk(package: &Package, keys: &Keys) -> Result<Vec<u8>> {
123121
let zip_buf_cursor = Cursor::new(&mut zip_buf);
124122
pack_zip::zip_apk(&apk_files, zip_buf_cursor)?;
125123

124+
Ok(zip_buf)
125+
}
126+
127+
/// Performs all the steps in packaging an APK.
128+
///
129+
/// This includes:
130+
///
131+
/// - Compiling resources into `aapt2`'s ResourceChunk format
132+
/// - Constructing a 4-byte aligned Zip file with the right compression settings
133+
/// - Signing the resultant APK with APK Signature Scheme v2 & v3
134+
///
135+
/// Returns: A vector of bytes representing the final APK zip file. For example,
136+
/// you could flush these to disk or download them from a webpage if called from WASM.
137+
///
138+
/// The APK is built and signed in-memory without using the local filesystem.
139+
pub fn compile_and_sign_apk(package: &Package, keys: &Keys) -> Result<Vec<u8>> {
140+
let mut zip_buf = compile_apk(package)?;
126141
pack_sign::sign_apk_buffer(&mut zip_buf, keys)
127142
}
128143

0 commit comments

Comments
 (0)