17

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.

EvilBurrito
  • 823
  • 8
  • 14
  • 2
    Check this out http://stackoverflow.com/questions/28923716/getting-resolve-error-while-importing-project-in-android-studio-unable-to-load – Emre Eran Apr 05 '15 at 00:40

4 Answers4

6

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

Vlad
  • 18,195
  • 4
  • 41
  • 71
4

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'])
}
Nurdin
  • 23,382
  • 43
  • 130
  • 308
4

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.

Raul Pinto
  • 1,095
  • 8
  • 15
  • Thank you so much! I upgraded to Studio 1.3.1 and was dead in the water for a couple of hours until I found your answer!!!!!!! – Jim In Texas Aug 15 '15 at 18:58
  • You saved my life! After upgrading to Studio 1.5.1 from 1.4.1, I encountered this problem. And this answer works. – Better Shao Dec 23 '15 at 05:51
0

I have had a same problem. And I have found a solution.

Cause

This problem is caused by android gradle plugin does not match for gradle version.

Solution

Edit build.gradle in project. gradle plugin version must be satisfied requirements for android studio.

dependencies {
   classpath 'com.android.tools.build:gradle:1.1.0'
}

And edit distrubutionUrl in gradle/wrapper/gradle-wrapper.properties. version of gradle must be satisfied requirements for gradle plugin.

distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip

You can find version compatibilities between android studio, android gradle plugin and gradle in this page

https://stackoverflow.com/a/29695756/3675925

Community
  • 1
  • 1
Hamid Zandi
  • 2,714
  • 24
  • 32