vlc android 程式碼編譯--親測可用
程式碼:git://git.videolan.org/vlc-ports/android.git
程式碼版本:375646994d0602
年初的時候搞了三個月的vlc android。昨天看到vlc android的beta版本釋出了,決定編譯一個看看效果。把自己此次的編譯過程記錄下來,供朋友們參考。下文中的檔案路徑,要替換成正確的路徑。
1. 搭建ubuntu android開發環境
要找一個自己喜歡的目錄安裝jdk、SDK、NDK、ANT
1.1 安裝jdk
參考我轉發的《Ubuntu11.10下安裝 jdk-6u30-linux-i586.bin》
1.2 安裝SDK
下載SDK:
把SDK解壓到一個目錄下:
- $ sudo tar -xvf android-sdk_r20-linux.tgz
1.3 安裝NDK
下載NDK:http://developer.android.com/tools/sdk/ndk/index.html
把NDK解壓到一個目錄下:
- $ sudo bzip2 -d android-ndk-r5b-linux-x86.tar.bz2
- $ sudo tar -xvf android-ndk-r5b-linux-x86.tar
1.4 安裝ANT
下載ANT:http://mirror.bit.edu.cn/apache//ant/binaries/apache-ant-1.8.4-bin.tar.gz
解壓:
- $ sudo tar -xvf apache-ant-1.8.4-bin.tar.gz
- $ sudo vim /etc/profile
- export ANT_HOME=/home/workenv/apache-ant-1.8.4
- PATH=$PATH:/home/workenv/apache-ant-1.8.4
- $ source /etc/profile
- $ ant -version
- Apache Ant(TM) version 1.8.4 compiled on May 22 2012
1.5 安裝eclipse:
- $ sudo cp eclipse-jee-indigo-SR1-linux-gtk.tar.gz ../workenv/
- $ cd ../workenv/
- $ sudo gzip -d eclipse-jee-indigo-SR1-linux-gtk.tar.gz
- $ sudo tar -xvf eclipse-jee-indigo-SR1-linux-gtk.tar
- $ sudo chmod 777 -R eclipse/
- $ rm eclipse-jee-indigo-SR1-linux-gtk.tar
1.6 安裝ADT外掛
- $ ./eclips
選擇Add Name:ADT Location:http://dl-ssl.google.com/Android/eclipse/
選擇:AndroidDDMS和AndroidDevelopmentTools
1.7 更新Android SDK API
- $ ./eclips
填入SDK的路徑。
Windows > Android SDK Manger
選擇 2.2 和 4.1
Install
2. 安裝vlc依賴的其他庫:
- $ sudo apt-get build-dep vlc
3. 編譯
3.1 設定環境變數
- $ export ANDROID_SDK=/home/workenv/android-sdk-linux
- $ export ANDROID_NDK=/home/workenv/android-ndk-r8
- $ export PATH=$PATH:$ANDROID_SDK/platform-tools:$ANDROID_SDK/tools如果是 ARMv7和以上並支援NEON的裝置:
- $ export ANDROID_ABI=armeabi-v7a
- $ export ANDROID_ABI=armeabi-v7a
- $ export NO_NEON=1
- Processor : ARMv7 Processor rev 2 (v7l)
- BogoMIPS : 998.36
- Features : swp half thumb fastmult vfp edsp neon vfpv3
- CPU implementer : 0x41
- CPU architecture : 7
- CPU variant : 0x3
- CPU part : 0xc08
- CPU revision : 2
- Hardware : P1Lite Samsung Board
- Revision : 0004
- Serial : 0000000000000000
3.2 獲取程式碼
- $ git clone git://git.videolan.org/vlc-ports/android.git
- $ cd android
3.3 編譯
- $ sh compile.sh
a. 下載vlc程式碼:compile.sh的42行 git clone git://git.videolan.org/vlc.git vlc。
b. 並check out vlc程式碼到e75d2024這個版本:compile.sh的44行 git checkout -B android ${TESTED_HASH}
c. 編譯所有需要的第三方庫,先下載再編譯,這個過程需要很長時間,還可能下載不成功,如果無法下載某些庫,就手動下載下來,並放到這個目錄下即可:android/vlc/contrib/tarballs。
d. vlc的Configuring。
e. vlc的編譯。
f. 編譯android部分程式碼並連結vlc so庫。
4 解決編譯過程中遇到的問題
4.1 錯誤 C compiler cannot create executables
- configure: error: C compiler cannot create executables
- See `config.log' for more details.
- $ vim ./vlc/contrib/android/a52dec/config.log
- /home/workenv/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: crtbegin_dynamic.o: No such file: No such file or directory
- $ find -name crtbegin_dynamic.o
- ./platforms/android-14/arch-x86/usr/lib/crtbegin_dynamic.o
- ./platforms/android-14/arch-mips/usr/lib/crtbegin_dynamic.o
- ./platforms/android-14/arch-arm/usr/lib/crtbegin_dynamic.o
- ./platforms/android-3/arch-arm/usr/lib/crtbegin_dynamic.o
- ./platforms/android-8/arch-arm/usr/lib/crtbegin_dynamic.o
- ./platforms/android-5/arch-arm/usr/lib/crtbegin_dynamic.o
- ./platforms/android-9/arch-x86/usr/lib/crtbegin_dynamic.o
- ./platforms/android-9/arch-mips/usr/lib/crtbegin_dynamic.o
- ./platforms/android-9/arch-arm/usr/lib/crtbegin_dynamic.o
- ./platforms/android-4/arch-arm/usr/lib/crtbegin_dynamic.o
- $ ll ./platforms/android-14/arch-x86/usr/lib/crtbegin_dynamic.o
- $ sudo chmod 755 -R android-ndk-r8
- $ sh compile.sh
4.2 ant錯誤
- /bin/sh: 1: ant: Permission denied
- $ ant -version
- $ source /etc/profile
4.3
- BUILD FAILED
- /home/workenv/android-sdk-linux/tools/ant/build.xml:518: Unable to resolve project target 'android-15'
- $ vim vlc-android/project.properties
- $ vim vlc-android/AndroidManifest.xml
終於:BUILD SUCCESSFUL
後記:
由於之前編譯過很多次,所以這次編譯還算順利。如果有朋友遇到vlc裡的某些程式碼編譯出錯的問題,那麼很可能是許可權、git checkout、git am打補丁的問題。後續我會總結一些vlc android的程式碼架構方面的東西,也會長期學習、關注vlc,希望與大家一起交流。
如果編譯過程中遇到錯誤checking host system type… Invalid configuration `arm-linux-androideabi’: system `androideabi’ not recognized,請在編譯之前執行以下操作:
1.到http://git.savannah.gnu.org/gitweb/?p=config.git;a=tree下載最新的config.guess和config.sub檔案;
2.將下載的檔案拷貝到/usr/share/misc目錄下;
3.重新啟動編譯(sh compile.sh)。
錯誤一:
出錯資訊:
CC posix/plugin.lo
../../src/posix/plugin.c: In function 'module_Load':
../../src/posix/plugin.c:50:50: warning: unused parameter 'lazy' [-Wunused-parameter]
CC posix/thread.lo
../../src/posix/thread.c:85:5: warning: #warning Monotonic clock not available. Expect timing issues. [-Wcpp]
../../src/posix/thread.c: In function 'vlc_cancel':
../../src/posix/thread.c:830:5: error: implicit declaration of function 'pthread_cancel' [-Werror=implicit-function-declaration]
../../src/posix/thread.c: In function 'vlc_savecancel':
../../src/posix/thread.c:847:5: error: implicit declaration of function 'pthread_setcancelstate' [-Werror=implicit-function-declaration]
../../src/posix/thread.c:847:39: error: 'PTHREAD_CANCEL_DISABLE' undeclared (first use in this function)
../../src/posix/thread.c:847:39: note: each undeclared identifier is reported only once for each function it appears in
../../src/posix/thread.c: In function 'vlc_restorecancel':
../../src/posix/thread.c:867:9: error: 'PTHREAD_CANCEL_DISABLE' undeclared (first use in this function)
../../src/posix/thread.c: In function 'vlc_testcancel':
../../src/posix/thread.c:884:5: error: implicit declaration of function 'pthread_testcancel' [-Werror=implicit-function-declaration]
cc1: some warnings being treated as errors
make[3]: *** [posix/thread.lo] Error 1
make[3]: Leaving directory `/srv/android/vlc/android/src'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/srv/android/vlc/android/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/srv/android/vlc/android'
make: *** [all] Error 2
解決方法:
進入下載的android vlc目錄,執行以下指令:
# cd vlc
# git reset --hard origin
# git pull origin master
# git checkout -b android ${TESTED_HASH}
# git am ../patches/*
注:在老的git版本中git checkout並沒有-B的選項,所以一開始執行的時候並沒有下載android版本的vlc程式碼,故使用git checkout -b android ${TESTED_HASH}。
錯誤二:
出錯資訊:
BUILD FAILED
/usr/local/android-sdk-linux/tools/ant/build.xml:517: Unable to resolve project target 'android-15'
Total time: 3 seconds
make: *** [vlc-android/bin/VLC-debug.apk] Error 1
rm android-libs/libmedia.c android-libs/libutils.c android-libs/libstagefright.c android-libs/libbinder.c
解決方法:
進入到android-sdk-linux/tools目錄,執行“./android“,下載Android 4.0.3(API15)相關檔案。
錯誤三:
出錯資訊:
curl -f -L -- "http://git.xiph.org/?p=speex.git;a=snapshot;h=HEAD;sf=tgz" > "../../contrib/tarballs/speex-git.tar.gz"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 814 100 814 0 0 226 0 0:00:03 0:00:03 --:--:-- 23941
../../contrib/src/speex/rules.mak:20: .sum-speex not implemented
touch .sum-speex
touch -r .sum-speex .sum-speexdsp
rm -Rf speex-git
mkdir -p speex-git
zcat "../../contrib/tarballs/speex-git.tar.gz" | (cd speex-git && tar xv --strip-components=1)
gzip: ../../contrib/tarballs/speex-git.tar.gz: not in gzip format
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
make: *** [speex] Error 2
解決方法:
在ie欄中直接輸入“http://git.xiph.org/?p=speex.git;a=snapshot;h=HEAD;sf=tgz”(會開始下載你所需要的檔案),然後將相應下載的壓縮檔案存放於contrib/tarballs/目錄下,將名字改成speex-git.tar.gz。若碰到其它的庫檔案有類似的錯誤,可採用該辦法。