How to run sdkmanager behind a proxy? - android-studio

At my workplace, we have a corporate proxy that signs every incoming connections and we need to authenticate to be able to connect to Internet. I've configured the proxy in way too many places, and I got most software to use it. Now, the only program left (for now) that disrespect my config is sdkmanager. So, how do I make sdkmanager respect my proxy/authentication/certificate config?
sdkmanager
Warning: File /home/users/n.gendron/.android/repositories.cfg could not be loaded.
Warning: java.net.ConnectException: Connection timed out (Connection timed out)
Warning: Failed to download any source lists!
[=======================================] 100% Computing updates...
Android Studio / Appearance & Behaviour / System Settings / HTTP Proxy is correctly configured, and Check connection says Connection successful.
Android Studio / Appearance & Behaviour / System Settings / Android SDK does fetch updates without errors. I can even install new Android SDK Platforms.
Android Studio / Tools / Server Certificates has the correct certificate imported
http_proxy, https_proxy and no_proxy are correctly configured in my .profile.
Certificate is added to multiple keystores with sudo /usr/lib/jvm/default-java/bin/keytool -importcert -file /etc/ssl/certs/guardianCA.pem -keystore /usr/lib/jvm/default-java/jre/lib/security/cacerts.
~/.android/androidtool.cfg has yet another copypasta of my settings

I guess it's too late for a reply, I was going through the same problem. So answering now so that others can get help from it.
Basically SDK manager proxy hasn't been set so using command line proxy tunneling is helpful in this case.
This post has been helpful for me installing android command line tools using sdkmanager on windows.
If all the path variables are set properly
"%ANDROID_HOME%\tools\bin\sdkmanager" "emulator" "platform-tools" "platforms;android-28" "build-tools;28.0.3" "extras;android;m2repository" "extras;google;m2repository" --no_https --proxy=http --proxy_host=10.60.11.11 --proxy_port=8080
or
you can navigate to the directory where sdkmanager.bat file is set it in the path variable, or run this command directly from that location
sdkmanager "emulator" "platform-tools" "platforms;android-28" "build-tools;28.0.3" "extras;android;m2repository" "extras;google;m2repository" --no_https --proxy=http --proxy_host=10.60.11.11 --proxy_port=8080

Related

I updated Android Studio and now gradle project sync fails

I updated Android Studio and now I get these errors:
1. Gradle project sync failed. Basic functionality (e.g. editing, debugging) will not work properly.
2. Unable to tunnel through proxy. Proxy returns "HTTP/1.1 403 Request blocked by Privoxy"
I add this line "systemProp.http.nonProxyHosts=*|localhost" in gradle.properties. Works !!!
Just 1.close your IDE(Android Studio) 2.delete .gradle folder in C:/Users/Your User.gradle in Windows and 3.open your IDE and enjoy
Updated: 2020/04/21
this problem could be fixed by delete gradle.properties file in C:/Users/Your User/.gradle folder
following option solved "Unable to tunnel through proxy. Proxy returns "HTTP/1.1 403 Request blocked by Privoxy" issue
In Android Studio: From the menu bar, click File > Settings (on macOS, click Android Studio > Preferences). In the left pane, click Appearance & Behavior > System Settings > HTTP Proxy. Select No proxy radio button.
deleted gradle.properties file in C:/Users/Your User/.gradle folder
In my case I was using two proxies at a time (even though I disabled first)
If you have a $HOME/.gradle/gradle.properties files, make sure your proxy matched the content of this file.
then:
Prefer a proxy [that bypasses the link giving 403]
Or a strong protocol of VPN (Kerio, ...)
(Discovered it by running with --debug option

Android Studio : adb unable to connect to local host 5037 CreateFileW nul system cannot file specified

I know this is an duplicate question and believe me I have read every thread there is on this post
1) adb: CreateFileW 'null' failed: The system cannot find the specified file
2) Daemon not running. starting it now on port 5037 * Cannot open 'nul': The system cannot find the file specified
3) ddms: 'adb.exe,start-server' failed — run manually if necessary, Android Studio
I have tried EVERYTHING!!!
a)Uninstalling android studio,its emulators,sdk and deleting every folder saying android in my system
from C:/Users/${HOME}/AddData/Local & Roaming to even C:/Windows/[All System Folders(No adb was found in these folders)},Program Data etc.
b)Uninstalling and Reinstalling Platform Tools from Tools->SDK Manager->SDK Tools after android studio reinstallation
c)Manually going to ${ANDROID_SDK_HOME}/platform-tools folder, opening cmd as administrator and running
->adb start-server[Gives Same Error As Above]
->adb kill-server[Unable to connect to target machine ip xxx.xx.xx connection actively refused]
->adb start-server[Same Error As My Question]
d)Tried to verify if any apps running on port 5037
netstat -aon | findstr 5037
nothing
My specs are[No new updates are available for any of the below specifications]
1)Android Studio 3.5.1
2)Platform Tools 29.0.4
3)gradle 5.4.1
4)Windows 10 64 bit
Also i have geny motion installed but with no adb the emulator is not recognized in the device list
I know this issue was posted atleast an year back but i hope some new light has been shed on the issue
plzz help thank u in advanced

Android Studio: Server's certificate is not trusted

Is it safe to ignore this warning? It shows up when I create a new project in Android Studio:
Server's certificate is not trusted
Certificate details
Issued To
CN (Common Name) *.google.com
O (Organization) Google Inc
L (Locality) Mountain View
C (Country) US
ST (State or Province) California
Issued By
CN (Common Name) Google Internet Authority G2
O (Organization) Google Inc
C (Country) US
Validity Period
Valid from: 9/24/14
Valid until: 12/23/14
...
The date looks alright and I checked my computer's date settings to be sure. Why else would it be "not trusted"?
Android Studio has a configuration for Server Certificates (This works for other IntelliJ platforms like PyCharm as well)
Go to File->Settings. In the IDE Settings section select Server Certificates
NOTE: Newer IntelliJ it is in File->Settings->Tools->Server Certificates as mentioned in the comments.
Myself I just selected the Accept Automatically check box, hit Apply and never had to deal with it. If you are worried about security, there is also the option to add them 1 at a time as they come up.
In my case I did this because I already had a *.google.com certificate configured as accepted, but I still got the popup. I suspect that the fingerprint changed and if I would have deleted and then accepted the error would have gone away, but I decided to just make it go away by selecting the check box.
It is not safe to ignore that warning. Someone could be attempting a man-in-the-middle attack with a fake certificate in order to install malicious software on your computer through the update process. This probably isn't happening but it's always better to do things correctly when it comes to security.
You should instead add root certificates you trust to the Android Studio keystore. The location and default password of the keystore should be listed at the bottom of that warning. For example, mine is at ~/Library/Caches/AndroidStudio/tasks/cacerts. Next you'll want to find the root certificate in the chain the server is presenting. Unfortunately the warning doesn't list the whole chain so it takes a little work to find it. The Google Internet Authority G2 certificate is the same one that is used to sign the certificates for google's sites. You can view the chain in Chrome by going to google.com, clicking on the green lock, then "Certificate Information" in the connection tab. At this point you can verify that the hashes in the warning match the hashes for the real G2 certificate. You'll also see that the root certificate is named Equifax Secure Certificate Authority. You can download it from https://www.geotrust.com/resources/root-certificates/. Next you'll need to add it to the keystore:
keytool -import -alias equifaxca \
-file Equifax_Secure_Certificate_Authority.pem -keystore cacerts
Finally, restart Android Studio. That warning should not appear again until August 22, 2018 unless someone is actually presenting a fake certificate.
I ran into this problem after adding a maven repository with SSL certificate signed by non-standard Certificate Authority (CA).
When running the gradle build for my project from my command line, everything worked fine (I had added the custom CA to my machine Java installation cacerts). I had problem running the build from Android studio however, and was getting errors like this:
> Could not resolve joda-time:joda-time:2.9.9.
> Could not get resource 'https://custom-maven-repo.com/repository/releases/joda-time/joda-time/2.9.9/joda-time-2.9.9.pom'.
> Could not GET 'https://custom-maven-repo.com/repository/releases/joda-time/joda-time/2.9.9/joda-time-2.9.9.pom''.
> sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
> PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
> unable to find valid certification path to requested target
I downloaded the pem file for the custom CA, called my-ca.pem. I tried adding this to Android Studio in Preferences -> Tools -> Server Certificates, but that didn't fix it.
I noticed that Android Studio uses an embedded JDK (File -> Project Structure -> SDK Location -> JDK Location) at /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home. In order to get the certificate accepted, I ran (on Mac OS X) these commands to add the certificate, then kill the Android Studio java process:
/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/bin/keytool -import -alias my-ca -keystore /Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/jre/lib/security/cacerts -storepass changeit -file path/to/my-ca.pem -noprompt
kill -9 $(ps -A | grep java | grep "Android Studio" | grep -v grep | awk '{print $1}')
Running the gradle build from Android Studio then worked.
An alternative solution is to set up Android Studio to use a custom JDK using on your machine which has the CA certificate installed, using the menu in File -> Project Structure -> SDK Location -> JDK Location
For Mac Operating System it is in the menu Android Studio->Preferences->Tools->Server Certificates.
In the top of the right side window select the checkbox Accept non-trusted certificates automatically. Hit apply and ok.
As of AndroidStudio 1.5.1 You can go to Preferences -> Tools -> Server Certificates and click the + button to manually add certificates that should be trusted.
It is missing system certificate specific for Java. If you are using Ubuntu and Oracle JRE/JDK, install ca-certificates-java package.
I followed the SELF_SIGNED_CERT_IN_CHAIN error a lot.
Solving npm in node.js solves the certificate problem.
npm config set cafile /path/to/cert.pem
See below
https://mmx5002.blogspot.com/2020/02/selfsignedcertinchain.html

Can't build Android app using crashlytics behind VPN and proxy

As a teleworker I use a VPN with a proxy.pac (config file is available at http://proxy.mycompany.com/proxy.pac).
To update packages Android SDK Manager, the following proxy settings work properly:
HTTP Proxy Server: proxy.mycompany.com
HTTP Proxy Port: 80
In Android Studio I work on an Android-Gradle project using crashlytics. I have set the same parameters in Proxy HTTP.
A gradle assembleDebug command fails when checking crashlytics apikey:
:myproject-project:compileDebugNdk UP-TO-DATE
:myproject-project:preBuild
:myproject-project:preDebugBuild
:myproject-project:checkDebugManifest
:myproject-project:prepareDebugDependencies
:myproject-project:compileDebugAidl UP-TO-DATE
:myproject-project:compileDebugRenderscript UP-TO-DATE
:myproject-project:generateDebugBuildConfig UP-TO-DATE
:myproject-project:processDebugManifest UP-TO-DATE
> Building 32% > :myproject-project:crashlyticsCleanupResourcesDebug
then after timeout:
ERROR - Crashlytics Developer Tools error.
com.crashlytics.reloc.org.apache.http.conn.HttpHostConnectException: Connect to api.crashlytics.com:443 [api.crashlytics.com/54.225.193.37, api.crashlytics.com/54.243.69.50, api.crashlytics.com/54.243.106.90, api.crashlytics.com/54.243.136.142, api.crashlytics.com/54.243.186.185, api.crashlytics.com/107.21.114.251, api.crashlytics.com/184.72.240.69, api.crashlytics.com/54.225.68.102] failed: Connection timed out: connect
at com.crashlytics.reloc.org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:138)
...
I have tried to set gradle properties in ~/.gradle/gradle.properties file:
systemProp.http.proxyHost=proxy.mycompany.com
systemProp.http.proxyPort=80
... but it not seems to be a great idea as I have a warning in HTTP Proxy settings (those settings are obsolete).
I have ask people from network to snif what happens, and there are access failure on URLs like http://dl-ssl.google.com (same that are used in Android SDK manager), or EC2 on Amazon (possibly used by crashlytics, isn't it?).
Of course all this runs perfectly when I'm directly connected in my company's LAN.
Any idea of what could happen? Any workaround?
Thanks for support. Jean
EDIT:
Solution is to set https proxy server and port in ~/.gradle/gradle.properties file. In my case, http parameters seems useless.
systemProp.https.proxyHost=proxy.mycompany.com
systemProp.https.proxyPort=80
Thanks for you help!
Hemal from Crashlytics here. Can you set https.proxyHost and https.proxyPort? In addition, if you have one, go ahead and set https.proxyUser and https.proxyPassword as well! This should take care of it for ya :)

Tomcat Intellij Idea: Remote deploy

RackSpace Cloud Server Ubuntu-12.04, Intellij Idea-11.1.2, Windows-8, Tomcat-7.0.26, JDK-6.
On Intellij Idea when i try to run jsf project on my remote Tomcat 7 server it says:
Error running servername: Unable to connect to the ip-address:1099
It seems problem is about JNDI port which is 1099 but I couldn't activate it I guess. Tomcat config is sth. like that:
What I've tried?
Setting CATALINA_OPTS or JAVA_OPTS on the server side with:
CATALINA_OPTS=-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
and
JAVA_OPTS=-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
But this one did not work, any ideas?
My answer to my question:
The correct way to deploy remotely is editing JAVA_OPTS environment variable on the remote server. Just enter the command below:
export JAVA_OPTS="-Dcom.sun.management.jmxremote=
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false"
If that's not going to work and if you don't have any obsession to deploy your website via Intellij Idea, I've got the solution for this problem. To be able to run your website under Tomcat, you can/should get artifact in form of .war file.
It can be done in Intellij from project settings(ctrl+alt+shift+s) then hit the plus button and add new artifact(web:application archieve)
After rebuilding the artifact, .war file can be seen in project-folder\out\artifacts. Next, you should place this file into your tomcat/webapps folder.
For example if you are using Tomcat-7, the folder that I mean exists in /var/lib/tomcat7/webapps. Before copying your .war file you should rename it as ROOT.war. This provides to access your site directly by http://youripaddress:8080. After restarting Tomcat7 service you can access the site.
But not finished yet, you can debug your project remotely like you are debugging your project at your local machine with Intellij Idea. Open Run/Debug Configuration in Idea, hit the plus button and there must be Remote. This is the way to debug your projects for application servers like JBoss, Glassfish as well in Idea. Enter your host and port numbers, select your project as a module.
Before starting to debug, as Intellij says you should give the following parameter to your server JVM:
JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
To be able to do that in Ubuntu and for Tomcat-7, modified the catalina.sh file in usr/share/tomcat7 folder. I inserted the parameter above of the if [ -z "$LOGGING_MANAGER" ]; then line. It must be on the middle part of the file. Then you should be able to debug your project with Intellij Idea.

Resources