Ubuntu下为AndroidStudio编译并使用x264(一)ndk部分

1.1 下载ndk,并编译,做示例程序测试
1、下载Android NDK自解压包,
官方地址:
https://developer.android.com/ndk/downloads/index.html#download
下载:
$ wget -c http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin


2、解压,
将Android NDK压缩包解压到你想要的目录下,如
/opt/android/ndk/

ndk$ chmod a+x android-ndk-r10e-linux-x86_64.bin
ndk$ ./android-ndk-r10c-linux-x86_64.bin

解压后目录结构为:
/opt/android/ndk/android-ndk-r10e


3、配置PATH路径:
命令:
$ sudo vim /etc/profile,在文件末尾加入如下内容:

#set NDK env
export NDK_HOME=/opt/android/ndk/android-ndk-r10e
export PATH=$NDK_HOME:$PATH
【保存并退出】
$ source /etc/profile
至此 android NDK 安装配置完毕。


4、编译sample工程:
执行命令
$ cd /opt/android/ndk/android-ndk-r10e/samples/hello-jni

进入示例项目根目录,然后执行如下命令:
$ ndk-build

您将看到系统会编译出libhello-jni.so
至此示例项目编译完成,可将hello-jni项目导入ADT进行进一步的测试。

1.2 使用ndk编译x264
1.  下载源码并编译
$ cd /opt/android/ndk/android-ndk-r10e/resources
$ git clone http://git.videolan.org/git/x264.git
$ cd x264

修改configure文件
$ vim configure
将下面的这四句:
else
echo "SOSUFFIX=so" >> config.mak
echo "SONAME=libx264.so.$API" >> config.mak
echo "SOFLAGS=-shared -Wl, -soname, \$(SONAME)$SOFLAGS" >> config.mak
中的这句:
echo "SONAME=libx264.so.$API" >> config.mak
改成:
echo "SONAME=libx264.so" >> config.mak
【保存并退出】

创建配置脚本
$ vim android_x264_configure.sh
#!/bin/bash 
NDK=/opt/android/ndk/android-ndk-r10e
SYSROOT=$NDK/platforms/android-9/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64

function build_one 
{
./configure \
--prefix=$PREFIX \
--enable-shared \
--enable-static \
--enable-strip \
--enable-cli \
--enable-pic\
--enable-cross-compile \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--host=arm-linux-androideabi \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
}
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS=""

build_one
【保存并退出】

$ chmod +x android_x264_configure.sh
$ ./android_x264_configure.sh
platform:      ARM
byte order:    little-endian
system:        LINUX
cli:           no
libx264:       internal
shared:        yes
static:        yes
asm:           yes
interlaced:    yes
avs:           avxsynth
lavf:          no
ffms:          no
mp4:           no
gpl:           yes
thread:        posix
opencl:        yes
filters:       crop select_every
debug:         no
gprof:         no
strip:         yes
PIC:           yes
bit depth:     8
chroma format: all

You can run 'make' or 'make fprofiled' now.

$ make
$ make install
$ ls -R android
android:
arm

android/arm:
Android.mk  bin  include  lib

android/arm/bin:
x264

android/arm/include:
x264_config.h  x264.h

android/arm/lib:
libx264.a  libx264.so  pkgconfig

android/arm/lib/pkgconfig:
x264.pc

$ vim android/arm/Android.mk
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VRS)
LOCAL_MODULE := libx264
LOCAL_SRC_FILES := lib/libx264.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)

【保存并退出】


至此ndk配置完毕.后面是配置Android Studio的部分。


fedora 23安装android studio:http://www.linuxdiyf.com/linux/16294.html

ubuntu15.04下Android studio开发配置完全教程:http://www.linuxdiyf.com/linux/14284.html

Ubuntu上安装Android Studio 1.3(谷歌Android IDE开发):http://www.linuxdiyf.com/linux/13264.html

在64位ubuntu15.04中安装android studio开发环境:http://www.linuxdiyf.com/linux/12996.html

在Ubuntu 15.04里安装Visual Studio Code:http://www.linuxdiyf.com/linux/12987.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值