Unable to locate a Java Runtime Android Studio Robolectric

丶灬走出姿态 提交于 2019-12-02 18:34:00

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.

UPDATE

From the 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.

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.

For me, adding JAVA_HOME to your Path Variables (Android Studio -> Preferences -> Path Variables), then restarting the Gradle daemon, as mentioned above (./gradlew --stop) did the trick.

On a Mac, you can find your Java directory (version 6) with /usr/libexec/java_home -v 1.6

Switching back to Gradle 1.10 worked for me (on OS-X). You can edit the gradle-wrapper properties or configure a local gradle distribution in Android-Studio

Try setting sourceCompatibility and targetCompatibility in your build.gradle file. For Java 1.7 it should look like:

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!