Peer not authenticated in AndroidStudio, but not on commandline-gradle - android

When building my project in AndroidStudio I regularly get the error
08:53:33.788 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
It happens whenever the local gradle cache is invalidated, so around once a day. When I build it from the commandline, either with gradle or ./gradlew, it works and the artifacts are downloaded.
The project uses a private maven repository for downloading dependencies. It was a bit tricky to set up and probably is part of the problem. Authentication works via a client certificate that is specified in a bash variable:
GRADLE_OPTS=-Djavax.net.ssl.keyStore=client_certificate.p12 -Djavax.net.ssl.keyStorePassword=password -Djavax.net.ssl.keyStoreType=PKCS12 -Djavax.net.ssl.trustStore=truststore.jks -Djavax.net.ssl.trustStorePassword=changeit
It is exported in my ~/.profile script. When this variable is not set, also the commandline build will fail with a "peer not authenticated" error.
What I tried already with no success:
Set GRADLE_OPTS in "Compiler/Command-line Options" with -P
Set GRADLE_OPTS in "Path Variables"
Import the server certificate to jdk/Contents/Home/jre/lib/security
Use the latest Java version for compiling
How can the AndroidStudio build be fixed?

Related

Trouble getting gradle project building in Intellij: Task 'compileJava' is ambiguous

I am attempting to get
https://github.com/KodeinKoders/Playground-Demo-Crypto (commit 2a9b2b9)
Repository to build.
After doing some updates of tooling MacOS & XCode. And addition of the following override to gradle build file:
tasks.getByName<org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest>("iosX64Test") {
deviceId = "iPhone 14"
}
I am able to build within command line use
gradle build
On
MacOS: 13.2
XCode: 14.2
However, when I run build within IntelliJ. I get the following error:
Task 'compileJava' is ambiguous in root project 'DemoCrypto'. Candidates are: 'compileDebugAndroidTestJavaWithJavac', 'compileDebugJavaWithJavac', 'compileDebugUnitTestJavaWithJavac', 'compileReleaseJavaWithJavac', 'compileReleaseUnitTestJavaWithJavac'.
The IntelliJ notifications show:
Executing tasks: [:compileDebugSources, :compileDebugUnitTestSources, :compileDebugAndroidTestSources, :compileJava, :testClasses] in project /usr/local/workplace/sandbox-kotlin-thorg/Playground-Demo-Crypto
Prior to build failure.
I am new to gradle. I don't know where this list of tasks that intellij chooses to use for build is coming from? I am also confused by fact that running:
grep -r "compileDebugSources" .
From within the project root leads to 0 matches.
So the questions are:
How does IntelliJ choose to use that particular list of tasks to for its build. Given that compileDebugSources doesnt even exist in the project.
Advice on getting the build to work in IntelliJ?

org.gradle.kotlin.kotlin-dsl was not found

I am getting the following error while running the build
FAILURE: Build failed with an exception.
* Where:
Build file '/home/charming/mainframer/bigovlog_android/buildSrc/build.gradle.kts' line: 4
* What went wrong:
Plugin [id: 'org.gradle.kotlin.kotlin-dsl', version: '1.2.6'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:1.2.6')
Searched in the following repositories:
Gradle Central Plugin Repository
my buildSrc/build.gradle.kts
repositories {
jcenter()
}
plugins {
`kotlin-dsl`
id("groovy")
}
dependencies{
gradleApi()
localGroovy()
}
I tried everything but still not working
Did you check that Android Studio wasn't running in Offline Mode? Take a look at Preferences/Build, Execution, Deployment/Gradle/Global Gradle settings and see if Offline Work is checked.
In my case, my company is using a proxy behind the network.
So it must be an SSL handshake fail issue.
To fix this issue, I use KeyStore Explorer.
Follow these steps.
Download KeyStore Explorer and install it on your system. (In my case Windows10 OS)
Run KeyStore Explorer and open the cacerts file, if you are using Android Studio on Windows 10, it's here: C:\Program Files\Android\Android Studio(or Preview)\jre\jre\lib\security with password changeit.
On the toolbar, go to Examine -> Examine SSL, insert these values and click OK.
SSL Host: plugins.gradle.org
SSL Port: 443
Click the Import button and OK.
Save the file, and go to Android Studio, run Invalidate Caches / Restart.
If Android Studio is reopened, try Sync Project with Gradle Files again.
Please leave a comment, if you have more questions.
The same exact build file works for me. Try clean Gradle cache in both your project and home directory and check if it will work then. If it will still fail, try to update Gradle and the plugin to the latest version id("org.gradle.kotlin.kotlin-dsl") version "1.3.2"
I have the same problem and I try gradle --info
the log is below:
Evaluating project ':buildSrc' using build file '/Users/fjh1997/mirai/buildSrc/build.gradle.kts'.
I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {tls}->http://127.0.0.1:1083->https://plugins.gradle.org:443: The target server failed to respond
Retrying request to {tls}->http://127.0.0.1:1083->https://plugins.gradle.org:443
I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {tls}->http://127.0.0.1:1083->https://plugins.gradle.org:443: The target server failed to respond
Retrying request to {tls}->http://127.0.0.1:1083->https://plugins.gradle.org:443
I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {tls}->http://127.0.0.1:1083->https://plugins.gradle.org:443: The target server failed to respond
It seems that pass requests to proxy 127.0.0.1:1083.However what url I set proxy in local gradle.properties file is 127.0.0.1:8118.What's wrong with that?After long time's efforts,I find it out.
Actually,there are two gradle.properties configuration files in your system , one is in your project/.gradle,another is in ~/.gradle.And the latter is the global setting for gradle.
If the global setting has set variables for systemProp.http.proxyHost, then whatever you set in project/.gradle/gradle.properties, proxy dosen't work at all,you have to change it in the global setting.
And BTW,I find that the global setting for gradle is changed by my android studio preference.

Android Studio : Gradle failed to resolve Dependencies

I recently migrated an eclipse project to androidStudio. But while building AS failed to resolve the dependencies. Initially I thought it might be the proxy problem as I am in the restricted network, So I added the proxy settings resulting nothing.
So I tried gradlew in terminal and the output of is as below :
Could not resolve all dependencies for configuration ':classpath'.
Could not resolve com.android.tools.build:gradle:2.3.2.
Required by:
project :
Could not resolve com.android.tools.build:gradle:2.3.2.
Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/2.3.2/gradle-2.3.2.pom'.
Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/2.3.2/gradle-2.3.2.pom'.
This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server
So I tried reaching "https://jcenter.bintray.com/com/android/tools/build/gradle/2.3.2/gradle-2.3.2.pom" from my browser and it browser downloaded file successfully. That means network if fine.
So why AS studio is failing to solve dependencies?
Is there something wrong with the gradle version?
How do I decide which gradle version suits my Project?
Appreciate your responses.
Try :
First :
repositories {
jcenter({url "http://jcenter.bintray.com/"})
}
If that does not work.Gradle to manually sync proxy
gradlew -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8580

Configure Bamboo for Android Gradle based Project

I am trying to setup Bamboo for my Gradle build system based Android Project.
I have done the following setup on Bamboo.I'm done with rest of all setup upto project repository path.
I want to run the following tasks using gradlew for android
clean assembleDebug LintDebug
For that I have created new task called Gradle Wrapper.
Below is the Gradle Wrapper Configuration
When I am executing gradle wrapper task, I am getting the following error.
Caused by: java.lang.IllegalStateException: Cannot find executable 'D:\AndroidDemo\gradle-2.10\bin\gradlew.bat'
Note :- Standalone Gradle is working fine on local machine with all the tasks(clean assembleDebug LintDebug)
Gradle_Home = D:\AndroidDemo\gradle-2.10\bin(Local machine)
Can anyone suggest a solution for the same?
I also had some initial difficulties to set up Bamboo to build an Android project using Gradle.
First of all, make sure that you have the Gradle wrapper (gradlew) in your repo. (Seemingly that's the situation in your case). It seems to me, however the Gradle wrapper ignores the system default Gradle distribution (set by the GRADLE_HOME env var), and always downloads a Gradle version mandated by the Android Build tools.
Also make sure, that the Android SDK root environment variable (ANDROID_HOME or ANDROID_SDK_ROOT) is pointing to the SDK's root directory (e.g. $ export ANDROID_HOME="/opt/android-sdk/")[1].
Restart Bamboo after applying the environment variable changes.
In Bamboo, in the build tasks lists, add a new Script task. The interpreter should be '/bin/sh or cmd.exe', the script location should be 'inline', and the script body should contain the call for the parametrized Gradle wrapper, e.g.
gradlew clean build
Point the working subdirectory to the Gradle wrapper's relative location (to the repo root), if necessary.
[Sample Bamboo Android Gradle build script]
After these steps, Bamboo should execute the Gradle wrapper, which in fact should perform the actual build steps.

gradle build in jenkins [duplicate]

While I am importing gradle project in eclipse, it is giving me this error.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'test'.
> Could not resolve all dependencies for configuration ':classpath'.
> Could not resolve de.richsource.gradle.plugins:gwt-gradle-plugin:0.3.
Required by:
:test:unspecified
> Could not GET 'https://github.com/steffenschaefer/gwt-gradle-plugin/raw/maven-repo/de/richsource/gradle/plugins/gwt-gradle-plugin/0.3/gwt-gradle-plugin-0.3.pom'.
> peer not authenticated
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
I am using internet via proxy connection. If that is the issue, where to specify the proxy settings inside eclipse. In General-->Network connections, proxy settings are already there
Please help.
NOTE: Please ensure the server is trustworthy before you follow these steps.
If you get any other error like this:
Could not GET 'https://some_server.com/some/path/some.pom'.
> peer not authenticated
Then you need to import a certificate :
open the 'https://some_server.com/some/path/some.pom' in your favorite browser
export the cert using the Steps to export cert from a web site
copy the cer into JDK_HOME/jre/lib/security folder
open a shell and go to JDK_HOME/jre/lib/security folder
then import the cer into java using the
keytool -import -alias <the short name of the server> -file <cert_file_name_you_exported.cer> -keystore cacerts -storepass changeit
It will prompt you to import the certificate, type yes and press enter.
Then restart your eclipse and try building the project.
ANSWER#2:Providing the correct fix after two Negative markings
Make this changes to the top-level build.gradle file.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
//jcenter()
jcenter {
url "http://jcenter.bintray.com/" <=THIS IS THE LINE THAT MAKES THE DIFFERENCE
}
}
}
allprojects {
repositories {
//jcenter()
jcenter {
url "http://jcenter.bintray.com/" <=THIS IS THE LINE THAT MAKES THE DIFFERENCE
}
}
}
ANSWER#1 (Although this is not accepted would like to keep this)
If you see "peer not authenticated errors , it does not necessarily mean that the application does not hold a valid certificate. It also could mean that connections are being reset by the firewall, load balancer, or web servers. Try (re)starting the application with the Administator privilege.
On Windows:
Ensure you have administrator privileges.
Right Click application icon -> Select "Run as Administrator"
On Linux:
Ensure you have root access.
type sudo "app execution script name"
Change your repositories to the following in the build.gradle
repositories {
maven {
url "http://repo1.maven.org/maven2"
}
}
After importing the certificate as suggested in the above answer, edit your gradle.properties file and insert the following lines (having in mind your proxy settings):
HTTPS:
systemProp.https.proxyHost=www.somehost.org
systemProp.https.proxyPort=8080
HTTP:
systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
Upgrading from java7 to java8 did the trick for me.
I had a strange case where I had to change the order of jcenter and maven to get rid of the error
Not working
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
maven { url "https://jitpack.io" }
}
}
Working
allprojects {
repositories {
maven {
url "https://maven.google.com"
}
jcenter()
maven { url "https://jitpack.io" }
}
}
I try to modify the repositories and import the cer to java, but both failed, then I upgrade my jdk version from 1.8.0_66 to 1.8.0_74, gradle build success.
I found that this was failing because of transient network issues with my Artifactory server. Other fixes didn't work for me, but simply retrying the build worked.
I using Java 11 cause this issue, problem resolved with change to Java 8, maybe you can check your java version.
I'm using android studio 1.51 with Linux (Ubuntu 14.04 LTS) and got the same error message:
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not resolve com.github.PhilJay:MPAndroidChart:v2.1.6.
Required by:
dbtraining-dbtrainingandroidapp-517de26197d8:app:unspecified
> Could not resolve com.github.PhilJay:MPAndroidChart:v2.1.6.
> Could not get resource 'https://jitpack.io/com/github/PhilJay/MPAndroidChart/v2.1.6/MPAndroidChart-v2.1.6.pom'.
> Could not GET 'https://jitpack.io/com/github/PhilJay/MPAndroidChart/v2.1.6/MPAndroidChart-v2.1.6.pom'.
> peer not authenticated
I tried to move maven { url "https://jitpack.io" }, set it to http instead of https, activated the "accept non-trusted certificates automatically", added the ssl certificate manually ... but still no luck.
The solution was to switch from OpenJDK 7 to Oracle JDK 8:
Downloaded the files for the JDK from Oracle, I took the tarball
(jdk-8u101-linux-x64.tar.gz) - http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Extract the files. The folder name is jdk1.8.0_101
Now switch to the directory /opt/ (nautilus hotkey: CTRL+L) and create a new folder
"Oracle_Java". Maybe this requires root access, so open nautilus
from the terimal with sudo nautilus
Copy the folder jdk1.8.0_101 to /opt/Oracle_Java Follow the
instructions from https://wiki.ubuntuusers.de/Java/Installation/Oracle_Java/Java_8/#Java-8-JDK: Do not forget to replace the version placeholder in the path with your version
sudo update-alternatives --install "/usr/bin/java" "java" "/opt/Oracle_Java/jdk1.8.0_VERSION/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/opt/Oracle_Java/jdk1.8.0_VERSION/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/opt/Oracle_Java/jdk1.8.0_VERSION/bin/javaws" 1
sudo update-alternatives --install "/usr/bin/jar" "jar" "/opt/Oracle_Java/jdk1.8.0_VERSION/bin/jar" 1
sudo update-alternatives --set "java" "/opt/Oracle_Java/jdk1.8.0_VERSION/bin/java"
sudo update-alternatives --set "javac" "/opt/Oracle_Java/jdk1.8.0_VERSION/bin/javac"
sudo update-alternatives --set "javaws" "/opt/Oracle_Java/jdk1.8.0_VERSION/bin/javaws"
sudo update-alternatives --set "jar" "/opt/Oracle_Java/jdk1.8.0_VERSION/bin/jar"
You can check in the terminal with the command java -version if
your installation was successful.
Now to back to android studio and open the project structure
window by pressing the hotkey CTRL+SHIFT+ALT+S and go to SDK
Location. Here you can set the path to JDK, for example
/opt/Oracle_Java/jdk1.8.0_101
That's it! :)
I had this error and it was happening because of a VPN proxy issue. I disabled my VPN client and everything worked fine after. I used this command (on a Mac):
sudo /opt/cisco/anyconnect/bin/acwebsecagent -disablesvc -websecurity
Upgrading to the latest version of gradle fixed this for me.
update distributionUrl in gradle-wrapper.properties to use the latest version.
update gradleVersion in build.gradle to match that version.
An old one, but since I just had this issue with an install of Eclipse 4.11...
There is apparently an issue with JDK11 which could cause this (https://github.com/spring-projects/sts4/issues/208#issuecomment-469661129). When I reverted back to my existing install of JDK8, I no longer saw the error.
Removing .gradle directory fixed this for me. If u r getting this due to a caching issue this will help.
As suggested in some answers here, I installed Java 8 and error was gone. Seems like bug is related to Java 11.
I used jEnv to manage java versions.
brew install jenv
brew install --cask adoptopenjdk8
jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
jenv global 1.8
Selected answer didn't help, I just couldn't download said certificate using Safari...
I recently had this same issue on Gitlab pipeline that uses gradle to build .jar.
Failing build configuration:
gradle-build:
image: gradle:5.2.1-jdk11-slim
stage: build
script:
- ./gradlew clean
- ./gradlew bootJar
It turned out that I was using outdated and not-supported gradle Docker image and after upgrading to gradle:6-jdk11-alpine, build passed
In my case upgrading ca-certificates package that's used by openssl fixed this error.
I could download the erring file successfully using the browser and looking at previous answers on this question made me think of old root CA's at OS level and that actually worked.
Not specific to Ubuntu but leaving following url for reference
https://ubuntu.com/server/docs/security-trust-store

Categories

Resources