I have tried to test my code with robolectric. Problem is that it has duplicated References. e.g.
java.lang.RuntimeException: java.lang.RuntimeException: Duplica
Finally get the test running. I've excluded all libs with duplicated classes:
testImplementation ("org.robolectric:robolectric:4.3"){
exclude group: 'org.apache.maven', module: 'maven-artifact'
exclude group: 'org.apache.maven', module: 'maven-artifact-manager'
exclude group: 'org.apache.maven', module: 'maven-model'
exclude group: 'org.apache.maven', module: 'maven-plugin-registry'
exclude group: 'org.apache.maven', module: 'maven-profile'
exclude group: 'org.apache.maven', module: 'maven-project'
exclude group: 'org.apache.maven', module: 'maven-settings'
exclude group: 'org.apache.maven', module: 'maven-error-diagnostics'
exclude group: "org.apache.maven.wagon"
}
Not all possibilities tested but a simple test worked already.
The solution for me was to ensure that I was not requiring Robolectric in my androidTestImplementation
dependencies.
Once I fixed that, I did not have any conflicts to fix.
This probably could be written in more general way:
testImplementation ("org.robolectric:robolectric:4.3") {
exclude group "org.apache.maven.wagon"
exclude group "org.apache.maven"
}
or even:
testImplementation ("org.robolectric:robolectric:4.3") {
exclude group: "org.apache.maven", name: "maven-ant-tasks"
}
because it is maven-ant-tasks of pluginapi, which pulls in org.apache.maven
dependencies.
I've encountered the same issue and the thing that helped me was that I had defined the Roboelectric dependency twice in Gradle file one with androidTestImplementation and the other with testImplementation so when I removed the first part problem solved!!!