When I am trying to Build an Android Library Project in Android Studio, I am getting the following Gradle error:
Gradle sync failed: Plugin with id 'com.android.library' not found.
I am pretty 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'
}
In my case was due to wrong sdk/ndk paths inside local.properties file, i moved the project from an hd to another and these settings were wrong, fixing the paths fixed the problem.
Assuming you have a standard project structure like the following:
Your failure to sync seems to indicate an issue with your SDK/IDE config.
Start by opening the "Project Structure" dialog and ensure that the "Android SDK location:" value is set to the correct path.
Second, open the SDK manager and again ensure that you have the correct SDK location path set.
Third, verify that you have the correct version of the "Android SDK Build-Tools" package installed. (23.0.2 in this case)
Finally just to verify that we don't have any bad state I recommend doing an "Invalidate and Restart" from File -> "Invalidate Caches /Restart..."
After all of this I expect that it should sync up. If not try to run
./gradlew
from the root of your project and update us with any new information.Your issue is that you are using the top-level file where you can't use this kind of plugin.
In AS you have a structure like this:
In your top-level file you can use:
In your
lib/build.gradle
you can use the code posted in the question:Finally in your
settings.gradle
Also you can refer this question.
Add these lines to gradle file of library.