We are developing an android app and we are currently trying to update to gradle 3.0. We follow the guide from google from here to migrate to the new gradle version.
But we are getting a Exception which says that any of our method is to large:
Exception in thread "main" java.lang.RuntimeException: Method code too large!
at org.objectweb.asm.MethodWriter.a(Unknown Source)
at org.objectweb.asm.ClassWriter.toByteArray(Unknown Source)
at com.google.devtools.build.android.desugar.CoreLibraryRewriter$UnprefixingClassWriter.toByteArray(CoreLibraryRewriter.java:152)
at com.google.devtools.build.android.desugar.Desugar.desugarClassesInInput(Desugar.java:403)
at com.google.devtools.build.android.desugar.Desugar.desugarOneInput(Desugar.java:326)
at com.google.devtools.build.android.desugar.Desugar.desugar(Desugar.java:280)
at com.google.devtools.build.android.desugar.Desugar.main(Desugar.java:584)
I already waste a day to find out what is going wrong here. I know this failure is caused by the ASM bytecode manipulator (http://asm.ow2.org/) which probably comes new with gradle 3. I also know the code part inside ASM Framework which throws this RuntimeException (see here).
I also find out that most times such hugh classes / methods gets generated by a framework (for example Lombok or Dagger) and could / should not be written by human (source).
Can anyone help me please with this problem? Does anyone know how i can find out which class or method (hopefully generated) from our app causes this exception? Maybe there is a tool outside which can analyse java code to find methods which exceed the 64k limit?
Solution
I got the hint from the method comment of desugar.desugarClassesInInput
(see). There it says:
/** Desugar the classes that are in the inputs specified in the command line arguments. */
So i checked the gradle output and i found this output:
Error while executing java process with main class com.google.devtools.build.android.desugar.Desugar with arguments {--input .....
The listed inputs are some jar files and library dependencies of our project. I removed all listed dependencies step by step and if found the library which causes this exception. Removed that library and now our project runs with Gradle 3.
Maybe this helps some guys out there if they are facing a similiar issue.