我已将Robolectric添加到Android项目中。我正在使用Build Tools版本为19.0.1的Android Studio。
我可以使用以下命令运行测试:
$./gradlew test
能够成功执行。
如果我尝试:
$ gradle installDebug
它也能顺利执行:
$ ./gradlew installDebug
WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for debugTest as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.3 is ignored for debugTest as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
The Test.testReportDir property has been deprecated and is scheduled to be removed in Gradle 2.0. Please use the Test.getReports().getHtml().getDestination() property instead.
:app:compileDebugNdk
:app:preBuild
:app:preDebugBuild
:app:checkDebugManifest
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:mergeDebugAssets
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:compileDebugJava
:app:preDexDebug
:app:dexDebug
:app:processDebugJavaRes UP-TO-DATE
:app:validateDebugSigning
:app:packageDebug
:app:installDebug
8266 KB/s (46166 bytes in 0.005s)
pkg: /data/local/tmp/app-debug-unaligned.apk
Success
BUILD SUCCESSFUL
Total time: 4.291 secs
然而,当我尝试从Android Studio在设备或模拟器上运行我的项目时,我遇到以下问题:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Applications/Android Studio.app/sdk/build-tools/19.0.1/dx --dex --output /Users/fstephany/Code/android/RoboElectricTestingProject/app/build/dex/debug /Users/fstephany/Code/android/RoboElectricTestingProject/app/build/classes/debug /Users/fstephany/Code/android/RoboElectricTestingProject/app/build/dependency-cache/debug
Error Code:
1
Output:
Unable to locate a Java Runtime to invoke.
有什么线索可以找到这个问题吗?我可以在CLI或Studio中安装installDebug
,但这会妨碍我的工作。
export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home"
(我使用的是OSX),并没有解决问题。 - fstephany