update android sdk with shadowsocks proxy

博格坎普说,我们 android 项目的 build 挂了。

去 Jenkins 看了一下,日志里面的错误是:

[android] $ /usr/local/share/gradle-1.11/bin/gradle clean build
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "buildName" on "ProductFlavorDsl_Decorated{name=main, minSdkVersion=null, targetSdkVersion=null, renderscriptTargetApi=-1, renderscriptSupportMode=null, renderscriptNdkMode=null, versionCode=-1, versionName=null, applicationId=null, testApplicationId=null, testInstrumentationRunner=null, testHandleProfiling=null, testFunctionalTest=null, signingConfig=null, resConfig=null}", value: "1.0.97".

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
   > Could not find com.android.support:appcompat-v7:20.0.0.
     Required by:

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.s

这其实在天朝是蛮常见的现象,因为dl-ssl.google.com被封了,所以你总是会因为下面的错误无法更新 Android 的 SDK:

Failed connect to dl-ssl.google.com:443;


这里之所以选择shadowsocks,是因为可以用自己在Google的VM上配置的 shadowsocks 代理服务器(顺便广告一下,Google 的 VM 在做活动,几乎是最高配的机器都不要钱,而且第一跳就在美帝,用来做代理非常爽)。

安装 shadowsocks 的 pythohn client:

$ pip install shadowsocks

Downloading/unpacking shadowsocks
  Running setup.py egg_info for package shadowsocks

    warning: manifest_maker: MANIFEST.in, line 1: 'recursive-include' expects <dir> <pattern1> <pattern2> ...

Installing collected packages: shadowsocks
  Running setup.py install for shadowsocks

    warning: manifest_maker: MANIFEST.in, line 1: 'recursive-include' expects <dir> <pattern1> <pattern2> ...

    Installing sslocal script to /usr/local/bin
    Installing ssserver script to /usr/local/bin
Successfully installed shadowsocks
Cleaning up...

可以看到安装完之后有两个可执行文件,运行其中的sslocal就可以启动 shadowsocks 的客户端了:

root@palm4fun-core-1:~/install# sslocal -h
usage: sslocal [-h] -s SERVER_ADDR [-p SERVER_PORT]
               [-b LOCAL_ADDR] [-l LOCAL_PORT] -k PASSWORD [-m METHOD]
               [-t TIMEOUT] [-c CONFIG] [--fast-open] [-v] [-q]

optional arguments:
  -h, --help            show this help message and exit
  -s SERVER_ADDR        server address
  -p SERVER_PORT        server port, default: 8388
  -b LOCAL_ADDR         local binding address, default:
  -l LOCAL_PORT         local port, default: 1080
  -k PASSWORD           password
  -m METHOD             encryption method, default: aes-256-cfb
  -t TIMEOUT            timeout in seconds, default: 300
  -c CONFIG             path to config file
  --fast-open           use TCP_FASTOPEN, requires Linux 3.7+
  -v, -vv               verbose mode
  -q, -qq               quiet mode, only show warnings/errors

Online help: <https://github.com/clowwindy/shadowsocks>


```javascript ~/.shadowconfig { “server”:”my_server_ip”, “server_port”:8388, “local_port”:1080, “password”:”barfoo!”, “timeout”:600, “method”:”table” }


root@palm4fun-core-1:~/install# sslocal -c ~/.shadowconfig
INFO: loading config from /root/.shadowconfig
shadowsocks 2.1.0
2014-09-02 00:27:53 INFO     starting local at

命令行更新android sdk

先配置 java 命令使用的代理,然后 从命令行更新 android sdk。只需要到 tools 目录下面去跑(-u是不显示 GUI,-s是指定不使用 ssl 链接):

$ export _JAVA_OPTIONS="-DsocksProxyHost="
$ android update sdk -u -s --all

注意socksProxyHost的默认端口就是 1080,如果你使用了其他端口不能只配 ip。

另外,--all是比较猛烈的选项(人家的硬盘就是大,人家的代理就是快嘛),你可以在命令行里面通过 filter 来安装你需要的东西。

When shit happens

运行起来之后更新非常慢,可以android命令报 timeout,而代理那边打出日志:

2014-09-02 00:27:53 INFO     starting local at
2014-09-02 00:28:04 INFO     connecting
2014-09-02 00:28:04 INFO     connecting
2014-09-02 00:28:04 INFO     connecting

因为本座平时上网也是在用 Google VM 上的这个代理,没理由这么慢。所以就怀疑那个 的地址是被谁在/etc/hosts里面给配了固定 ip。打开一看果然有:


估计是之前配置的基友搜索到了类似这样的文章。这也是为什么我从来不用也不推荐别人用修改 hosts 文件的方法来翻墙的原因:它们总是在过期。

Last but not the least, Fuck you, GFW.