Solve the Android compilation error: Error:Execution failed for task ':app:transformClassesWithDexForDebug'.

Recently, I was researching the TDD development model. After setting up the framework, I found that the compilation error was reported. After some fiddling around, the problem was solved. Then record it, I hope it will be helpful to the students who also encounter this problem.

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

Inexplicable error, no solution ideas. So I searched on the Internet and referenced a number of solutions but did not solve the problem.

But the search process is still rewarding:

  • For the convenience of testing, I created a new Java Library project to store classes that do not depend on the Android system. Then add it to app/build.gradle as a dependency.

dependencies {
  ...
  compile project(':core')
}
  • When I removed this line of code, I found that it could be compiled and passed, which means that the problem lies in the dependency on the library.

  • In the process of searching for solutions, I found that most of the people who encountered such problems were using the JDK 1.8 version (I believe you should also notice which version I am using, if not, please look up and have a look ^_ ^). This is not a coincidence, so I suspect Gradle has compatibility issues with JDK 1.8. Try to reduce the JDK version that the project depends on to 1.7, try to compile again, success!

Small summary:

Gradle is still in the active development period, and many new versions have unstable functions. It is recommended to update the Gradle version used by the project with caution.

This article is reprinted from http://www.jianshu.com/p/af9fec8a746e

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325757669&siteId=291194637