Gradle error “Java plugin is not compatible with a

2019-09-10 05:27发布

问题:

I am trying to run my testng tests through gradle on Android studio. I have source code and tests placed in the gradle file using unitTest gradle feature. So to use the test task i have to apply java plugin but android studio is giving me an error saying "Java plugin is not compatible with android plugins". I know android and java plugins are not compatible with each other, but is there any solution for it? This is my build.gradle looks like

apply plugin: 'com.android.application'
apply plugin: 'java'
dependencies {
    // Android Support Library
    compile 'com.android.support:support-v4:21.0.3'
    androidTestCompile 'org.testng:testng:6.8.7'
    androidTestCompile 'dom4j:dom4j:1.6.1'
    androidTestCompile 'org.seleniumhq.selenium:selenium-server:2.44.0'
    androidTestCompile 'jaxen:jaxen:1.1.6'
    androidTestCompile 'io.appium:java-client:2.2.0'
}

test {

    useTestNG()
    //options.suites("src/androidTest/res/groups.xml")

}

回答1:

As I said in the comments you don't need the Java plugin for testing; Android Studio already has built-in support for testing (as of 1.1). So I suggest you taking a look at the Android Studio testing support which you can find here. It is described very nicely how to install and use (with screenshots).



回答2:

It works by changing the androidTestCompile to testCompile