我正在尝试学习 android espresso ..我遵循了一些基本的教程,它工作正常.但现在我想在android导航抽屉上做一些测试.为此,我需要使用gradle依赖androidTestCompile’c​​om.android.support.test.espresso:espresso-contrib:2.2.2′,但它导致与其他依赖项冲突.我的gradle文件:
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'
        }

解决方法

TL; DR;

新版本的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 design support lib has dependency on
appcompat-v7.
So,when we exclude ‘appcompat-v7’ module from
espresso-contrib dependencies(like above),the design support lib downloaded as
part of transitive dependency of espresso-contrib lib Couldn’t find
the compatible version of appcompat-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版中的冲突问题!

android-gradle – Android espresso-contrib gradle build失败的更多相关文章

  1. android – 使用Gradle构建本机代码时会删除符号

    )或者我错过了什么?解决方法符号位于:src/main/obj/local所以添加到build.grade:然后转到DebugConfiguration->调试器并添加到Symbol目录:应用程序/建立/中间体/jniLibs之后我能够调试我的本机代码.

  2. Android studio – Faild to resolve:com.android.support:design:26.0.1错误

    我有一个错误叫:我的androidstudio版本是3.0beta1.我的gradle文件如下:我想把“设计”放到我的项目中,但我不能这样做.我该怎么做?解决方法尝试改变和或者不要更改为bulidToolsversion更改依赖项

  3. android-studio – IDEA中Gradle自动完成的位置在哪里?

    解决方法对于Groovy插件,它可能是Cucumber.我知道Gradle使用Groovy的一些技术和语法,所以我尝试在第一次尝试时安装一些Groovy插件并取得成功.安装此插件的步骤:>在MacOS上:首选项…

  4. Android L上片段的Lint错误:“此方法不会覆盖任何内容”

    klwQWQ6Z!

  5. 在Android中启用MultiDex支持以在Eclipse中实现65K方法

    我正在尝试在eclipse中构建Multidexapk,但无法成功.我尝试了以下步骤,在Android应用程序中配置Multidex支持:>我已将位于/extras/android/support/multidex/的Multidex库添加到我的项目中.>由于我的应用程序具有自定义应用程序类,我已将android.support.multidex.MultiDexApplication类扩展到我的

  6. Android Studio导入模块Gradle构建错误

    我试图在AndroidStudio(GameBaseUtils)中添加一个目录作为依赖项.我已经看到其他SO答案只是为他们的特定问题发布正确的gradle配置,但是我不明白我如何能够根据我的情况调整他们的答案.这是我做的:第一步:文件–>导入模块–>导航到目录并选择它.第二步–文件–>项目结构–>模块–>选择我的应用程序–>依赖关系–>将模块添加为我的项目的依赖项.现在我的代码没有任何红线表示导入

  7. Android Studio 3.0 – 对于externalNativeBuild,Gradle Sync失败

    当我迁移到Androidstudio3.0时,我得到以下回溯我的build.gradle就在这里.任何帮助深表感谢!

  8. android-gradle – Android espresso-contrib gradle build失败

    我正在尝试学习androidespresso..我遵循了一些基本的教程,它工作正常.但现在我想在android导航抽屉上做一些测试.为此,我需要使用gradle依赖androidTestCompile’com.android.support.test.espresso:espresso-contrib:2.2.2′,但它导致与其他依赖项冲突.我的gradle文件:错误是这样的:紧随其后:linkf

  9. android – 依赖项 – >无法创建’AppPlugin’类型的插件

    我正在尝试继续研究我的一个旧项目,它已经有一年的历史了,当时工作正常,但是现在我已经更新了AndroidStudio,它甚至无法构建.我收到一个错误,说我有两次相同的dex文件:为了解决这个问题,我可以简单地做’gradledependencies’来查找罪魁祸首,并排除故障文件,但这是我遇到实际问题的地方.当我’gradledependencies’时,我收到以下错误:这是我的完整build.g

  10. Android Studio:Gradle Build运行3分钟

    请提供有关如何解决此问题的任何建议.谢谢:)解决方法我发现了为什么会这样.这是因为我在onCreate函数()中解析XML,并且因为XML有70,000行,所以编译器需要很长时间.但是将文件移动到“assets”文件夹后,问题就解决了.这是我的错误,与gradle设置无关,但如果有人遇到类似的问题,我建议你尝试我上面列出的所有内容,你的gradle构建应该运行得更快.

随机推荐

  1. bluetooth-lowenergy – Altbeacon库无法在Android 5.0上运行

    昨天我在Nexus4上获得了Android5.0的更新,并且altbeacon库停止了检测信标.似乎在监视和测距时,didEnterRegion和didRangeBeaconsInRegion都没有被调用.即使RadiusNetworks的Locate应用程序现在表现不同,一旦检测到信标的值,它们就不再得到更新,并且通常看起来好像信标超出了范围.我注意到的一点是,现在在logcat中出现以下行“B

  2. android – react-native动态更改响应者

    我正在使用react-native进行Android开发.我有一个视图,如果用户长按,我想显示一个可以拖动的动画视图.我可以使用PanResponder实现这一点,它工作正常.但我想要做的是当用户长按时,用户应该能够继续相同的触摸/按下并拖动新显示的Animated.View.如果您熟悉Google云端硬盘应用,则它具有类似的功能.当用户长按列表中的任何项目时,它会显示可拖动的项目.用户可以直接拖

  3. android – 是否有可能通过使用与最初使用的证书不同的证书对其进行签名来发布更新的应用程序

    是否可以通过使用与最初使用的证书不同的证书进行签名来发布Android应用程序的更新?我知道当我们尝试将这样的构建上传到市场时,它通常会给出错误消息.但有没有任何出路,比如将其标记为主要版本,指定市场中的某个地方?解决方法不,你不能这样做.证书是一种工具,可确保您是首次上传应用程序的人.所以总是备份密钥库!

  4. 如何检测Android中是否存在麦克风?

    ..所以我想在让用户访问语音输入功能之前检测麦克风是否存在.如何检测设备上是否有麦克风.谢谢.解决方法AndroidAPI参考:hasSystemFeature

  5. Android – 调用GONE然后VISIBLE使视图显示在错误的位置

    我有两个视图,A和B,视图A在视图B上方.当我以编程方式将视图A设置为GONE时,它将消失,并且它正下方的视图将转到视图A的位置.但是,当我再次将相同的视图设置为VISIBLE时,它会在视图B上显示.我不希望这样.我希望视图B回到原来的位置,这是我认为会发生的事情.我怎样才能做到这一点?编辑–代码}这里是XML:解决方法您可以尝试将两个视图放在RelativeLayout中并相对于彼此设置它们的位置.

  6. android – 获得一首歌的流派

    我如何阅读与歌曲相关的流派?我可以读这首歌,但是如何抓住这首歌的流派,它存放在哪里?解决方法检查此代码:

  7. android – 使用textShadow折叠工具栏

    我有一个折叠工具栏的问题,在展开状态我想在文本下面有一个模糊的阴影,我使用这段代码:用:我可以更改textColor,它可以工作,但阴影不起作用.我为阴影尝试了很多不同的值.是否可以为折叠文本投射阴影?

  8. android – 重用arm共享库

    我已经建立了armarm共享库.我有兴趣重用一个函数.我想调用该函数并获得返回值.有可能做这样的事吗?我没有任何头文件.我试过这个Android.mk,我把libtest.so放在/jni和/libs/armeabi,/lib/armeabi中.此时我的cpp文件编译,但现在是什么?我从objdump知道它的名字编辑:我试图用这个android.mk从hello-jni示例中添加prebuild库:它工作,但libtest.so相同的代码显示以下错误(启动时)libtest.so存在于libhello-j

  9. android – 为NumberPicker捕获键盘’Done’

    我有一个AlertDialog只有一些文本,一个NumberPicker,一个OK和一个取消.(我知道,这个对话框还没有做它应该保留暂停和恢复状态的事情.)我想在软键盘或其他IME上执行“完成”操作来关闭对话框,就像按下了“OK”一样,因为只有一个小部件可以编辑.看起来处理IME“Done”的最佳方法通常是在TextView上使用setonEditorActionListener.但我没有任何Te

  10. android – 想要在调用WebChromeClient#onCreateWindow时知道目标URL

    当我点击一个带有target=“_blank”属性的超链接时,会调用WebChromeClient#onCreateWindow,但我找不到新的窗口将打开的新方法?主页url是我唯一能知道的东西?我想根据目标网址更改应用行为.任何帮助表示赞赏,谢谢!

返回
顶部