我发表了以下评论:
./gradlew app:installDebug
只是遇到了日志:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '11.0.2'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
我的gradle版本是5.1.1:
------------------------------------------------------------
Gradle 5.1.1
------------------------------------------------------------
Build time: 2019-01-10 23:05:02 UTC
Revision: 3c9abb645fb83932c44e8610642393ad62116807
Kotlin DSL: 1.1.1
Kotlin: 1.3.11
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.2 (Oracle Corporation 11.0.2+9-LTS)
OS: Mac OS X 10.13.6 x86_64
我不知道如何继续(我尝试过升级/降级,但到目前为止都没有工作)。
更新:当我运行。/gradlew——版本,我得到以下:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '11.0.2'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
我的…/ gradle /包装/ gradle-wrapper。properties包含以下内容,包括distributionUrl=…/gradle-4.1-rc-1-all.zip:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip
正如其他人所提到的,在Gradle 5中添加了对Java 11的支持。解决方案是升级你的Gradle包装:
Go here to figure out the latest version of Gradle: https://gradle.org/releases/
Upgrade the Gradle wrapper
If you have Gradle installed on your machine:
gradle wrapper --gradle-version 7.2
If you don't have Gradle installed:
Modify gradle/wrapper/gradle-wrapper.properties
Update distributionUrl with the latest version of Gradle, e.g.
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
Upgrade the remaining wrapper files (gradle-wrapper.jar, gradlew, gradlew.bat)
./gradlew wrapper --gradle-version 7.2
因为你是从一个旧版本的Gradle升级的,你可能会得到这样的错误:
Could not find method compile() for arguments ...
Could not find method testCompile() for arguments ...
要修复这些问题,请编辑build。gradle,用implementation替换compile的每个实例,用testimplemimplementation替换testCompile。
正如其他人所提到的,在Gradle 5中添加了对Java 11的支持。解决方案是升级你的Gradle包装:
Go here to figure out the latest version of Gradle: https://gradle.org/releases/
Upgrade the Gradle wrapper
If you have Gradle installed on your machine:
gradle wrapper --gradle-version 7.2
If you don't have Gradle installed:
Modify gradle/wrapper/gradle-wrapper.properties
Update distributionUrl with the latest version of Gradle, e.g.
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
Upgrade the remaining wrapper files (gradle-wrapper.jar, gradlew, gradlew.bat)
./gradlew wrapper --gradle-version 7.2
因为你是从一个旧版本的Gradle升级的,你可能会得到这样的错误:
Could not find method compile() for arguments ...
Could not find method testCompile() for arguments ...
要修复这些问题,请编辑build。gradle,用implementation替换compile的每个实例,用testimplemimplementation替换testCompile。
Tl;dr:运行update-alternatives来降级Java
我的系统gradle版本是4.4.1,gradle包装器版本是4.0。在运行其他几个答案给出的命令后:
gradle wrapper --gradle-version 4.4.1
我还是犯了同样的错误:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '11.0.4'.
原来直到gradle 4.8才支持java 11,而我的软件库只有4.4.1。(此外,升级到较新的gradle版本可能与我试图编译的包不兼容。)
答案是降级java。我的系统实际上已经安装了java8,通过运行这个命令并按照说明在java版本之间切换很容易:
sudo update-alternatives --config java