I'm using Mac, Android Studio(0.3.6), Robolectric 2.2, Android Annotations 2.7.1, Junit 4.10.
I just built up my project with Android Annotations
, so I can see the activity that is using @EActivity(R.layout.activity_some)
like
@EActivity(R.layout.activity_some)
public class SomeActivity extends ActionBarActivity implements View.OnClickListener{
// ...
}
on the device.
However, something happened in my Robolectric tests. All tests passed before using Android Annotations
.
I always test with the command ../gradlew clean check
in Terminal,
and it shows
: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
...
One of the tests is this.
@RunWith(RobolectricGradleTestRunner.class)
public class SomeActivityTest {
SomeActivity someActivity;
@Before
public void setUp() {
ShadowLog.stream = System.out;
someActivity = Robolectric.buildActivity(SomeActivityTest.class).create().visible().get();
// ...
Like SomeActivityTest, all tests containing Robolectric stuff failed because of NullPointException at onCreate() of Activities.
My main code worked on Android Studio, but Robolectric test code using command in Terminal failed. I think it's about compile timing with my build.gradle file.
in my build.gradle file I copy & paste the Android Annotations
part
// ... 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()
}
}
Do you guys have an idea for this? Please help me :)