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

查看:103
本文介绍了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 

顶级文件中,您可以使用:

In your 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()
    }
}

在您的 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天全站免登陆