Error:Execution failed for task \':app:preDebugAndroidTestBuild\'.
Conflict with dependency \'com.android.support:support-annotations\' in project \':app\
you can also go for this one.
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
instead of this,
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1'
Based on the documentation:
Both your app APK and its test APK share the same classpath. So, you can get a build error if both APKs depend on different versions of the same library.
So the fix would be to change your
com.android.support:appcompat-v7:26.1.0
to
com.android.support:appcompat-v7:27.1.1