Android Studio中的Gradle错误:找不到id为'com.android.library'的插件 [英] Gradle Error in Android Studio: Plugin with id 'com.android.library' not found

查看:2391
本文介绍了Android Studio中的Gradle错误:找不到id为'com.android.library'的插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在Android Studio中构建Android库项目时,出现以下Gradle错误:

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.

我对Gradle很新颖,这对我来说非常混乱。为什么会发生这种情况?

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

build.gradle文件如下:

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


推荐答案

正在使用顶级文件,您无法使用此类插件

Your issue is that you are using the top-level file where you can't use this kind of plugin.

在AS中你有这样的结构:

In AS you have a structure like this:

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

您可以在您的顶级文件中使用:

// 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()
    }
}

lib / build.gradle 中,您可以使用代码发布在问题中:

In your lib/build.gradle you can use the code posted in 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'
}

最后在 settings.gradle

include ':lib'

你也可以参考这个问题

这篇关于Android Studio中的Gradle错误:找不到id为'com.android.library'的插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆