7

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!

Caleb An
  • 366
  • 1
  • 10
  • facing same issue let me know in case any solution is found – amodkanthe Oct 07 '15 at 04:53
  • 1
    I have reviewed an answer to this question that turned out to be an audit based on a deleted answer. Maybe it was not good enough to be an answer, but it still said something useful: it said that this is an official bug, which can be found at [Android's bug tracker](https://code.google.com/p/android/issues/detail?id=187483&q=label%3AReportedBy-Developer&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars). Its current status is FutureRelease and there are even some workarounds, like reverting to 7.8 or reverting from gradle 1.5.0 to 1.3.0, check it out for more details. I Hope this helps! – Fabio says Reinstate Monica Nov 19 '15 at 23:09

2 Answers2

1

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.

Iang
  • 11
  • 2
  • 1
    This is not an answer; maybe comment on the question instead if you feel it is valuable – beresfordt Feb 21 '15 at 00:36
  • Folks, thanks for suggesting commentary, but I am not permitted to comment on OP due to apparent lack of reputation. It's back to obscurity for me :) – Iang Feb 23 '15 at 20:12
0

This can occur if you are using java 1.8+ level API in Android Studio and/or:

  1. building with an incompatible gradle configuration (sourceVersion/targetVersion are invalid)
  2. building using 1.8 API that isn't currently available on Android
  3. you're using illegal class-casts or reflection that may not be detected before dex time (unresolved as of this posting)

You can substitute 1.7 and 1.8 for "older" and "newer", the exact API version shouldn't really matter.

I suggest stripping out libraries and suspect code until you get a successful build. In my case, it was casting to a class like this:

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

Which built fine (with an occasional warning--another bug), but threw the obscure error you are receiving at dex time. Removing it solved the issue.

I also noticed that switching the language level down a version and then back (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.

EntangledLoops
  • 1,951
  • 1
  • 23
  • 36