无法找到 Java 运行时 Android Studio Robolectric [英] Unable to locate a Java Runtime Android Studio Robolectric

查看:23
本文介绍了无法找到 Java 运行时 Android Studio Robolectric的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将 Robolectric 添加到一个 Android 项目中.我在 19.0.1 中使用带有构建工具的 Android Studio.

I've added Robolectric to an Android project. I'm using Android Studio with Build Tools in 19.0.1.

我可以运行测试:

$./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 的设备或模拟器上运行我的项目时,我得到以下信息:

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.

推荐答案

过期的 gradle 守护进程可能会导致后台出现一些性能问题.我以为 gradle 会在闲置 3 小时后将其清理干净,但事实并非如此.转到您的终端,转到 gradle 文件所在的项目根文件夹,然后输入命令

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.

更新

来自 Gradle Design Github 页面:

目前,守护进程在出现内存压力时会出现严重的问题.在压力下,守护进程会出现 GC 抖动.

Currently, the daemon has serious problems when memory pressure occurs. When under pressure, the daemon process exhibits GC thrash.

对此的一个假设是使用弱引用缓存,特别是在 Groovy 元类系统中,其中元类实例保存在弱引用缓存中.请注意,这不一定是守护程序的问题,因为它也适用于非守护程序的情况.但是,守护进程泄漏内存会加剧这种情况,从而增加发生内存压力情况的机会.

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.

这并没有给出任何明确的答案,但它确实给人一种预感,即守护程序可能是您所看到的(以及其他事情)的罪魁祸首.我已经看到一些 gradle 任务需要花费 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 Studio Robolectric的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆