Wednesday, October 28, 2009

Workaround on installing Android SDK 2.0 behind proxy requiring authentication

This morning I tried to install Android SDK 2.0 on my Ubuntu desktop. I downloaded the package with my browser without any problem. Extract it and then run tools/android to download the packages. Realising that my desktop requires a proxy which requires authentication to get to the Net, I went to the Settings panel of the Android SDK and AVD. There are only proxy host and port entries, no username and password entries. I was hoping that the software is smart enough to prompt for username and password later. However, I was wrong. It did not prompt me any authentication form whatsoever. Bummer...... Then I got an idea. I remember few months ago when I set up a forwarding only proxy to act as a child of a parent proxy. I thought if I could get this child proxy to authenticate to the parent proxy and forward all request to the parent proxy, the user won't need to authenticate at all. Hmmm.... Looking at the manual of squid http proxy, I saw cache_peer option which enable child proxy to login to the parent proxy by specifying login=username:password. Yummy.... So, I fired up the trusty apt-get to pull and install squid from my local repository.
$ sudo apt-get install squid
$ sudo vi /etc/squid/squid.conf
Then I added the following setting:
cache_peer parent 8080 0 no-query default login=username:password
never_direct allow all
Then I restart squid
$ sudo /etc/init.d/squid stop
$ sudo /etc/init.d/squid start
Then I pointed the Android SDK and AVD to use and port 3128. I also set the software to force downloading using http even if the URL is in https. Finger cross and I tick the site and click Refresh. Viola... it works. It is downloading as I write this blog entries.