找不到符号:classAndActivity_(Android Annotations)在Robolectric Test的compileDebug中

时间:2013-12-04 15:34:20

标签: android unit-testing junit robolectric android-annotations

我正在使用Mac,Android Studio(0.3.6),Robolectric 2.2,Android Annotations 2.7.1,Junit 4.10。

我刚用Android Annotations构建了我的项目,因此我可以看到正在使用@EActivity(R.layout.activity_some)的活动

@EActivity(R.layout.activity_some)
public class SomeActivity extends ActionBarActivity implements View.OnClickListener{
    // ...
}

在设备上。

然而,我的Robolectric测试中发生了一些事情。在使用Android Annotations之前通过了所有测试。

我总是在终端中使用命令../gradlew clean check进行测试, 并显示

:MyProject:clean
:MyProject:preBuild UP-TO-DATE
:MyProject:preDebugBuild UP-TO-DATE
:MyProject:preReleaseBuild UP-TO-DATE
:MyProject:prepareComAndroidSupportAppcompatV71900Library
:MyProject:prepareDebugDependencies
:MyProject:compileDebugAidl
:MyProject:compileDebugRenderscript
:MyProject:generateDebugBuildConfig
:MyProject:mergeDebugAssets
:MyProject:mergeDebugResources
:MyProject:processDebugManifest
:MyProject:processDebugResources
:MyProject:generateDebugSources
:MyProject:compileDebug
/Users/StevenKim/AndroidStudio/MyProject/MyProject/src/main/java/com/sk/myproject/alarm/listview/item/MNAlarmItemClickListener.java:8: cannot find symbol
symbol  : class SomeActivity_
location: package com.sk.myproject.alarm.pref
import com.sk.myproject.alarm.pref.SomeActivity_;
                                         ^
Note: Starting AndroidAnnotations annotation processing
Note: AndroidManifest.xml file found: /Users/StevenKim/AndroidStudio/MyProject/MyProject/build/manifests/debug/AndroidManifest.xml
Note: Number of files generated by AndroidAnnotations: 1
Note: Generating source file: com.sk.myproject.alarm.pref.SomeActivity_
Note: Time measurements: [Whole Processing = 453 ms], [Extract Manifest = 158 ms], [Process Annotations = 116 ms], [Extract Annotations = 51 ms], [Find R Classes = 50 ms], [Generate Sources = 38 ms], [Validate Annotations = 37 ms], 
Note: Time measurements: [Whole Processing = 0 ms], 
Note: Time measurements: [Whole Processing = 0 ms], 
warning: The following options were not recognized by any processor: '[androidManifestFile]'
Note:     /Users/StevenKim/AndroidStudio/MyProject/MyProject/src/main/java/com/sk/myproject/common/size/MNViewSizeMeasure.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:MorningKit:compileTestDebugJava
Note: Starting AndroidAnnotations annotation processing
:MyProject:copyDebugTestResources
:MyProject:processTestDebugResources UP-TO-DATE
:MyProject:testDebugClasses
:MyProject:testDebug

com.sk.myproject.alarm.listview.MNAlarmListViewTest > mainAlarmListAdaptorTest STARTED

com.sk.myproject.alarm.listview.MNAlarmListViewTest >         mainAlarmListAdaptorTest FAILED

...

其中一项测试是这样的。

@RunWith(RobolectricGradleTestRunner.class)
public class SomeActivityTest {

    SomeActivity someActivity;

    @Before
    public void setUp() {
        ShadowLog.stream = System.out;

        someActivity = Robolectric.buildActivity(SomeActivityTest.class).create().visible().get();

// ...

与SomeActivityTest一样,所有包含Robolectric内容的测试都因为onCreate()活动中的NullPointException而失败。

我的主要代码适用于Android Studio,但使用终端命令的Robolectric测试代码失败。我认为这与我的build.gradle文件的编译时间有关。

在我的build.gradle文件中我复制&粘贴Android Annotations部分

// ... etc

ext.androidAnnotationsVersion = '2.7.1';

configurations {
    apt
}

dependencies {

    // ... etc

    // Android Annotations part
    apt "com.googlecode.androidannotations:androidannotations:${androidAnnotationsVersion}"
    compile "com.googlecode.androidannotations:androidannotations-api:${androidAnnotationsVersion}"

}

def getSourceSetName(variant) {
    return new File((String)variant.dirName).getName();
}

android.applicationVariants.all { variant ->
    def aptOutputDir = project.file("build/source/apt")
    def aptOutput = new File(aptOutputDir, variant.dirName)
    println "****************************"
    println "variant: ${variant.name}"
    println "manifest:  ${variant.processResources.manifestFile}"
    println "aptOutput:  ${aptOutput}"
    println "****************************"

    android.sourceSets[getSourceSetName(variant)].java.srcDirs+= aptOutput.getPath()

    variant.javaCompile.options.compilerArgs += [
            '-processorpath', configurations.apt.getAsPath(),
            '-AandroidManifestFile=' + variant.processResources.manifestFile,
            '-s', aptOutput
    ]

    variant.javaCompile.source = variant.javaCompile.source.filter { p ->
        return !p.getPath().startsWith(aptOutputDir.getPath())
    }

    variant.javaCompile.doFirst {
        aptOutput.mkdirs()
    }
}

你们有这个想法吗?请帮帮我:)。

0 个答案:

没有答案