[gradle] Android Studio: Plugin with id 'android-library' not found

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?

The answer is


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 {
        jcenter()
    }
    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 {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

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

buildscript {
    repositories {
        jcenter()
    }

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

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


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'
    }
}

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.+'
    }
}

Examples related to gradle

Gradle - Move a folder from ABC to XYZ A failure occurred while executing com.android.build.gradle.internal.tasks Gradle: Could not determine java version from '11.0.2' Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0 Failed to resolve: com.android.support:appcompat-v7:28.0 Failed to resolve: com.google.firebase:firebase-core:16.0.1 com.google.android.gms:play-services-measurement-base is being requested by various other libraries java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion Error - Android resource linking failed (AAPT2 27.0.3 Daemon #0)

Examples related to android-studio

A failure occurred while executing com.android.build.gradle.internal.tasks "Failed to install the following Android SDK packages as some licences have not been accepted" error Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util This version of Android Studio cannot open this project, please retry with Android Studio 3.4 or newer WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' Flutter plugin not installed error;. When running flutter doctor ADB.exe is obsolete and has serious performance problems Android design support library for API 28 (P) not working Flutter command not found How to find the path of Flutter SDK

Examples related to android-build

Installation failed with message Invalid File failed to find target with hash string android-23 What is the difference between compileSdkVersion and targetSdkVersion? Gradle, Android and the ANDROID_HOME SDK location Android Studio: Plugin with id 'android-library' not found How to install Android SDK Build Tools on the command line?

Examples related to build.gradle

Android Material and appcompat Manifest merger failed Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve Android dependency has different version for the compile and runtime Setting up Gradle for api 26 (Android) What's the difference between implementation and compile in Gradle? More than one file was found with OS independent path 'META-INF/LICENSE' Android Studio - Failed to notify project evaluation listener error Gradle error: Minimum supported Gradle version is 3.3. Current version is 3.2 All com.android.support libraries must use the exact same version specification DELETE_FAILED_INTERNAL_ERROR Error while Installing APK

Examples related to gradlew

Gradle: Could not determine java version from '11.0.2' Difference between using gradlew and gradle Android- Error:Execution failed for task ':app:transformClassesWithDexForRelease' Difference between clean, gradlew clean Could not find or load main class org.gradle.wrapper.GradleWrapperMain How/when to generate Gradle wrapper files? Android Studio: Plugin with id 'android-library' not found gradlew: Permission Denied