Cannot add a configuration with name 'testCompile' as a configuration with that name already exists

假如想象 提交于 2019-12-01 17:38:23

问题


When updating to gradle plugin 1.1.0 I kept getting the following error

Cannot add a configuration with name 'testCompile' as a configuration with that name already exists

I am also using the Robolectric gradle plugin from here, v0.14.0.

The new gradle 1.1.0 plugin adds additional unit test support, so I suspect the gradle and Robolectric plugins are battling for use of 'testCompile,' though I'm not sure how to resolve this.


回答1:


To fix that issue i did the following:

Added the following to my build gradle script:

 apply plugin: 'org.robolectric'

 dependencies {
    classpath 'org.robolectric:robolectric-gradle-plugin:1.0.0'
 }

This wouldnt work for me with gradle version 1.1.0 though. I had to use 1.1.0-rci which is still only in experimental phase. So i added the following to my project build.gradle:

  dependencies {
    classpath 'com.android.tools.build:gradle:1.1.0-rc1'
}

Ran sync project with gradle files and the issue was corrected. Hope this helps.




回答2:


Looks like the fine people over at Robolectric have updated their plugin to resolve the issue.

Use Robolectric Plugin v1.0.0 and you will be able to update gradle plugin and also run your Robolectric tests.

Here is the discussion on the pull request if you are interested in further information:

https://github.com/robolectric/robolectric-gradle-plugin/issues/128




回答3:


I had the same issue and I fixed it.

In my case I had my

apply:plugin statements below the configurations I have added them above and the already exists issue is fixed.



来源:https://stackoverflow.com/questions/28729576/cannot-add-a-configuration-with-name-testcompile-as-a-configuration-with-that

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!