4
votes

While build android app from command line i am getting error Execution failed for task ':app:compileDebugJavaWithJavac'. java.lang.NoClassDefFoundError: javax/annotation/Generated

I am enable dataBinding in android application

symbol: class DataBindingComponent location: class ActivityMainBinding /home/chetan/project/newGradle/app/build/generated/source/dataBinding/baseClasses/debug/com/sko/gradledemo/databinding/ActivityMainBinding.java:49: error: cannot find symbol @Nullable DataBindingComponent component) {

symbol: class DataBindingComponent location: class ActivityMainBinding /home/chetan/project/newGradle/app/build/generated/source/dataBinding/baseClasses/debug/com/sko/gradledemo/databinding/ActivityMainBinding.java:60: error: cannot find symbol @Nullable DataBindingComponent component) {

symbol: class DataBindingComponent location: class ActivityMainBinding 5 errors

FAILURE: Build failed with an exception. What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'. java.lang.NoClassDefFoundError: javax/annotation/Generated

1
I am getting error when added dataBinding and build application from command line using ./gradlew assembleDebug - Chetan Chaudhari

1 Answers

3
votes

I got this in my project when I used commandline ./gradlew :app:assembleDevDebug but not when running my project in Android studio. Problem is that the annotation processing requery (dataBinding in your case) is failing with a dependency which was removed in newer JDKs.

My problem boiled down to Gradle using my "system" JDK which was openjdk version "13.0.1". Even when setting JAVA_HOME to a specific one with JDK 8, Gradle was using the "system" one. This is easy to discover using ./gradlew -v which printed JVM: 13.0.1 (Oracle Corporation 13.0.1+9).

I solved this by setting the JDK home in my gradle.properties file in the root of the project to the JDK bundled with Android Studio.

org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home

After this the project run fine using commandline. Hope it helps others.