Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio / gradle: "Could not create plugin of type 'LibraryPlugin'"

I have two modules in Android Studio.

Main is the application and Sub is a library module. Sub is referred from Main with compile project(':Sub') in the gradle script. That works when run from Android Studio. But when run from command line, gradlew says:

Could not create plugin of type 'LibraryPlugin'.
Caused by: java.lang.NoClassDefFoundError: org/gradle/api/artifacts/result/ResolvedComponentResult 

This is the important parts in Main's build.gradle file:

apply plugin: 'android'

buildscript {
    repositories {
        mavenCentral()
        maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots/'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

repositories {
    mavenCentral()
    maven {
        url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
}

task wrapper(type: org.gradle.api.tasks.wrapper.Wrapper) {
    gradleVersion = '1.11'
}

android {
    buildToolsVersion '19.0.3'
}


dependencies {
    compile 'com.android.support:support-v4:13.0.+'
    compile project (':Sub')
}

The Sub gradle file is more or less identical, but has

apply plugin: 'android-library'

instead of 'android'

I have tried with gradle 1.9 and 1.10, but same result.

Anyone knows how to solve this?

like image 225
Roar Skullestad Avatar asked Apr 10 '14 13:04

Roar Skullestad


1 Answers

Verify that your dependencies contains classpath 'com.android.tools.build:gradle:0.9.+' in each gradle.build file (or just put it in the base one and not declare it in the others). Update gradle/wrapper/gradle-wrapper.properties to point to gradle 1.11:

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

If you have any other instances of the gradle-wrapper (such as if you originally made the library project on its own and later added an example app), verify that all instances are updated to point to the same version (each gradle-wrapper.properties file).

like image 178
Ian G. Clifton Avatar answered Oct 06 '22 02:10

Ian G. Clifton