Android Studio 3.4 Hello World错误:已应用'java'插件,但与Android插件不兼容

时间:2019-04-24 11:29:58

标签: android android-studio android-gradle

我刚刚下载并安装了Android Studio 3.4,并根据https://developer.android.com/training/basics/firstapp/creating-project选择Java作为语言创建了一个新项目。

完成向导后,Gradle Sync报告错误:

ERROR: Cannot add task 'clean' as a task with that name already exists.

我在build.gradle中发现一个“干净”的东西,并将其注释掉,并尝试再次同步,从而导致错误

ERROR: The 'java' plugin has been applied, but it is not compatible with the Android plugins.

根目录中的build.gradle:

// 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.4.0'
    }
}
allprojects {
    repositories {
        google()
        jcenter()

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

app / build.gradle:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.myapp"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

上面显示的是项目中唯一build.gradle文件的全部内容。

我尝试使用Kotlin作为语言,结果相同。

关于Stackoverflow的类似问题的解决方案似乎涉及删除apply plugin: 'java',但我在这里看不到。

所以我想我的问题是:我如何打破Android Studio中的Hello World向导?

1 个答案:

答案 0 :(得分:0)

我删除了$ HOME / .gradle文件夹,现在重新下载gradle-wrapper后,它可以按预期工作。显然我在那里有一些旧配置,使gradle混乱不堪。