1

I've been unable to build my project due to this error:

Error:Gradle: Execution failed for task ':transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_74\bin\java.exe'' finished with non-zero exit value 1

The build used to work, no new dependencies were added, nor Java updates nor Gradle updates, it stopped working all of a sudden. My method count doesn't surpass 2^16 methods (counted per http://www.methodscount.com).

Have tried various solutions proposed in StackOverflow (except multiDex which I don't want to use), but to no effect, including:

  • Cleaning and rebuilding the project from the Build menu and also from the Gradle tasks.
  • Changing Java version (1.6 -> 1.7 -> 1.6)
  • Tinkering with ProGuard settings.
  • Not using ProGuard.
  • Enabling preDexLibraries = false

My projects uses the following external libraries:

compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'net.sourceforge.jexcelapi:jxl:2.6.12'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'joda-time:joda-time:2.9.2'
compile 'org.achartengine:achartengine:1.2.0'
compile 'com.squareup.okhttp3:okhttp:3.2.0'

testCompile 'org.jmockit:jmockit:1.22'
testCompile 'junit:junit:4.12'

Built the project with the command line gradlew build --stacktrace --info. This is the relevant part:

Starting process 'command 'C:\Program Files\Java\jdk1.8.0_74\bin\java.exe''. Working directory: C:\Users\<MyUser>\Documents\<MyProjects>\<MyApp> Command: C:\Program Files\Java\jdk1.8.0_74\bin\java.exe -Djava.awt.headless=true -Xmx4g -Dfile.encoding=UTF-8 -Duser.country=<CountryCode> -Duser.language=<LanguageCode> -Duser.variant -cp C:\Users\<MyUser>\AppData\Local\Android\android-sdk\build-tools\23.0.2\lib\dx.jar com.android.dx.command.Main --dex --verbose --num-threads=4 --output C:\Users\<MyUser>\Documents\<MyProjects>\<MyApp>\build\intermediates\pre-dexed\debug\com.google.android.gms-play-services-base-8.4.0_f1b0dcf4430103fbfcfd5d1164213cb1cfdd3142.jar C:\Users\<MyUser>\Documents\<MyProjects>\<MyApp>\build\intermediates\exploded-aar\com.google.android.gms\play-services-base\8.4.0\jars\classes.jar
Successfully started process 'command 'C:\Program Files\Java\jdk1.8.0_74\bin\java.exe''
processing <FilesInMyProject>.class...
:transformClassesWithDexForDebug FAILED
:transformClassesWithDexForDebug (Thread[Task worker Thread 3,5,main]) completed. Took 34.893 secs.

If I run the command listed above (Command: C:\Program Files\Java\jdk1.8.0_74\bin\java.exe -Djava.awt.headless=true [...]), it runs perfectly fine.

I am not sure what additional information is needed to solve this issue. I'll post more information as requested.

Regards.

OneEyeQuestion
  • 742
  • 7
  • 22
  • 1
    you did clean your project right? – Adam Forbis Mar 19 '16 at 22:33
  • @AdamForbis Yes. Adding that to the original post. – OneEyeQuestion Mar 19 '16 at 22:44
  • do you have any external library or module in your project ? – Fakher Mar 19 '16 at 22:49
  • @Fakher Yes. The ones listed in my `build.gradle`. Updating my post. – OneEyeQuestion Mar 19 '16 at 22:59
  • When I was getting that error, it was because I was including too many libraries, and was getting more than 65536 functions. I added the count function here to check when I had it: http://stackoverflow.com/questions/27766628/check-how-many-methods-you-have-in-android-studio Try enabling multiDex to see if it fixes it, and if it does, this might help you figure out where all the calls are. – Matthew Carlson Mar 20 '16 at 01:26
  • @MatthewCarlson Here the problem isn't the number of dependencies because as stated in the first post the build used to work and no new dependencies were added. Nevertheless I checked just to be on the safe side and the count is around 20K. Also, take into account that the error is "exit value 1", and not "exit value 2", which I've seen in other posts related to the 2^16 functions limit. I would also recommend visiting: http://www.methodscount.com – OneEyeQuestion Mar 20 '16 at 01:35
  • @OneEyeQuestion I see those notes in your post now, I must have just missed them. It was the only thing I remembered happening to me. I remember now some message like that when two of my dependencies had the same jar file in them, but same thing if you haven't changed dependencies. You can try adding the `--info` or `--debug` flags to see if it gives you more output: http://stackoverflow.com/questions/21674091/how-to-add-stacktrace-or-debug-option-when-building-android-studio-project – Matthew Carlson Mar 20 '16 at 01:55
  • @MatthewCarlson I'll update the post with what I got. – OneEyeQuestion Mar 20 '16 at 15:01
  • @OneEyeQuestion I just started a new project, and tried to put in your includes, and got: ` Failed to resolve: org.achartengine:achartengine:1.2.0` It looks like that's at a different repo you have to add to your project. And it looks like that library is constantly updating, last modified date is today. It could have cuased a conflict. After adding that repo, and compiling, I get this output for my dexcount: 37758 (there are still 22778 references to burn...) Just that, without any code of my own is higher than the 20K number you have. – Matthew Carlson Mar 20 '16 at 16:24
  • @OneEyeQuestion At this point, if I was debugging it myself, I would start removing all my java classes, and see if the build succeeds, and then try to add them back in piece by piece until it breaks again, Which I know is a bad way to do it, but it's the habit I've fallen into. – Matthew Carlson Mar 20 '16 at 16:26
  • @MatthewCarlson I created a new project. Added all the dependencies I listed above. Used this plugin (https://github.com/KeepSafe/dexcount-gradle-plugin) and got a method count of 32741. Still way below the number. – OneEyeQuestion Mar 20 '16 at 17:46
  • @OneEyeQuestion No worries, glad you got it fixed though! – Matthew Carlson Mar 20 '16 at 20:33

1 Answers1

1

The problem was an old file which I had emptied while doing a refactor and had a package header as package java; This caused the error. While looking at the info shown in console it stated that it had trouble processing the class XXXX and "Ill-advised or mistaken usage of a core class (java.* or javax.*) [...]"

OneEyeQuestion
  • 742
  • 7
  • 22