24

I'm trying to build a Sencha Touch app for android using Cordova. However, after the gradle build kicks off I get a connection error when trying to connect to the maven repo:

[INF] [shellscript] Running: C:\xxx\gradlew cdvBuildDebug -b C:\xxx\application\cordova\platforms\android\build.gradle -Dorg.gradle.daemon=true
[INF] [shellscript]
[INF] [shellscript] FAILURE: Build failed with an exception.
[INF] [shellscript]
[INF] [shellscript] * What went wrong:
[INF] [shellscript] A problem occurred configuring root project '''android'''.
[INF] [shellscript] > Could not resolve all dependencies for configuration ''':classpath'''.
[INF] [shellscript]    > Could not resolve com.android.tools.build:gradle:1.0.0+.
[INF] [shellscript]      Required by:
[INF] [shellscript]          :android:unspecified
[INF] [shellscript]       > Failed to list versions for com.android.tools.build:gradle.
[INF] [shellscript]          > Unable to load Maven meta-data from https://repo1
.maven.org/maven2/com/android/tools/build/gradle/maven-metadata.xml.
[INF] [shellscript]             > Could not GET '''https://repo1.maven.org/maven
2/com/android/tools/build/gradle/maven-metadata.xml'''.
[INF] [shellscript]                > Connection to https://repo1.maven.org refused

I would imagine this is related to the corporate proxy I have to connect through in my office - however I'm not sure how to configure Gradle to connect via this proxy since it is being executed by Cordova, which is itself being executed by Sencha Cmd.

Is there a way to configure a proxy with Sencha?

semiserious
  • 610
  • 1
  • 8
  • 12

2 Answers2

51

You'll need to configure Gradlew to use a proxy server. This is done by creating a gradle.properties file with the following contents:

systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost  

systemProp.https.proxyHost=www.somehost.org
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=userid
systemProp.https.proxyPassword=password
systemProp.https.nonProxyHosts=*.nonproxyrepos.com|localhost

This is an example taken from Chapter 19.3 of the User Guide. Make sure you include both the HTTP and HTTPS values in your file.

You'll place this gradle.properties file in either of these locations:

  1. In your "cordova/platform/android" folder for your mobile project

OR

  1. In your Gradle home folder. For Windows, this is likely %USERPROFILE%\.gradle\ (Ex: C:\Users\username\.gradle\).

I would recommend putting it in Gradle home so that other projects pick it up and you don't have to worry about putting it under source control.

You can also find more info in this post.

Community
  • 1
  • 1
swbradshaw
  • 874
  • 9
  • 15
  • It's always helpful to include some code (here: examples) in the answer. Up for editing your answer to include one or two of them? – bardzusny May 14 '15 at 17:56
  • Thanks! I was aware of that file but thought it was generated by Cordova and would be overwritten on each build.. – semiserious May 15 '15 at 13:25
  • @bardzusny - Thanks for the edit. I see what you mean now. (This was my first answer). – swbradshaw May 19 '15 at 02:10
  • Also, if you need to completely unset these settings (while in a non-proxy net) you've gotta fill your gradle.properties like this: systemProp.http.proxyHost= systemProp.http.proxyPort= It took me 30min to figure it out – rotoxl Jun 12 '15 at 17:46
  • Can gradle not pull those from the HTTP_PROXY environment variable? – Norman H Jul 16 '15 at 21:11
  • It's working.If you have a test server or something like that,you could use it. – Fatih Ayyildiz Feb 01 '16 at 22:27
  • I have gone thought COUNTLESS articles on this issue but none of them worked (most of them regarding the wrapper) but none of them even mention this. Not sure if it helped but I have also setup DEFAULT_JVM_OPTS with the proxy settings as well. Thank you so much. – Vyrnach Apr 29 '16 at 02:37
  • I tried the solution but i get this error: Could not GET 'https://maven.google.com/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.pom'. Received status code 403 from server: Authentication required – Fakher Oct 11 '17 at 14:18
  • If your build initially worked but then for some mysterious reason just stopped, the first thing you should try before going to all these extremes is just restart your computer. – Johann Feb 21 '18 at 17:11
0

I had the same error, but it was after i installed git which in turn changed my environment variables. I went back there to remove the added path and it worked