问题描述
我添加Robolectric到Android项目。我使用的是Android的工作室生成工具在19.0.1。
I've added Robolectric to an Android project. I'm using Android Studio with Build Tools in 19.0.1.
我可以运行测试:
$./gradlew test
这执行罚款。
Which execute fine.
如果我尝试:
$ gradle installDebug
这执行罚款,以及:
It executes fine as well:
$ ./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
然而,当我试图在设备或仿真的机器人工作室上运行我的项目,我得到如下:
However when I'm trying to run my project on a device or emulator from Android Studio, I get the following:
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.
在哪里寻找这个问题的任何提示?我总能 installDebug
然后开始从CLI或Studio中的应用程序,但它的凑了过来。
Any hint on where to look for this issue? I can always installDebug
then start the app from CLI or Studio but it's getting in the way.
推荐答案
这是过期的摇篮守护进程可能会导致在后台的一些性能问题。我想摇篮会3个小时的闲置后,它清理干净,但似乎并非如此。去到终端,到项目的根文件夹,摇篮文件,并键入命令
An expired gradle daemon may be causing some performance issues in the background. I thought gradle would clean it up after 3 hours of being idle, but that seems to not be the case. Go to your terminal, go to your project's root folder where the gradle files are, and type in the command
./gradlew --stop
和尝试重新运行您的构建。希望能解决你的问题,像它做我的。
and try running your build again. Hopefully that resolves your issue like it did mine.
我试图理解为什么这引起了一个问题,但我还没有找到足够的理由呢。我将编辑答案,如果我发现任何东西。
I'm trying to understand why this caused an issue, but I haven't found a good enough reason yet. I'll edit the answer if I find anything.
更新
在<一个href="https://github.com/gradle/gradle/blob/master/design-docs/daemon-improvements.md#daemon-feature-is-usable-when-under-memory-$p$pssure">Gradle设计Github上页:
目前,该守护程序存在严重问题时,内存pressure发生。当在pressure,守护进程表现出GC鞭挞。
一个假说,这是使用弱引用缓存,特别是在元类实例的弱引用缓存中保存Groovy的元类系统。注意,这并不一定是守护程序的一个问题,因为它也将适用于非守护进程情况。然而,它是由守护泄漏存储器,由此增加的存储器pressure情况发生的可能性而加剧。
One hypothesis for this is the use of weak reference caches, particularly in the Groovy metaclass system where meta class instances are held in a weak reference cache. Note that this is not necessarily a problem with the daemon, as it would also apply to the non daemon case. However, it is exacerbated by the daemon leaking memory, thereby increasing the chance of a memory pressure situation occurring.
这没有给出任何明确的答案,但它确实给守护程序可能是罪魁祸首你们看到的(连同其他东西)的预感。我已经看到了一些摇篮任务,采取10倍,只要他们通常做的,运行--stop缓解这些问题也是如此。
This doesn't give any definitive answer, but it does give the hunch that the daemon may be the culprit for what you are seeing (along with other things). I've seen some gradle tasks take 10x as long as they usually do, and running --stop alleviates those issues as well.
这篇关于无法找到Java运行Android的工作室Robolectric的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!