Qt Tips and Tricks: Qt Creator for develop Android app using Gradle and proxy problem
Qt Creator recently introduced a new way for develop android application. Basically is now possible to select use Gradle instead of apache-ant for final APK creation. Gradle is going to be the new "standard" than the choice of Qt team look perfectly reasonable. However if you are developing in a network under a proxy you could experiment some problem using Gradle.
The problem is Qt Creator want to download the Gradle package for each first compilation of a new project and if your network require a proxy access for Internet download this operation will fail. To add more problem the java engine is used for download than we need to find a way for externally set the proxy settings to be used by java itself. Fortunately there is the possibility to make such result by setting a global environment variable called _JAVA_OPTIONS. This variable is get by java at engine startup and automatically configure the settings inside. In our case the settings need to instruct java to use a proxy are the following:
-Dhttp.proxyHost=[proxy IP] -Dhttp.proxyPort=[proxy port]
This are valid only for http connections but it would be better to add also https as follow:
-Dhttp.proxyHost=[proxy IP] -Dhttp.proxyPort=[proxy port] -Dhttps.proxyHost=[proxy IP] -Dhttps.proxyPort=[proxy port]
In case your proxy require username and password also the settings string will add new params as follow:
-Dhttp.proxyHost=[proxy IP] -Dhttp.proxyPort=[proxy port]-Dhttp.proxyUser=[username] -Dhttp.proxyPassword=[password] -Dhttps.proxyHost=[proxy IP] -Dhttps.proxyPort=[proxy port] -Dhttps.proxyUser=[username] -Dhttps.proxyPassword=[password]
To be totally sincere I'm not sure if the latest two params (-Dhttps.proxyUser and -Dhttps.proxyPassword) are really necessary since there is some confusion in the documentation around. However I prefer to add it just in case to avoid future problems. Now let's make a practical example. In our example I'll use as proxy IP the classic 192.168.0.1 and port 8080. As username something like "1234" and password "5678" but as said in television don't try use these account at home (or in office) ^_^. Obviously the procedure to set a global environment variable will differ from OS, than in Unix based system like Linux will be:
export _JAVA_OPTIONS="-Dhttp.proxyHost=192.168.0.1 -Dhttp.proxyPort=8080 -Dhttp.proxyUser=1234 -Dhttp.proxyPassword=5678 -Dhttps.proxyHost=192.168.0.1 -Dhttps.proxyPort=8080 -Dhttps.proxyUser=1234 -Dhttps.proxyPassword=5678"
On Windows you have to go to Control Panel -> System Properties. Here, some difference between different Windows versions, in the tab "Advanced" look for the button "Environment Variables" and set the _JAVA_OPTIONS in a new item with the java proxy settings as explained above.
In some cases I found Gradle seem not able to use correctly the username and password settings with the result to get an error like "Authentication failed". In this case the only workaround I found is to use some tool like Cntlm that allow to "bypass" username and password insertion by create and internal service able to redirect the proxy request. Look into the site for info about use it.
Comments
Post a Comment