Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proguard Obfuscation causing dex compliation to throw Exceptions

I have an android app that I am only trying to obfuscate with Proguard(hence, I have the -dontoptimize -dontshrink -dontpreverify flags). When I build with Proguard, proguard itself does not throw any errors, but then dex throws the following exception:

Exception in thread "pool-1-thread-1" com.android.dx.cf.code.SimException: com.android.dx.rop.cst.CstMethodRef cannot be cast to com.android.dx.rop.cst.CstInterfaceMethodRef
at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:810)
... 
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassCastException: com.android.dx.rop.cst.CstMethodRef cannot be     cast to com.android.dx.rop.cst.CstInterfaceMethodRef

and the app crashes immediately from a NullPointerException.

I'm building in Android Studio, with the latest version of Proguard, on the default proguard file and some additional -keep options and -dontwarn options. Any ideas what is causing this? Thanks!

like image 614
Caleb An Avatar asked Jul 11 '14 00:07

Caleb An


1 Answers

I hit a similar problemin Android Studio. It struck when doing the 'dex' to convert an external Jar to dalvik:

Error:Android Pre Dex: [SOX.jar]
com.android.dx.rop.cst.CstInterfaceMethodRef cannot
be cast to com.android.dx.rop.cst.CstMethodRef

and then some obscure references to strings being processed. Upgraded everything to no avail.

I eventually figured out that one of the methods being called to do some minor string processing had been placed in an interface. Which worked happily for mainstream java, but evidently not for dex. When the method was moved out of the interface and back into one of the many classes, dex did not barf.

My suggestion would then be to carefully review the code looking for newer or advanced language features that dex might barf on. Not a lot of help, I know, this bug stalled all my android development for 2 months.

like image 133
Iang Avatar answered Sep 27 '22 19:09

Iang