My orignal app.gradle had:
dependencies {
// App dependencies
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
// Testing-only dependencies
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
}
which resulted in following error:
Error:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.4.0) and test app (22.2.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
After reading the link suggested in error, I found theses lines:
When instrumentation tests are run, both the main APK and test APK
share the same classpath. Gradle build will fail if the main APK and
the test APK use the same library (e.g. Guava) but in different
versions. If gradle didn't catch that, your app could behave
differently during tests and during normal run (including crashing in
one of the cases).
So I modified my app.gradle dependencies to:
dependencies {
// App dependencies
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
// Testing-only dependencies
androidTestCompile 'com.android.support:support-annotations:23.3.0'
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
}
Even after the above change gradle was not happy :-(:
Error:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.4.0) and test app (23.3.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
Change in test apk version was different! So I modified the version string as pasted below which worked for me:
(Nirvana)
dependencies {
// App dependencies
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0' // main APK
// Testing-only dependencies
androidTestCompile 'com.android.support:support-annotations:23.4.0' //test APK
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
}