Is there a way to get a list of all classes from a .dex file?

ioreskovic picture ioreskovic · Jul 5, 2012 · Viewed 35.5k times · Source

I have a .dex file, call it classes.dex.

Is there a way to "read" the contents of that classes.dex and get a list of all classes in there as full class names, including their package, com.mypackage.mysubpackage.MyClass, for exmaple?

I was thinking about com.android.dx.dex.file.DexFile, but I cannot seem to find a method for retrieving an entire set of classes.

Answer

Use the command line tool dexdump from the Android-SDK. It's in $ANDROID_HOME/build-tools/<some_version>/dexdump. It prints a lot more info than you probably want. I didn't find a way to make dexdump less verbose, but

dexdump classes.dex | grep 'Class descriptor'

should work.