How to configure Android Studio Gradle proxy from behind the Great Firewall

tsunemori
3 min readMar 15, 2020
Two man climbing boarder wall between the U.S. and Maxico.

We are all facing some kind of wall, either digital or physical.

Not long ago, I was building a toy android app just for practice and try out the new features of android 10. Unfortunately, I got bitten at the very first step: starting a project using Android Studio.

Screenshot of the error

My primary research pointed to the possibility that the mysterious force that tripled me at the beginning of the app-building journey: the Great Firewall, one of the most capable weapons of all time. Since I was working as an indie developer back then, I had to overcome this without a corp dedicated VPN.

Most of the solutions I found online are provided by the programmers ‘Dans le Mur’ (how surprising), while most of them seem to work for lots of people but eventually failed me. Some typical not-working-solutions are listed below just for your desperation (kidding).

https://xkcd.com/979/

Disclaimer alert: the following just failed for me. They might somehow solve your problem due to various factors regarding environments.

The Unsuccessful Efforts

  1. Using a mirror from within the wall

To be honest, it could be a once-for-all solution. It completely eliminated the need for connection to a Google service which is blocked by the GFW. However, this has an obvious downside that the mirrors often suffer a significant version lag compared to the original service. Besides, most of the provided mirrors don’t seem to alive when I’m writing this. So, this seems to be a dead end.

buildscript { repositories { maven{ url ‘http://maven.aliyun.com/nexus/content/groups/public/'} } } allprojects { repositories { maven{ url ‘http://maven.aliyun.com/nexus/content/groups/public/'} } }

One suggestion is to modify the build.gradle file as above and rebuild the project. You can try out to see if there’s any luck.

2. A subtle trick of Gridle wrapper setting

When I first saw this solution I thought it would be the killer solution. Maybe it was the overflowed confidence in the author’s tone, or I was just too desperate searching, it turned out another disappointment of the day. It just doesn’t work. The trick is attached below.

This may work for some proxy other than v2ray

3. Setting an HTTP proxy for the Android Studio

If you find this article by searching, you probably know what V2Ray is. If you don’t, well, either you are not under censorship or you don’t care about censorship at all. You are lucky either way. Back to the matter, the setting suggested is shown below:

The key is that you have a running proxy that listening to localhost at a port decided by you.

And…again, I searched, I tried, I failed.

The Silver Lining

Just before I freak out, I realized that the v2ray inbound in my current config file does not support HTTP protocol. So I added it as this response suggests:

GitHub link to the issue

And, restart the v2ray service. It should work now. If not, you may want to check if the distributionUrl property in the gradle-wrapper.properties. The URL should start with https instead of http because the unsafe version is no longer supported.

Then, as expected, when I restart Android Studio (given the v2ray is running properly), Gradle sync succeeded.

--

--