Lint - 失败:构建失败并出现异常

Lint - FAILURE: Build failed with an exception

我想 运行 gradlew :lint 我的项目。

但是,我收到 错误:

C:\[ProjectName]>gradlew :lint
Starting a Gradle Daemon, 1 incompatible and 3 stopped Daemons could not be reused, use --status for details
Incremental java compilation is an incubating feature.

FAILURE: Build failed with an exception.

* What went wrong:
Task 'lint' not found in root project '[ProjectName]'. Some candidates are: 'init'.

* Try:
Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1 mins 27.334 secs

当我运行:gradlew lint

我收到 错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_151 contains a valid JDK installation.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

我无法在线搜索任何解决方案。

Refer: https://developer.android.com/studio/write/lint.html

将 JAVA_HOME 变量设置为 C:\Program Files\Java\jdkX.XX 对我有用。

之前因为某些原因设置为JRE目录。

将 JAVA_HOME 变量设置为 C:\Program Files\Java\jdkX.XX

1) 转到搜索栏并输入 "environment" 并单击 "Edit the system environment variables"。 2) 点击 "Environment Variables" 按钮 3) 在系统变量标题下,单击 "new"。输入名称 JAVA_HOME 并查找 jdk 的路径,如 Jeffrey 所说。再次单击“确定”和“确定”。

echo %JAVA_HOME% 在 DOS 上 window