The original project used jdk8, and this problem occurred after upgrading gradle.
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
at org.codehaus.groovy.vmplugin.VMPluginFactory.<clinit>(VMPluginFactory.java:43)
at org.codehaus.groovy.reflection.GroovyClassValueFactory.<clinit>(GroovyClassValueFactory.java:35)
at org.codehaus.groovy.reflection.ClassInfo.<clinit>(ClassInfo.java:109)
at org.codehaus.groovy.reflection.ReflectionCache.getCachedClass(ReflectionCache.java:95)
at org.codehaus.groovy.reflection.ReflectionCache.<clinit>(ReflectionCache.java:39)
...
By tracing the stack, it is found that jdk7, 8, and 9 cannot be found in the current environment.
solution
First, java -version
check the Java version of the current environment. Generally, it is caused by the inconsistency between the Java version configured by Android Studio, the command line that comes with Android Studio, and the system's command line environment. Some of them are jdk8, jdk11, and jdk17, so adjust the current build. The jdk version of the environment is enough.
If it is jdk17, try downgrading to jdk11;
if it is jdk7 or 8, try upgrading to jdk11