【问题标题】:Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'com.android.application']原因:org.gradle.api.internal.plugins.PluginApplicationException:无法应用插件 [id 'com.android.application']
【发布时间】:2019-12-13 08:50:22
【问题描述】:

Android Studio 3.6

build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.AA_VERSION = '4.4.0'
    ext.kotlin_version = '1.2.21'
    ext.BUTTER_KNIFE_VERSION = '8.8.1'
    ext.GLIDE_VERSION = '4.2.0'

    repositories {
        google()
        jcenter()
    }
    dependencies {
       classpath 'com.android.tools.build:gradle:3.6.0-beta05'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

在 app/build.gradle 中

  buildscript {
        repositories {
            maven { url 'https://maven.fabric.io/public' }
        }
    }

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android-extensions'
    apply plugin: 'kotlin-android'

    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    def keystoreProperties = new Properties()
    keystoreProperties.load(new FileInputStream(rootProject.file("app/keystore.properties")))

    android {
        dataBinding {
            enabled = true
        }
        // Configure only for each module that uses Java 8
        // language features (either in its source code or
        // through dependencies). E.g. lambda expressions.
        compileOptions {
            targetCompatibility JavaVersion.VERSION_1_8
            sourceCompatibility JavaVersion.VERSION_1_8
        }
        compileSdkVersion 29
        defaultConfig {
        applicationId "com.myproject"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "0.0.1"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    def anko_version = '0.10.4'

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:26.1.0'
        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
        implementation 'com.android.support:design:26.1.0'
        implementation "com.github.bumptech.glide:glide:$GLIDE_VERSION"
        implementation 'org.greenrobot:eventbus:3.0.0'
        implementation "com.jakewharton:butterknife:$BUTTER_KNIFE_VERSION"
        implementation 'com.journeyapps:zxing-android-embedded:3.5.0'
        implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
        implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
        implementation 'com.squareup.retrofit2:retrofit:2.3.0'
        implementation "org.androidannotations:androidannotations-api:$AA_VERSION"
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
        implementation "org.jetbrains.anko:anko:$anko_version"

        annotationProcessor "com.jakewharton:butterknife-compiler:$BUTTER_KNIFE_VERSION"
        annotationProcessor "org.androidannotations:androidannotations:$AA_VERSION"

        implementation project(':common')

        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.1'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
        androidTestImplementation 'com.squareup.okhttp:mockwebserver:2.7.0'
    }

但从 Android Studio 启动时出现错误:

Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'com.android.application']

但是当像这样从控制台启动时:

gradlew build

我收到另一个错误:

 Build file 'D:\dev\mobile\TAgent\app\build.gradle' line: 7

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.internal.version-check']
   > Cannot parse project property android.enableD8='true ' of type 'class java.lang.String' as boolean. Expected 'true' or 'false'.

在这一行:

apply plugin: 'com.android.application'

【问题讨论】:

  • 你应该修复applicationId "com.myproject "上的格式
  • 没有帮助。同样的错误
  • 我知道,我只是在说 :) 你是在制作模块还是应用程序?
  • 您是否检查过android.enableD8='true ' 是否使用像android.enableD8=true 这样的布尔值?
  • @ישואוהבאותך 是的,这个帮助。从 gradle.properties 中删除“android.enableD8=true”后项目成功构建并运行

标签: android android-studio-3.0


【解决方案1】:

org.gradle.api.internal.plugins.PluginApplicationException: 您通常会收到此信息,因为您尝试使用的插件版本与所需的 Gradle 版本不匹配。

查看下面的链接以找到可以指导您的列表,它肯定解决了我的问题 https://developer.android.com/studio/releases/gradle-plugin

获得 Gradle 版本后,导航到 gradle-wrapper.properties 并编辑 distributionUrl。干杯

【讨论】:

    【解决方案2】:

    Gradle 是一个构建工具,而 android gradle plugin 是一个插件。 他们的版本有一些关系:

    https://developer.android.com/studio/releases/gradle-plugin#updating-gradle

    插件版本太新和gradle版本太旧时会出现这个问题。

    一种解决方案: 打开根 build.gradle 文件,然后像这样更改 android gradle 插件的版本:

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

    如果这不起作用,请将该版本更小,直到某个版本起作用。

    【讨论】:

      猜你喜欢
      • 2021-06-26
      • 2016-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多