178

I've been trying to get ActionBarSherlock to work and having some issue. One issue I've come across is the following message when trying to build it:

Plugin with id 'android-library' not found

Specifically:

D:\Projects\Android\actionbarsherlock>D:\Projects\Android\gradlew --info build
Starting Build
Settings evaluated using empty settings script.
Projects loaded. Root project using build file 
  'D:\Projects\Android\actionbarsherlock\build.gradle'.
Included projects: [root project 'actionbarsherlock']
Evaluating root project 'actionbarsherlock' using build file 
  'D:\Projects\Android\actionbarsherlock\build.gradle'.

FAILURE: Build failed with an exception.

* Where:
Build file 'D:\Projects\Android\actionbarsherlock\build.gradle' line: 1

* What went wrong:
A problem occurred evaluating root project 'actionbarsherlock'.
> Plugin with id 'android-library' not found.

I'm treating this as an ABS issue in a seperate thread, so here I'm curious how to address the general issue of:

Plugin with id 'android-library' not found

Here is the build.gradle:

apply plugin: 'android-library'

dependencies {
  compile 'com.android.support:support-v4:18.0.+'
}

android {
  compileSdkVersion 14
  buildToolsVersion '17.0.0'

  sourceSets {
    main {
      manifest.srcFile 'AndroidManifest.xml'
      java.srcDirs = ['src']
      res.srcDirs = ['res']
    }
  }
}

Can you help?

JJD
  • 50,076
  • 60
  • 203
  • 339
Michael
  • 4,010
  • 4
  • 28
  • 49

10 Answers10

287

Instruct Gradle to download Android plugin from Maven Central repository.

You do it by pasting the following code at the beginning of the Gradle build file:

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

Replace version string 1.0.+ with the latest version. Released versions of Gradle plugin can be found in official Maven Repository or on MVNRepository artifact search.

AZ_
  • 21,688
  • 25
  • 143
  • 191
Grzegorz Żur
  • 47,257
  • 14
  • 109
  • 105
  • For more up-to-date info, a higher version number for com.android.tools is definitely recommended, as also mentioned by @Elenasys in a later answer. Otherwise you can run into this problem: https://discuss.gradle.org/t/gradle-thinks-2-10-is-less-than-2-2-when-resolving-plugins/13434 – RenniePet Aug 28 '16 at 14:13
  • 1
    I needed to add this to my *project's* build.gradle, adding it to one module gradle file didn't help – syonip Sep 06 '16 at 14:17
  • How will i know which gradel version i have downloaded to? Btw 1.1.1 works for me – Binil Jacob Dec 08 '16 at 13:08
  • 2
    @binil This is a version of Android Gradle plugin not the Gradle itself. All versions are listed on Maven Repository http://mvnrepository.com/artifact/com.android.tools.build/gradle To list build dependencies run `gradle buildEnvironment` – Grzegorz Żur Dec 08 '16 at 13:15
  • This answer https://stackoverflow.com/a/48451418/2186220, in this thread itself worked for me as of August, 2019. – Bot Aug 30 '19 at 05:27
  • this didn't work for me on android studio 4.2 C15 SDK30 – Miguel Tomás Mar 04 '21 at 21:43
30

Just for the record (took me quite a while) before Grzegorzs answer worked for me I had to install "android support repository" through the SDK Manager!

Install it and add the following code above apply plugin: 'android-library' in the build.gradle of actionbarsherlock folder!

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.+'
    }
}
sergej shafarenka
  • 20,071
  • 7
  • 67
  • 86
Langusten Gustel
  • 10,917
  • 9
  • 46
  • 59
18

Use

apply plugin: 'com.android.library'

to convert an app module to a library module. More info here: https://developer.android.com/studio/projects/android-library.html

IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147
12

In later versions, the plugin has changed name to:

apply plugin: 'com.android.library'

And as already mentioned by some of the other answers, you need the gradle tools in order to use it. Using 3.0.1, you have to use the google repo, not mavenCentral or jcenter:

buildscript {
    repositories {
        ...
        //In IntelliJ or older versions of Android Studio
        //maven {
        //   url 'https://maven.google.com'
        //}
        google()//in newer versions of Android Studio
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}
Zoe
  • 27,060
  • 21
  • 118
  • 148
7

Use mavenCentral() adding in the build.gradle file the script:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'   
    }
}
rekire
  • 47,260
  • 30
  • 167
  • 264
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
6

In addition to previous answers, when using Gradle Kotlin DSL, you should add resolution strategy for Android plugins in your settings.gradle.kts:

pluginManagement {

    repositories {
        google()
        gradlePluginPortal()
    }

    resolutionStrategy {
        eachPlugin {
            if(requested.id.namespace == "com.android") {
                useModule("com.android.tools.build:gradle:${requested.version}")
            }
        }
    }

}

Then, you need to specify plugin version in your build.gradle.kts, e.g.:

plugins {
    id("com.android.library") version "4.1.3"
}

No buildscript is required.

Slav
  • 786
  • 1
  • 13
  • 25
2

For me, on android studio 4.2 C15 SDK30, this is what worked:

buildscript {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
        maven {
            url 'https://mvnrepository.com/artifact/com.android.tools.lint/lint-gradle-api'
        }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.0-beta05"
    }
}
allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://maven.google.com' }
    }
}
rekire
  • 47,260
  • 30
  • 167
  • 264
Miguel Tomás
  • 1,714
  • 1
  • 13
  • 23
1

Add the below to the build.gradle project module:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
rekire
  • 47,260
  • 30
  • 167
  • 264
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203
0

I ran into this issue when I was applying plugin like this in build.gradle:

plugin {
     id 'com.android.library'
     id 'org.jetbrains.kotlin.android'
}

This plugin won't work automatically and you have to add following code in your settings.gradle file.

pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven {
            url 'https://maven.google.com'
        }
    }
}

Even after this it would throw the error of not able to find argument android() which is because of the fact that plugins are not applied automatically so I changed this in build.gradle:

plugins {
    id 'com.android.library' version '7.4.2' apply true
    id 'org.jetbrains.kotlin.android' version '1.8.0' apply true
}

Including apply true at the end worked for me.

-2

Believe it or not, an empty settings.gradle file in the com.android.library module's root directory brought this error back from the grave in Android Studio 4.2.2.

Deleting the empty settings.gradle file fixed it.

Cruceo
  • 6,763
  • 2
  • 31
  • 52