Mac编译vlc-android

来源:互联网 发布:three.js空调贴图 编辑:程序博客网 时间:2024/06/05 20:22

这篇文章用于记录在Mac上编译vlc-android源码的过程以及遇到的各种坑。

vlc-android源码网站:https://code.videolan.org/videolan/vlc-android
编译指导wiki网址:https://wiki.videolan.org/AndroidCompile/

请尊重博主劳动成果,转载请标明原文出处和作者。

下载vlc-android

使用git下载将vlc-android下载到本地。

git clone https://code.videolan.org/videolan/vlc-android.git 

Android相关的工具

最好将Android SDK中的tools和platform及编译sdk更新到最新。NDK的版本需要13+,最好更新到最新版本,使用低版本的NDK会报错。

在当前用户的.bash_profile文件中将SDK和NDK的安装路径添加到path中:

export ANDROID_SDK=/xxx/xxx/android-sdkexport ANDROID_NDK=/xxx/xxx/android-ndkexport PATH=$PATH:$ANDROID_SDK/platform-tools:$ANDROID_SDK/tools

下载其它软件包

wiki上Ubantu系统上需要安装的软件包:

sudo apt-get install automake ant autopoint cmake build-essential libtool \     patch pkg-config protobuf-compiler ragel subversion unzip git \    openjdk-8-jre openjdk-8-jdk

Mac上可以参照这个安装相关的软件,如果已安装,则可以跳过。如果没有安装Homebrew,需要先安装该软件包。具体安装步骤请查看:https://brew.sh/index_zh-cn.html。然后使用brew命令安装所缺的软件包。

安装过程中遇到的一些问题:

使用brew install autopoint安装autopoint软件包,运行结果如下:

MacBook-Air:~ $ brew install autopointError: No available formula with the name "autopoint" ==> Searching for a previously deleted formula...Warning: homebrew/core is shallow clone. To get complete history run:  git -C "$(brew --repo homebrew/core)" fetch --unshallowError: No previously deleted formula found.==> Searching for similarly named formulae...Error: No similarly named formulae found.==> Searching taps...Error: No formulae found in taps.

提示错误:Homebrew库中并没有该软件包。

google上找了一大圈,才发现Mac中并没有这个软件包。最后在Homebrew的git上的[autopoint #24070]
(https://github.com/Homebrew/legacy-homebrew/issues/24070)问题中找倒解决办法。其实这个软件包被存放到gettext中,使用brew install gettext安装该软件。它会被安装到/usr/local/Cellar目录中,在gettext/0.19.8.1/bin目录中便有autopoint。需要将‘/usr/local/Cellar/gettext/0.19.8.1/bin’添加到path,这样就能使用autopoint。

编译

进入到vlc-android工程的根目录,执行如下命令:

./compile.sh

在编译的过程中遇到了不少问题:

1,sha1sum错误
错误信息:

./compile-libvlc.sh: line 768: sha1sum: command not found

直接使用brew install sha1sum命令安装,结果安装失败,提示没有sha1sum。在HOWTO: Install md5sum & sha1sum on Mac OS X这篇博客中找到软件包的名称:md5sha1sum。然后使用brew install md5sha1sum命令安装。

2,GP错误
错误信息:

{standard input}: Assembler messages:{standard input}:146: Error: unknown register alias 'GP'clang38: error: assembler command failed with exit code 1 (use -v to see invocation)

需要修改vlc-android/vlc/contrib/src/ffmpeg/rules.mak文件,在该文件的FFMPEGCONF配置中添加’–disable-asm \’。
添加结果如下图:
add_asm

3,网络问题
google被墙,导致constraint-layout的pom下载失败。错误信息:

FAILURE: Build failed with an exception.* What went wrong:A problem occurred configuring project ':vlc-android'.> Could not resolve all dependencies for configuration ':vlc-android:_chromeMIPS64SignedReleaseApkCopy'.   > Could not resolve com.android.support.constraint:constraint-layout:1.1.0-beta1.     Required by:         project :vlc-android      > Could not resolve com.android.support.constraint:constraint-layout:1.1.0-beta1.         > Could not get resource 'https://maven.google.com/com/android/support/constraint/constraint-layout/1.1.0-beta1/constraint-layout-1.1.0-beta1.pom'.            > Could not GET 'https://maven.google.com/com/android/support/constraint/constraint-layout/1.1.0-beta1/constraint-layout-1.1.0-beta1.pom'.               > Remote host closed connection during handshake

开启Android Studio,点击“SDK Manager”图标,在弹出的“Default Preferences”设置框中选择“SDK Tools”项,然后勾选“Show Packages Details”,继续勾选“ConstraintLayout for Android”和“Solver for ConstraintLayout”,再点击“OK”按钮,便会自动下载ConstraintLayout相关aar文件。
如下图:
sdk
下载下来最新的ConstraintLayout版本为1.0.2,需要将工程根目录的build.gradle文件中”constraintLayoutVersion = ‘1.1.0-beta1’”中的’1.1.0-beta1’改为’1.0.2’。

再次运行./compile.sh,又报出编译问题:

vlc-android/build/intermediates/data-binding-layout-out/vanillaARMv7/debug/layout/info_activity.xml:152: AAPT: No resource identifier found for attribute 'barrierDirection' in package 'org.videolan.vlc.debug'vlc-android/build/intermediates/data-binding-layout-out/vanillaARMv7/debug/layout/info_activity.xml:152: AAPT: No resource identifier found for attribute 'constraint_referenced_ids' in package 'org.videolan.vlc.debug'

出错的布局文件位置:

            <android.support.constraint.Barrier                android:id="@+id/barrier"                android:layout_width="0dp"                android:layout_height="0dp"                vlc:layout_constraintTop_toTopOf="@id/length_title"                vlc:layout_constraintBottom_toBottomOf="@id/size_title"                vlc:barrierDirection="end"                vlc:constraint_referenced_ids="size_title, length_title"/>

这是因为1.0.2版本的ConstratintLyaout中无android.support.constraint.Barrier这个类,所以info_activity.xml中’barrierDirection’和’constraint_referenced_ids’获取不到对应的资源。于是,又将build.gradle文件中constraintLayoutVersion信息改回’1.1.0-beta1’。

再次运行compile.sh文件,结果还是无法获取pom。

在网上查看许多博客和文档,最后发现工程根目录的build.gradle文件maven中的url有一个可选项,于是将url改为可选的值。如下所示:

allprojects {    repositories {        maven {            //url 'https://maven.google.com'            // Alternative URL is 'https://dl.google.com/dl/android/maven2/'            url 'https://dl.google.com/dl/android/maven2/'        }        jcenter()    }}

继续运行./compile.sh,等待了几分钟,终于编译成功。

compile_result

运行

编译生成的apk在vlc-android/build/outputs/apk/VLC-Android-2.1.16-ARMv7.apk。
使用x86的模拟器运行apk,结果安装后运行失败。以为生成的apk有问题,使用手机运行,能够正常运行。模拟运算失败的原因是不支持生成的so文件。
运行截图:
vl c_0

vlc_1

vlc_2

vlc_3

vlc_4

总结

网络实在是影响编译最大问题,需要一把畅通的梯子,能够下载SDK,NDK和工程中引用到的第三方软件或工程。还有就是最好使用Ubantu或其它linux系统来编译,这样遇到的问题会少很多。

如果觉得使用命令行不是很方便,也可以使用Android Studio导入工程,然后Run和修改。

参考博客

Android版本-编译VLC
http://hanhailong.com/2015/10/27/Android%E7%89%88%E6%9C%AC-%E7%BC%96%E8%AF%91VLC/

【VLC-Android】Mac下编译vlc-android
http://www.cnblogs.com/over140/p/3924209.html

Mac OS 下编译Vlc for android
http://www.jianshu.com/p/9b35e3fd2c8c

原创粉丝点击