简体   繁体   English

Android Studio 0.8.1机器人设置

[英]Android Studio 0.8.1 Robolectric Setup

I am trying to get robolectric working for new Android 0.8.1 since currently there is no robolectric gradle 0.12 plugin so I am hoping that .11 will work for now. 我正在尝试让robolectric在新的Android 0.8.1上工作,因为目前没有robolectric gradle 0.12插件,因此我希望.11可以正常工作。

* Problem: *问题:

androidTestCompile 'org.robolectric:robolectric:2.3' androidTestCompile'org.robolectric:robolectric:2.3'

Using the following declaration to compile robolectric, I am unable to find "org.robolectric.*" in my test directory, studio gives "cannot resolve symbol..." error. 使用以下声明编译robolectric,我无法在测试目录中找到“ org.robolectric。*”,studio给出了“无法解析符号...”错误。

According to the following projects you have to manually update the iml file. 根据以下项目,您必须手动更新iml文件。 This is probably not the best solution since updating gradle file overwrites any changes you have made. 这可能不是最佳解决方案,因为更新gradle文件会覆盖您所做的所有更改。

Would appreciate help on this matter!! 希望能对此事有所帮助!! thank you. 谢谢。

* Current project structure is: *当前项目结构为:

   src -> main -> java

   src -> test -> java

* Below is my current build.gradle module file: *以下是我当前的build.gradle模块文件:

apply plugin: 'android-library'
apply plugin: 'robolectric'


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

allprojects {
    repositories {
       jcenter()
    }
}

android {
    compileSdkVersion 16
    buildToolsVersion '19.1.0'
    publishNonDefault true

    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE'
    }

    defaultConfig {
        applicationId 'com.myapp.example.main'
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName '1.0'

    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
    sourceSets {
        androidTest {
            setRoot('src/test/java')
        }
    }
    lintOptions {
        abortOnError false
        disable 'InvalidPackage'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:+'
    compile files('libs/gson-2.2.4.jar')
    compile 'com.google.android.gms:play-services:+'
    compile 'com.android.support:support-v13:+'

    /* Including testing libraries */
    androidTestCompile 'junit:junit:4.10'
    androidTestCompile 'org.robolectric:robolectric:2.3'
}

robolectric {
    // configure the set of classes for JUnit tests
    include '**/*Test.class'

    // configure max heap size of the test JVM
    maxHeapSize = "2048m"
}

It's a bit later for now. 现在过一会儿。 But I ran into this error as well and it turned out the version of Robolectric in my dependencies was outdated. 但是我也遇到了这个错误,结果发现我依赖中的Robolectric版本已经过时了。 After I replaced it with the newest one found here , I fixed the error. 在用这里找到的最新软件替换它之后,我更正了该错误。 Also, you may change the androidTestCompile to testCompile since you're writing unit test here. 另外,由于您在此处编写单元测试,因此您可以将androidTestCompile更改为testCompile You can find the difference between the two here 您可以在这里找到两者之间的区别

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM