最近Facebook 又放出了一個(gè)用于Android apk字節(jié)碼優(yōu)化的工具包——redex,經(jīng)過redex的優(yōu)化apk會變的體積更小,速度更快。至于原理大家可以到https://code.facebook.com/posts/1480969635539475/optimizing-android-bytecode-with-redex這個(gè)網(wǎng)站去看,今天我想分享一下具體的實(shí)踐過程。
前兩天剛看到FB放出的這個(gè)工具包就迫不及待的去嘗試了下,結(jié)果一直報(bào)下面這個(gè)錯(cuò)誤:
configure: error: Please install double-conversion library
但其實(shí)這些library都已經(jīng)安裝好了的,那天倒騰了好久也跟群里的朋友交流過,感覺應(yīng)該是FB的一個(gè)小bug于是去github上提了issue,果然第二天得到了回應(yīng)官方更新了使用說明。下面是我在Mac OS X上的實(shí)踐過程:
1、首先需要你的Xcode安裝了命令行工具:
xcode-select --install
2、利用homebrew安裝依賴包:
brew install autoconf automake libtool python3
brew install boost double-conversion gflags glog libevent openssl
brew link openssl --force
3、通過Git將redex的源碼checkout到電腦上:
git clone https://github.com/facebook/redex.git
cd redex
git submodule update --init
4、通過autoconf和make來構(gòu)建redex:
autoreconf -ivf && ./configure && make
sudo make install
在執(zhí)行步驟四的時(shí)候就出現(xiàn)了問題:
configure: error: Please install google-gflags library
configure: error: ./configure failed for third-party/folly/folly
于是我又提了issue,下面是跟溝通的過程:
按照他的方法執(zhí)行下面的命令:
xcode-select --install
sudo xcode-select --switch /Library/Developer/CommandLineTools/
再執(zhí)行步驟四就OK了當(dāng)然如果看到很多warn也不用擔(dān)心,最終可以編譯通過。
接下來就可以通過redex執(zhí)行最后的優(yōu)化命令了:
redex path/to/your.apk -o path/to/output.apk
不過這里又出現(xiàn)了個(gè)問題:
又是環(huán)境問題?? ,下面是配置過程:
mafeideAir:~ mafei$ vi ~/.bash_profile
export PATH=/Users/mafei/Development/adt-bundle-mac-x86_64-20140702/sdk/build-tools/23.0.2:$PATH
因?yàn)檫@個(gè)是系統(tǒng)只讀文件所以退出的時(shí)候要輸入!wq才行
這下執(zhí)行下面的命令就完全沒問題啦!
mafeideAir:~ mafei$ cd GitHub/
mafeideAir:GitHub mafei$ cd redex/
mafeideAir:redex mafei$ redex metis_release_v1.0.2.apk -o out.apk
剛剛又去看了下redex的官網(wǎng)發(fā)現(xiàn)FB已經(jīng)把這幾天遇到的一些典型問題都匯總了一下: