Professionation Obfuscation causing dex to throw Exceptions

I have an Android app that I'm only trying to confuse with Proguard (hence I have the -dontoptimize -dontshrink -dontpreverify flags). When I build using 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 application will immediately fire from a NullPointerException.

I create in Android Studio, with the latest version of Proguard, in the default proguard file and some additional parameters -keep and -dontwarn. Any ideas what causes this? Thanks!

+7
android obfuscation proguard dex
source share
2 answers

I ran into a similar problem in Android Studio. He hit when he did "dex" to convert the 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 processed strings. Upgraded everything to no avail.

In the end, I realized that one of the methods called to do a little string processing was put into the interface. This worked with pleasure for the main java, but obviously not for dex. When a method was deduced from the interface and back to one of many classes, dex did not forbid.

My suggestion would be to carefully consider code that is looking for new or advanced language features that can be included in dex. I don’t know how much I can help, this error slowed down all my Android developments for 2 months.

+1
source share

This can happen if you use java 1.8+ level API in Android Studio and / or:

  • with incompatible gradle configuration (sourceVersion / targetVersion not allowed)
  • using the 1.8 API, which is currently not available on Android
  • you are using illegal class casts or reflections that cannot be detected before dex time (unresolved from this post)

You can replace 1.7 and 1.8 for "older" and "new", the exact version of the API should not matter.

I suggest cutting libraries and suspecting code until you get a successful build. In my case, it went into the class as follows:

 Class<E> klass = (Class<E>) Class.forname(...).asSubclass(...) ... ; 

Which of them was built perfectly (with a random warning - another mistake), but threw that incomprehensible error that you get at different times. Removing a solution to a problem.

I also noticed that switching the language level down the version and then backward (1.8 β†’ 1.7 β†’ 1.8) and applying and exiting the settings after each change generated a set of new warnings that were previously missing.

0
source share

All Articles