“java”插件与Android插件不兼容

前端之家收集整理的这篇文章主要介绍了“java”插件与Android插件不兼容前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我安装了 Android studio并创建了一个简单的应用程序后,我收到了错误.

步骤如下:

>新鲜下载&安装了Android studio.
>创建一个新项目.

当项目加载时,毕业生失败,错误

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

模块Gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "info.ankitjc.happybirthday"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs',include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',{
        exclude group: 'com.android.support',module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.0'
    testCompile 'junit:junit:4.12'
}

Project Gradle文件

// 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:2.2.3'

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

allprojects {
    repositories {
        jcenter()
    }
}

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

我在这里寻找可能的解决方案.

> Android compile error; Java plugin has been applied,not compatible with android
> Gradle error “Java plugin is not compatible with android plugins”

文件>无效缓存/重新启动

After File ></p> Invalidate Cache/Restart

解决方法

androidTestCompile可以抛出你这个错误
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',{
            exclude group: 'com.android.support',module: 'support-annotations'
        })

将androidTestCompile更改为testCompile

两者之间的主要区别是测试源运行在常规Java JVM中,而AndroidTest源集测试则在Android设备(或仿真器)上运行.就像冲突一样!

如果它没有任何机会

删除testInstrumentationRunner“android.support.test.runner.AndroidJUnitRunner”

可能会发生错误,因为它不允许您在同一版本中与两个测试运行程序一起运行测试.

原文链接:https://www.f2er.com/java/122806.html

猜你在找的Java相关文章