Skip to content

Decompiling to Java

Updated on 30 November 2026

ngr decompile app.apk

That gives you a .java file per class in app_java/. This page covers how to get the most out of it.

Reading the summary

The second-to-last line of stderr says how it went:

ngr decompile: 43 classes, 92 methods: 92 natural, 0 dispatcher, 0 smali; 17 files written

And the exit code sums it up in a number: 0 if everything is Java, 3 if something stayed as smali.

The three categories of a method

ngr does not write Java that looks right and is not. When it cannot translate something, it says so in place:

Category What you see in the file What you can do with it
natural Ordinary Java Read it and compile it
dispatcher A loop with a switch, after // nogar: dispatcher: Read it with more effort, and compile it
smali The code in smali, after /* NOGAR ERROR: */ and the reason Read it as smali. javac rejects the class

Each file starts with its count, so a search finds the ones that have something to look at:

grep -rl 'NOGAR ERROR' app_java
grep -rl 'nogar: dispatcher' app_java

“The decompiler output” explains each reason.

Decompiling only what matters

A real app carries many libraries. To keep just its code:

ngr decompile --packages com.example app.apk

To leave a part out, or to get a single class:

ngr decompile --packages com.example --exclude-packages com.example.thirdparty app.apk
ngr decompile --classes 'Lcom/example/app/MainActivity;' app.apk

The filters decide which files are written. The analysis is always of the whole app, so a file is identical whether you get it alone or with all the others. To find out which packages there are:

ngr list classes app.apk | cut -d/ -f1-3 | sort | uniq -c | sort -rn | head

Recovering names

An obfuscated app has classes and methods called a, b, c. There are three ways to improve that, from most to least reliable:

  1. With the mapping. If you have the mapping.txt that R8 or ProGuard wrote at build time, the original names come back:

    ngr decompile --mappings mapping.txt app.apk
    
  2. With what the dex carries. By default, parameters and variables take their name from the debug information and from the Kotlin metadata, when the dex keeps them. You do not have to ask for it.

  3. With invented names. --deobf replaces names of two characters or fewer with others taken from what the dex shows, such as the source file name or the type of a field:

    ngr decompile --deobf app.apk
    

    Each invented name gives the original in a /* renamed from */ comment. They are names to read better, not the ones the author wrote.

Matching a stack trace to the code

With --line-numbers, each statement is preceded by the line number it had in the original source, if the dex keeps it:

/* line 14 */ long[] arr = Counter.TABLE;
/* line 14 */ if (i >= arr.length) {

Getting output that compiles

If you want to run the output through javac, three options help:

ngr decompile --java-version 17 --stubs --report report.json app.apk
  • --java-version chooses the language level. With a higher one, fewer things have to stay as smali: private interface methods need Java 11, and code before super(...) needs Java 25.
  • --stubs writes to nogar-stubs/ minimal declarations of the classes the app uses and does not carry, so that javac finds them.
  • --report leaves the category of each method in a JSON, so you know which classes will not compile without trying.

Classes with any smali method do not compile, and that is on purpose. The rest do.

That it compiles does not mean you can put it back into the apk as it is. To change an app you edit its smali (“Modifying and rebuilding an apk”).

What to expect from the output

  • It is Java, also when the original was Kotlin. A Kotlin class comes out as the Java equivalent of its bytecode.
  • It is faithful before it is pretty. Where the dex does something odd, the output shows it, with a dispatcher or with smali, instead of covering it up.
  • The changes it makes are declared. If a class or a field is written with a different modifier or a different name than in the dex, a comment or the report says so (“Declared deviations”).
  • Check it before relying on it. It is the output of a program working on code it did not write. The license says so too: it may be incomplete or incorrect.

See also