ngr build
Builds an apk from the folder that ngr decode wrote. It is the second step to change an app: you
edit the resources, the manifest or the smali of the tree and build packs them again. The apk that comes out is
not validly signed: you have to sign it with ngr sign before installing it.
Usage
ngr build [options] <dir>
Inputs
| Input | What it is |
|---|---|
<dir> |
A folder that ngr decode wrote |
Options
| Option | What it does | Default |
|---|---|---|
-o, --output <file> |
The apk to write | <dir>_built.apk next to the folder |
-f, --force |
Overwrites the output if it already exists | |
--no-cache |
Reassembles all the smali and overwrites .cache/ with the result |
|
-h, --help |
Shows the help |
What it writes
The apk, <folder>_built.apk unless you say otherwise. The final line goes to stderr:
wrote app_built.apk
It does not touch the folder, except .cache/ when it reassembles smali.
Where the code comes from depends on how you decoded:
- If the tree has
dex/(decoded withngr decode --dex), the dex files come from there, as they are. - If not, they come from
smali/. Eachsmali/classes<N>reuses.cache/classes<N>.dexas long as no smali file is newer than it. If one is, that dex is reassembled and.cache/is updated.
--no-cache forces all the smali to be reassembled, even if nothing has changed.
Examples
Build the apk of a tree:
ngr decode app.apk
ngr build app
Build it with another name, overwriting the previous one:
ngr build -f -o app-modified.apk app
Reassemble all the smali, without trusting .cache/:
ngr build --no-cache app
Build and sign, which is what you need to install it:
ngr build app
ngr sign --ks release.p12 --ks-pass env:KS_PASS app_built.apk
Exit codes
| Code | When |
|---|---|
| 0 | The apk was written |
| 1 | The folder does not exist, is a file, is not a decode tree, or the output already exists and you did not pass -f |
| 2 | The options are wrong: <dir> is missing, there is an extra input or the option does not exist |
Things to know
- The apk does not verify. With a tree from a signed apk,
buildkeeps the signature blocks of the original, which no longer match the content. With a tree from an unsigned apk, there is no signature. In both casesngr verifyends with 3:
DOES NOT VERIFY
ERROR: APK Signature Scheme v3 signer #1: APK integrity check failed. CHUNKED_SHA256 digest mismatch. ...
DOES NOT VERIFY
ERROR: Missing META-INF/MANIFEST.MF
Sign the result with ngr sign.
- It is not the apk you started from. Even if you change nothing, the order of the zip entries, the header flags and the line numbers of the xml files are computed again. The size changes too.
- The folder has to be a
decodetree. If it is not,buildsays so and ends with 1:
ngr build: unable to build 'empty': no <package>/values/public.xml found under 'empty/resources': the tree is incomplete or was not written by 'ngr decode'.
A file instead of a folder gives ngr build: 'app.apk' is a file, not the directory 'ngr decode' writes.
- The output apk does not overwrite anything without
-f. If it already exists,buildends with 1 and says to pass-f.
See also
ngr decode, the previous step.ngr sign, to sign the apk that comes out.ngr verify, to check it.- “Modifying and rebuilding an apk”.