我的问题似乎与问题Build Android Studio app via command line类似,但有点不同。 我有一个android工作室项目,使用Android工作室IDE构建时一切正常但我需要通过 ubuntu 终端构建项目。 我键入./gradlew build我收到以下错误:
A problem occurred configuring root project 'ContentProvider'.
无法解析配置':classpath'的所有文件。 无法解决com.android.tools.build:gradle:3.0.1。 要求: 项目: 无法解决com.android.tools.build:gradle:3.0.1。 无法获取资源“https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom”。 无法获得“https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom”。 java.lang.RuntimeException:意外错误:java.security.InvalidAlgorithmParameterException:trustAnchors参数必须为非空 无法解决com.android.tools.build:gradle:3.0.1。 无法获取资源“https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom”。 无法获得“https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom”。 java.lang.RuntimeException:意外错误:java.security.InvalidAlgorithmParameterException:trustAnchors参数必须为非空。
在输入sudo ./gradlew时,我收到了以下错误:
正在下载https://services.gradle.org/distributions/gradle-4.1-all.zip
Exception in thread "main" javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1959)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1916)
at sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1899)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1420)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
at org.gradle.wrapper.Download.download(Download.java:44)
at org.gradle.wrapper.Install$1.call(Install.java:61)
at org.gradle.wrapper.Install$1.call(Install.java:48)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
at org.gradle.wrapper.Install.createDist(Install.java:48)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Caused by: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:91)
at sun.security.validator.Validator.getInstance(Validator.java:179)
at sun.security.ssl.X509TrustManagerImpl.getValidator(X509TrustManagerImpl.java:312)
at sun.security.ssl.X509TrustManagerImpl.checkTrustedInit(X509TrustManagerImpl.java:171)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:184)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1496)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1026)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:961)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1072)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
... 14 more
Caused by: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
at java.security.cert.PKIXParameters.setTrustAnchors(PKIXParameters.java:200)
at java.security.cert.PKIXParameters.<init>(PKIXParameters.java:120)
at java.security.cert.PKIXBuilderParameters.<init>(PKIXBuilderParameters.java:104)
at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:89)
... 26 more
即使项目构建良好,也没有任何错误通过IDE。 提前致谢
答案 0 :(得分:0)
最后我解决了我的问题,解决方法如下: 1-安装jdk8:
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jdk
sudo update-alternatives --config java
sudo update-alternatives --config javac
确定java类型:
java -version
2-安装Gradle版本4.4.1(这对我来说很顺利):
wget https://services.gradle.org/distributions/gradle-4.4.1-bin.zip
sudo mkdir /opt/gradle
sudo unzip -d /opt/gradle gradle-4.4.1-bin.zip
export PATH=$PATH:/opt/gradle/gradle-4.4.1/bin
确保gradle类型:
gradle -v
3-键入以下命令安装ca-certificates-java:
sudo apt install ca-certificates-java
4-重启你的电脑。
然后输入:
gradle build
如果您遇到如下错误: 任务&#39;:app:lint&#39;。
的执行失败将此添加到app模块的构建脚本中。
android {
lintOptions {
abortOnError false
}
}
一切都应该顺利。