apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsversion "23.0.3"
defaultConfig {
applicationId "my.com.myapp_android"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
}
repositories {
jcenter()
}
dependencies {
compile filetree(dir: 'libs',include: ['*.jar'])
testCompile 'junit:junit:4.12'
//material design
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
//zxing
compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
compile 'com.google.zxing:core:3.2.1'
//Testing
// Optional -- Mockito framework
testCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'com.android.support:support-annotations:23.3.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.4.1'
// Optional -- Hamcrest library
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
// Optional -- UI testing with Espresso
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'
// Optional -- UI testing with UI Automator
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
//inMarketSDK
//compile group: 'com.inmarket',name: 'm2msdk',version: '2.29',ext: 'aar'
}
错误是这样的:
Error:Conflict with dependency 'com.android.support:support-v4'. Resolved versions for app (23.3.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details. Error:Conflict with dependency 'com.android.support:appcompat-v7'. Resolved versions for app (23.3.0) and test app (23.1.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
紧随其后:link for espresso install
我还试图排除注释依赖:
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.2') {
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support',module: 'support-annotations'
}
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2')
{
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support',module: 'support-annotations'
}
解决方法
新版本的espresso-contrib 2.2.2库现在依赖于com.android.support:appcompat-v7:23.1.1,在我们的编译时依赖项中使用不同版本的appcompat-v7会产生冲突,如下所示:
dependencies {
compile filetree(dir: 'libs',include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'
}
为避免冲突,当我们从espresso-contrib中排除appcompat-v7依赖关系时,由于设计支持lib的某些值依赖性,它会再次中断.
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){
exclude module: 'support-annotations'
exclude module: 'support-v4'
exclude module: 'support-v13'
exclude module: 'recyclerview-v7'
exclude module: 'appcompat-v7'
}
错误:
Error:(69) Error retrieving parent for item: No resource found that matches the given name ‘TextAppearance.AppCompat.display1’.
根本原因:
This is because the
designsupport lib has dependency onappcompat-v7.
So,when we exclude ‘appcompat-v7’ module fromespresso-contribdependencies(like above),thedesignsupport lib downloaded as
part of transitive dependency ofespresso-contriblib Couldn’t find
the compatible version ofappcompat-v7 lib(23.1.1)it is using
internally in its resources files and thus gives out the above error.
因此,上述问题的解决方案是从espresso-contrib中排除“设计支持”的lib依赖性,如下所示:
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){
exclude module: 'support-annotations'
exclude module: 'support-v4'
exclude module: 'support-v13'
exclude module: 'recyclerview-v7'
exclude module: 'design'
}
这解决了冲突问题!
更长版本(如果有人有兴趣):
为了找出我们在使用`espresso-contrib’库时遇到的各种冲突问题的原因,我创建了示例应用程序以找出根本原因.
Step 1:Using Espresso-Contrib Lib version 2.2.1
创建App以通过在app / build.gradle文件中添加以下行来使用’espresso-contrib’lib 2.2.1版:
dependencies {
compile filetree(dir: 'libs',include: ['*.jar'])
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1'
}
注意:在这种情况下,我没有导入任何其他支持库组件,如
程序兼容性-V7,recyclerview-V7等.
上述设置的依赖关系图如下所示:
可以看出,espresso-contrib 2.2.1lib对23.0.1版本具有传递依赖性
support-v4,recyclerview-v7,support-annotations等.
由于我没有为recyclerview-v7定义依赖项,在我的项目中支持注释,上面的设置可以正常工作.
但是当我们在项目中将它们定义为编译依赖项[如下面]时,我们会遇到问题中所述的版本冲突问题.
compile 'com.android.support:appcompat-v7:23.3.0' compile 'com.android.support:support-v4:23.3.0'
为了避免这些冲突,我们将以下行添加到espresso-contrib lib中:
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.1'){
exclude module: 'support-annotations'
exclude module: 'support-v4'
exclude module: 'support-v13'
exclude module: 'recyclerview-v7'
}
这可以确保不会将这些依赖项作为espresso-contrib传递依赖项的一部分下载.
以上设置一切正常.没有问题!
Step 2: Using Espresso-Contrib lib version 2.2.2
通过更改以前的build.gradle文件,将App的build.gradle更改为使用’espresso-contrib’lib 2.2.2版:
dependencies {
compile filetree(dir: 'libs',include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
testCompile 'junit:junit:4.12'
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){
exclude module: 'support-annotations'
exclude module: 'support-v4'
exclude module: 'support-v13'
exclude module: 'recyclerview-v7'
}
}
但是当我使用上面的setup..build构建项目失败并发布了错误的错误..
错误:
Error:Conflict with dependency ‘com.android.support:appcompat-v7’. Resolved versions for app (23.3.0) and test app (23.1.1) differ. See 07001 for details.
所以,看错误我在build.gradle上面添加了一行:
exclude module: 'appcompat-v7' (inside androidTestCompile block of espresso-contrib)
但这并没有解决冲突问题,我在评论中发布了价值依赖性错误.
所以我再次检查我的应用程序的依赖图:
现在可以看出espresso-contrib 2.2.2 lib现在对com.android.support:design:23.1.1具有传递依赖性,导致上述冲突.
所以,我们需要在androidTestCompile(‘com.android.support.test.espresso:espresso-contrib:2.2.2’)块中添加以下行:
exclude module: 'design'
这解决了lib 2.2.2版中的冲突问题!