1.1 下载ndk,并编译,做示例程序测试
1、下载Android NDK自解压包,
官方地址:
https://developer.android.com/ndk/downloads/index.html#download
下载:
$ wget -c
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
$ 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 \
--disable-gpac \
--disable-cli \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--host=arm-linux \
--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的部分。
阅读(3887) | 评论(0) | 转发(0) |