Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Unable to load class 'org.codehaus.groovy.runtime.typehandling.ShortTypeHandling'

I installed Android Studio and when I try to import a project from gradle this resolve error shows up:

Unable to load class 'org.codehaus.groovy.runtime.typehandling.ShortTypeHandling'.

I deleted the files in my Users .gradle folder and tried different gradle versions. I don't know how to fix this.

like image 835
EvilBurrito Avatar asked Mar 31 '15 00:03

EvilBurrito


3 Answers

This page might help solve the problem. What they say is:

So we leveraged this version to add a new artifact, named groovy-backports-compat23. This artifact shouldn’t be necessary for most of you, but if you face an error like:

Caused by: java.lang.ClassNotFoundException:
org.codehaus.groovy.runtime.typehandling.ShortTypeHandling    at
java.net.URLClassLoader$1.run(URLClassLoader.java:372)

in your project, then it means that a class has been compiled with Groovy 2.3+ but that you are trying to use it with an older version of Groovy. By adding this jar on classpath, you give a chance to your program to run. This may be particularily interesting for Gradle users that want to use a plugin built on Gradle 2+ on older versions of Gradle and face this error. Adding the following line to their build files should help:

buildscript {
    // ...
    dependencies {
         classpath 'some plugin build on gradle 2'
         classpath 'org.codehaus.groovy:groovy-backports-compat23:2.3.5'
    } }

Note that for now, this jar only contains the ShortTypeHandlingClass. Future versions may include more. - See more at: http://glaforge.appspot.com/article/groovy-2-3-5-out-with-upward-compatibility#sthash.mv7Y8XQv.dpuf

like image 109
Vlad Avatar answered Nov 18 '22 11:11

Vlad


I can fix this error message using these three methods.

  1. use latest gradle version
  2. use latest android SDK and tools.
  3. use proguard-rules.pro

build.gradle (Project:xxxxx)

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
         classpath 'com.android.tools.build:gradle:1.2.3'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

build.gradle (Module:app)

apply plugin: 'android'

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}
like image 27
Nurdin Avatar answered Nov 18 '22 11:11

Nurdin


I had the same problem. I ran gradle from command line and that did work. After that, I found File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle. There "Use local gradle distribution" was active. Changed it to "Use default gradle wrapper (recommended)" and it worked.

like image 22
Raul Pinto Avatar answered Nov 18 '22 12:11

Raul Pinto