gpt4 book ai didi

android - 无法找到 Java 运行时 Android Studio Robolectric

转载 作者:IT老高 更新时间:2023-10-28 22:03:51 26 4
gpt4 key购买 nike

我已将 Robolectric 添加到一个 Android 项目中。我在 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.

关于在哪里寻找这个问题的任何提示?我总是可以 installDebug 然后从 CLI 或 Studio 启动应用程序,但它妨碍了。

最佳答案

过期的 gradle 守护程序可能会在后台导致一些性能问题。我以为 gradle 会在闲置 3 小时后清理它,但似乎并非如此。转到您的终端,转到您的项目的 gradle 文件所在的根文件夹,然后输入命令

./gradlew --stop

并尝试再次运行您的构建。希望这能像解决我的问题一样解决您的问题。

我试图了解这导致问题的原因,但我还没有找到足够好的理由。如果我找到任何东西,我会编辑答案。

更新

来自 Gradle Design Github page :

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

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 也可以缓解这些问题。

关于android - 无法找到 Java 运行时 Android Studio Robolectric,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21550897/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com