java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7

后端 未结 14 2057
南方客
南方客 2020-12-28 11:46

I am getting this exception java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7 and java.lang.NoClassDefFoundError: Coul

相关标签:
14条回答
  • 2020-12-28 11:59

    If you using Android Studio 4.0 or up and having Errors like below

        Cause: invalid type code: 17
        Cause: invalid type code: fe
        Cause: invalid type code: 13
    java.lang.NoClassDefFoundError: Could not initialize class
    

    Or

    Its says that something wrong with JDK then Follow below steps to resolve the error.

    Step 1: First delete .gradle and .idea folder from project directory and restart Android Studio. Make sure it's gone from recycle bin.

    Step 2: Go to Project Structure

    Step 3: Select SDK Location from the left panel on Project Structure window.

    Step 4: Go to JDK Location and click on down arrow then select the jre instead of jdk

    C:\Program Files\Android\Android Studio\jre
    

    And it will Solve the errors. Rebuild the project

    Note: jre come with the android studio 4 installation not sure about the older version.

    This solution work for me.

    0 讨论(0)
  • 2020-12-28 12:01

    In the file android/gradle/wrapper/gradle-wrapper.properties, ensure that the distributionUrl is as follows:

    distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
    

    Note: If you installed jdk 14

    0 讨论(0)
  • 2020-12-28 12:02

    in my case, the JRE version used in the Run Configuration was different than the target JDK version in the pom.xml

    0 讨论(0)
  • 2020-12-28 12:02

    If you are looking for similar solution as @godsim shared, but for gradle liquabase plugin, then modify your configuration section in build.gradle to exclude liquabase's groovy dependency:

    configurations {
        ...
        liquibaseRuntime.exclude group: "org.codehaus.groovy"
    }
    

    and then manually add groovy in dependencies section:

    dependencies {
        ...
        liquibaseRuntime('org.liquibase:liquibase-core:3.8.1')
        liquibaseRuntime('org.codehaus.groovy:groovy-all:3.0.3')
        liquibaseRuntime 'org.postgresql:postgresql'
        liquibaseRuntime('org.liquibase:liquibase-groovy-dsl:2.1.2')
        liquibaseRuntime('org.liquibase.ext:liquibase-hibernate5:3.10.2')
        liquibaseRuntime('org.springframework.boot:spring-boot-starter-data-jpa')
        liquibaseRuntime sourceSets.main.output
        ...
    }
    
    0 讨论(0)
  • 2020-12-28 12:03

    I solved this by selecting Installed JRE path in window => preferences => java => installed JRE => remve existing & select from local directory.

    Make sure you have java_home variable set in environmental variable

    0 讨论(0)
  • 2020-12-28 12:05

    are you using some third party library that brings in org.codehaus.groovy dependencies? If yes, you can try and replace the required groovy dependencies with the most current releases yourself.

    In my case it was the org.liquibase:liquibase-groovy-dsl, so I did this:

        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-groovy-dsl</artifactId>
            <version>2.1.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-sql</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy</artifactId>
            <version>3.0.3</version>
        </dependency>
    
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-sql</artifactId>
            <version>3.0.3</version>
        </dependency>
    
    0 讨论(0)
提交回复
热议问题