ngr merge
Merges the split apks of a bundle into a single apk: the base apk and the ones that carry the languages, screen
densities and architectures. You use it to turn an .xapk, an .apkm or an .apks into an apk that you can
install, inspect or decode like any other. The resulting apk is not validly signed: you have to sign it with
ngr sign.
Usage
ngr merge [options] <bundle>
Inputs
| Input | What it is |
|---|---|
<bundle> |
A bundle: .xapk, .apkm or .apks |
Options
| Option | What it does | Default |
|---|---|---|
-o, --output <file> |
The apk to write | <name>_merged.apk next to the bundle |
-f, --force |
Overwrites the output if it already exists | |
--clean-meta |
Removes the signature entries and nulls the apk signing block | |
--extract-native-libs <manifest|none|true|false> |
Sets extractNativeLibs in the merged manifest and chooses how the lib/**.so files are stored |
manifest |
--validate-res-dir |
Moves each resource file to the folder of its type | |
--res-dir <name> |
Changes the name of the res/ root folder of the merged apk |
|
--validate-modules |
Aborts if two modules of the same package have a different versionCode |
|
-h, --help |
Shows the help |
The values of --extract-native-libs:
| Value | What it does |
|---|---|
manifest |
Reads the value from the merged manifest |
none |
Removes the attribute and stores the libraries compressed |
true |
Sets the attribute to true and stores the libraries compressed |
false |
Sets the attribute to false and stores the libraries uncompressed, aligned to 4096 bytes |
What it writes
The merged apk, <name>_merged.apk unless you say otherwise. The final line goes to stderr:
wrote app_merged.apk
An .xapk with a base apk and seven splits for language, density and architecture becomes a single apk with the
manifest, the resource table, the dex files, the resources for all the languages and the libraries for both
architectures:
ngr merge app.xapk
ngr info --languages app_merged.apk
languages [ count 5]
1) es
2) fil
3) fr
...
With .apkm and with .apks the result has the same package, version and languages.
Examples
Merge an .xapk and sign the result:
ngr merge app.xapk
ngr sign --ks release.p12 --ks-pass env:KS_PASS app_merged.apk
Merge, removing the signatures of the base apk:
ngr merge --clean-meta -o app-clean.apk app.xapk
Store the native libraries uncompressed and set it in the manifest:
ngr merge --extract-native-libs false app.xapk
Check before merging that all the modules are of the same version, and move each resource to the folder of its type:
ngr merge --validate-modules --validate-res-dir -f app.xapk
Exit codes
| Code | When |
|---|---|
| 0 | The apk was written |
| 1 | The bundle does not exist or cannot be merged, or the output already exists and you did not pass -f |
| 2 | The options are wrong: <bundle> is missing, or --extract-native-libs has a value that is not valid |
Things to know
- The apk does not verify until you sign it. Without
--clean-meta, it keeps the signature blocks of the base apk, which no longer match the content, andngr verifyends with 3:
DOES NOT VERIFY
ERROR: APK Signature Scheme v3 signer #1: APK integrity check failed. CHUNKED_SHA256 digest mismatch. ...
With --clean-meta no signature is left, and verify also ends with 3:
DOES NOT VERIFY
ERROR: Missing META-INF/MANIFEST.MF
In both cases, ngr sign leaves an apk that verifies.
mergelooks for the.apkfiles inside the zip. A file that has none givesNo *.apk files found on the bundleand ends with 1: that is what happens with a normal apk, with a.jarand with an.aab.- Two apps in the same bundle do not give an error. If the bundle has two base apks of different packages,
mergewrites a single apk and does not warn. In a two-apk bundle, the result takes the package of the second one. - Two versions of the same package do not give an error either, except with
--validate-modules. Without the option,mergewrites the apk, and the result carries theversionCodeof the second module. With it, it ends with 1:
ngr merge: unable to merge 'app.xapk': Incompatible to merge: {com.example.app, 2}, with {com.example.app, 1}.
- A protected bundle is not merged. If a module has entries under
classes.dex/orAndroidManifest.xml/,mergewrites nothing, says which module and ends with 1:
ngr merge: unable to merge 'app.xapk': PROTECTED: module '...' has the entry 'classes.dex/...'; no output is written when a module has entries under 'classes.dex/' or 'AndroidManifest.xml/'.
A bundle whose resource table is damaged gives a read error, also with 1:
ngr merge: unable to merge 'app.xapk': Arsc: chunk at 12 is 0x0000, not a string pool.
--res-dirchanges the name of the resource root folder. With--res-dir ron a sample.xapk, 40 files went fromres/tor/, andres/Sy.9.png, a loose file inres/, stayed where it was..apkmcarries a note inngr identify: the<file>/<entry>.dexsyntax does not work with.apkm.
See also
ngr sign, to sign the merged apk.ngr identify, to find out what kind of bundle you have.- “Merging a bundle”.