Gradle Error in Android Studio: plugin with id 'com.android.library' not found

When I try to create an Android library project in Android Studio, I get the following Gradle error:

Gradle sync failed: Plugin with id 'com.android.library' not found. 

I am new to Gradle and this is very confusing for me. Why is this happening?

The build.gradle file is as follows:

 apply plugin: 'com.android.library' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { minSdkVersion 8 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.0' } 
+6
source share
4 answers

Your problem is that you are using a top-level file where you cannot use this kind of plugin.

In AS, you have this structure:

 Root/ + lib | build.gradle | build.gradle | settings.gradle 

In the top level file you can use:

 // 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:1.3.1' } } allprojects { repositories { jcenter() } } 

In your lib/build.gradle you can use the code sent to the question:

 apply plugin: 'com.android.library' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { minSdkVersion 8 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.0' } 

Finally, in settings.gradle

 include ':lib' 

You can also refer to this question .

+12
source

Assuming you have a standard project structure, such as:

 yourProject/ + .idea/ + gradle/wrapper/ + lib-module/ | build.gradle | build.gradle | gradlew | gradlew.bat | settings.gradle 

Failure to synchronize seems to indicate a problem with the SDK / IDE configuration.

Start by opening the "Project Structure" dialog and make sure that the "Android SDK location:" value is set to the correct path.

Secondly, open the SDK manager and again make sure that you have the correct SDK location path set.

Third, make sure you have the correct version of the Android SDK Build-Tools installed. (23.0.2 in this case)

Finally, to make sure we don’t have a bad condition, I recommend making "Invalidate and Restart" from "File" β†’ "Invalidate Caches / Restart ..."

After all this, I expect it to sync. If you do not try to run ./gradlew from the root of your project and update us with any new information.

+2
source
 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:1.3.0' } } apply plugin: 'com.android.library' 

Add these lines to the gradle library file.

0
source

In my case, due to incorrect sdk / ndk paths in the local.properties file, I moved the project from hd to another, and these settings were incorrect, fixing the paths fixed the problem.

0
source

All Articles