Android Studio:Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7

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)
     ...

Insert image description here
Insert image description here
By tracing the stack, it is found that jdk7, 8, and 9 cannot be found in the current environment.

solution

First, java -versioncheck 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

Guess you like

Origin blog.csdn.net/u011106915/article/details/132334172