Android Studio 3.0.1(错误:已应用'java'插件,但它与Android插件不兼容。)

时间:2018-02-10 08:23:48

标签: java android

我最近将我的android工作室更新到3.0.1版本,我的gradle app编译时遇到了问题。 在尝试在android studio 3.0.1上构建我的gradle时出现此错误 Error:The 'java' plugin has been applied, but it is not compatible with the Android plugins.

我已将我的Java开发工具包更新为最新的realese

请帮我一个新手。下面是我的构建脚本。我已将我的Java开发工具包更新到最新的realese

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

buildscript {
repositories {
    google() // Gradle 4.0+////////
    maven { url "https://maven.google.com" } // Gradle < 4.0
}

dependencies {
    classpath "com.android.tools.build:gradle:3.0.1"
}
}
android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.example.android.happybirthday"
    minSdkVersion 16
    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(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.0.0-beta1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:2.2.2'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
}
buildscript {
ext.kotlin_version = '1.2.0'
repositories {
    mavenCentral()
}
dependencies {
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
repositories {
mavenCentral()
}
compileKotlin {
kotlinOptions {
    jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
    jvmTarget = "1.8"
}
}

1 个答案:

答案 0 :(得分:-1)

尝试使用此构建脚本:

//Your root Gradle file
buildscript {
    ext.kotlin_version = '1.2.21'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

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

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



// Your application Gradle file
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

    android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.android.happybirthday"
        minSdkVersion 16
        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'
            }
        }

        testOptions {
            unitTests.returnDefaultValues = true
        }

        compileKotlin {
            sourceCompatibility = JavaVersion.VERSION_1_8
            targetCompatibility = JavaVersion.VERSION_1_8

            kotlinOptions {
                jvmTarget = "1.8"
                apiVersion = "1.2"
                languageVersion = "1.2"
            }
        }
    }
    }


    dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.0.0-beta1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:0.5'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"   
    }