Skip to content

How ngr works

Updated on 1 December 2026

All ngr commands follow the same rules. With this page you can predict what a command you have not used will do.

The shape of a command

ngr <command> [options] <input>...

Commands are flat: there are no subcommands. Long options start with -- and some have a short form (-o, -f, -v, -j). Options can go before or after the input, and their value is written separated by a space or with = (--output app2 or --output=app2). Short forms cannot be combined: -f -o, not -fo.

Order matters only in the signing commands: a signer's options go after the --ks that opens it (ngr sign).

Command What it does
ngr help Lists the commands by area, with three example walkthroughs
ngr help <command> Shows the inputs and options of a command
ngr <command> --help The same as the previous one
ngr --version Prints the ngr version

The 19 commands are grouped into five areas, and each has its own page in “Commands”:

Area Commands
Inspect an apk identify, info, resource, xml
Transform an apk decode, build, merge, refactor, protect
Align and sign align, sign, verify, rotate, lineage
Dex and smali disassemble, assemble, dump, list
Decompile decompile

Inputs are recognized by their structure

ngr looks at what a file is, not at what it is called. An apk renamed to .zip is still an apk. ngr identify tells you which of the five structures it knows a file has and which commands accept it.

The commands that read dex (disassemble, dump, list, decompile) accept a loose dex, an apk or an xapk. From an apk they read all its dex files, in order. To name just one, treat the apk as if it were a folder:

ngr list classes app.apk/classes2.dex

Where output goes

Each command that writes has a default output name, next to the input and with a suffix that says what it is. You do not need -o to work.

Command Input Default output
decode app.apk app/
build app/ app_built.apk
merge app.xapk app_merged.apk
refactor app.apk app_refactored.apk
protect app.apk app_protected.apk
align app.apk app_aligned.apk
sign app.apk app_signed.apk and app_signed.apk.idsig
disassemble classes.dex classes_smali/
assemble classes_smali/ classes_smali.dex
decompile app.apk app_java/

-o changes the destination. rotate has no default name and always requires -o.

No command changes the file you give it or overwrites an output that already exists. If the destination exists, the command ends with code 1 and says which option allows it. That option is -f, but it does not do the same in all of them:

  • in decode, -f deletes the whole folder before writing;
  • in disassemble and decompile, -f writes inside the folder without emptying it;
  • in the ones that write a file, -f overwrites it.

“Files each command writes” has the details.

What goes to stdout and what to stderr

  • stdout carries what you asked to see: the info report, the list listing, the verify -v verdict. It is what you redirect to a file or to another program.
  • stderr carries what ngr has to tell you about the run: warnings (WARN:), errors (ngr <command>: ...) and, in the commands that write, a last line that starts with wrote and says what was written and where.

An error is written on one line with the command that failed, the reason and, when there is one, the way out:

ngr decode: 'nope.apk' does not exist.
ngr decode: unrecognized option '--nope'. See 'ngr help decode'.

Exit codes

Code Meaning
0 Everything went well
1 Failure: an input cannot be read or used, or an output cannot be written
2 Usage error: the options or inputs on the command line are wrong
3 Negative verdict. Only identify, align, verify and decompile give it

The 3 is not an ngr failure: it is the answer to a question. verify ends with 3 when the apk does not verify, and align --check, when an entry is not aligned. “Output and exit codes” says what it means in each one.

Passwords

The options that ask for a password (--ks-pass, --old-ks-pass and the others) do not take it written out as is. They take one of these four forms:

Form Where the password comes from
pass:<password> The command line itself
env:<variable> An environment variable
file:<path> A file
stdin Standard input

pass: leaves the password in the shell history and visible in the process list. In a script, use env: or file:.

The 0.x versions are beta

We will try not to, but from one 0.x to the next the commands, the options, the exit codes and the output formats may change. “Release notes” says what changes in each version.

If you write a script, pin the version of ngr it uses, and rely on the exit codes and on file names, not on the text of stderr (“Using ngr in scripts”).

Next step

“Commands”, or one of the “tasks”.