Android Studio (Gradle) 找不到 Mockito [英] Android Studio (Gradle) cannot find Mockito

查看:91
本文介绍了Android Studio (Gradle) 找不到 Mockito的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 Android Studio 1.2.2 中使用 Mockito,但出现以下错误:

I try to use Mockito from within Android Studio 1.2.2 but I get the following error:

错误:(50, 17) 无法解析:org.mockito:mockito-core:1.10.19

Error:(50, 17) Failed to resolve: org.mockito:mockito-core:1.10.19

手动添加依赖后同步 Gradle 时发生错误.这是我的模块 Gradle 文件中的依赖项:

The error occurs when I sync Gradle after adding the dependency manually. This is the dependency in my module Gradle file:

    dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.0'
    testCompile 'org.mockito:mockito-core:1.10.19' 
}

有人能帮我解决这个问题吗?

Could anyone help my resolve this issue?

相关问题:

  1. 我是否首先需要手动下载 Mockito?
  2. 如果是这样,我应该把它放在哪里?

注意:评论对解决上述问题很有帮助.然而,它让我陷入了另一个我无法解决的问题.但是更新到 Android Studio 1.3 解决了它.我现在正在 Android Studio 中运行 Mockito.

Note: the comments were helpfull to solve the above problem. However, it got me into another problem which I could not solve. But updating to Android Studio 1.3 solved it. I am now running Mockito from within Android Studio.

推荐答案

尝试将 testCompile 替换为 androidTestCompile,它在导入 Mockito 库时对我有用.

Try replacing testCompile with androidTestCompile, it works for me when importing Mockito libs.

但是,如果仅包含 mockito-core,则可能会遇到运行时错误.您需要添加到您的 gradle 中:

However, you may run to a runtime error if you include only mockito-core. You'll need to add into your gradle:

androidTestCompile "org.mockito:mockito-core:1.10.19"
androidTestCompile "com.google.dexmaker:dexmaker:1.2"
androidTestCompile "com.google.dexmaker:dexmaker-mockito:1.2"

如果 dexcache 出错,请将此行放入您的 setUp()(假设您使用的是 InstrumentalTestCase)

If you have error with dexcache, put this line into your setUp() (Assuming you are using InstrumentalTestCase)

System.setProperty("dexmaker.dexcache", getInstrumentation().getTargetContext().getCacheDir().getPath());

这篇关于Android Studio (Gradle) 找不到 Mockito的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆