Android Studio Gradle 1.1 和 Roboeletric

标签 android testing android-studio gradle

我很难让带有 gradle 1.1 的 AS 与 Roboeletric 一起工作。我已经阅读了一些教程并尝试了一些方法,但都没有奏效。

这是我的项目 build.gradle 文件:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        classpath 'org.robolectric:robolectric-gradle-plugin:1.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

robo eletric 已下载,这是我的模块 build.gradle:

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "br.com.boozeprice"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

apply plugin: 'org.robolectric'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.android.support:support-v4:21.0.3'

    compile project(':androidcore')
    compile project(':persistencecore')

    testCompile 'junit:junit:4.12'
    testCompile 'org.robolectric:robolectric:2.4'
}

gradle 编译,但它看到我在项目中没有库,我不能导入 roboeletric 类,也不能导入它们的注释。

我错过了什么吗?

提前谢谢你。

最佳答案

我所做的就是更改 gradle 文件中的这一行:

testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:2.4'

对此:

androidTestCompile 'junit:junit:4.12'
androidTestCompile 'org.robolectric:robolectric:2.4

现在就像一个魅力

关于Android Studio Gradle 1.1 和 Roboeletric,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29336466/

相关文章:

android - Material 设计图标要下载什么包?

testing - 运行 TestCafe 时,页面似乎没有加载

android - 无法在 Android Studio 2.3 上启动 AVD

更改sdk路径后Android studio报错

java - 如何在Android Java中制作一行2个按钮和一列2个按钮?

android - ViewPager 显示 fragment 的问题

git - 如何处理 git 中的测试提交?

java - 如何在 Spock groovy 中模拟 RequestEntity.put() 和 restTemplate.exchange()

android - 如何使用 android studio 3.0 设置 GCE 开发服务器

java - 函数removeAnnotation的参数是什么