【问题标题】:Android Gradle plugin 3.0.1 must not be applied to projectAndroid Gradle 插件 3.0.1 不得应用于项目
【发布时间】:2018-06-23 01:16:10
【问题描述】:

当我尝试构建我的项目时,我不断收到此错误。我不知道它有什么问题,我尝试的任何方法都不起作用。

我正在尝试清理、重新启动 Android Studio,并使用 gradlew --stop 停止守护进程。

请帮帮我!

错误:

Android Gradle plugin 3.0.1 must not be applied to project since version 3.0.1 was already applied to this project

模块:应用脚本

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    apply plugin: 'com.android.library'

    defaultConfig {
        applicationId "com.example.joey.projectgenesis"
        minSdkVersion 26
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    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.google.android.gms:play-services-ads:11.8.0'
    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'
    implementation 'com.android.support:gridlayout-v7:26.1.0'
}

项目脚本

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

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'


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

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

gradle.wrapper.properties

#Fri Jan 12 20:21:58 EST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-all.zip

【问题讨论】:

  • 为什么在项目/模块级别的两个 build.gradle 文件中定义相同的值集?从 project.script 中删除。
  • 对不起,我编辑了它,所以项目与模块不同。该帖子现已修复。
  • 在建库吗?
  • remove apply plugin: 'com.android.library' 这样你就可以构建一个应用了

标签: android android-studio gradle android-gradle-plugin build.gradle


【解决方案1】:

如果您只是创建一个应用程序,请删除 apply plugin: 'com.android.library'

如果您要创建库,请将 apply plugin: 'com.android.application' 替换为 apply plugin: 'com.android.library' 并删除 applicationId

Refer this - Creating Android Libraries

【讨论】:

    【解决方案2】:

    我的问题要傻得多。在进行查找和替换时,我已将 versionCode 更新为十进制值。

    旧值:

    versionCode 253 versionName '2.53'

    较新的价值观:

    versionCode 2.54 versionName '2.54'

    versionCode 的 2.54 导致了该问题。将其改回 254 对我有用!

    【讨论】:

      猜你喜欢
      • 2017-12-05
      • 1970-01-01
      • 2013-09-04
      • 1970-01-01
      • 1970-01-01
      • 2016-03-16
      • 2013-06-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多