android studio 用cmake加入FFMPEG so及头文件
1. 下载最新的android studio, 同时更新cmake
2. 把要加载的so放到相应cpu架构目录下,头文件也一样,如果有多个头文件,也放到一个文件夹下,跟so的根目录同级,如下图:
3. 修改app下的build.gradle,在 android{}中修改
android {compileSdkVersion 22
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.android.test"
minSdkVersion 19
targetSdkVersion 22
versionCode 0
versionName 1
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
ndk {
abiFilters 'armeabi'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}
4. CMakeList.txt文件放在app目录下,跟build.gradle同级
5. 修改CMakeList.txt
make_minimum_required(VERSION 3.4.1)
add_library( # Sets the name of the library.
VideoPlayer
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/VideoPlayer.c )
add_library( avcodec-57
SHARED
IMPORTED )
set_target_properties( avcodec-57
PROPERTIES IMPORTED_LOCATION
../../../../libs/armeabi/libavcodec-57.so )
add_library( avformat-57
SHARED
IMPORTED )
set_target_properties( avformat-57
PROPERTIES IMPORTED_LOCATION
../../../../libs/armeabi/libavformat-57.so )
add_library( avutil-55
SHARED
IMPORTED )
set_target_properties( avutil-55
PROPERTIES IMPORTED_LOCATION
../../../../libs/armeabi/libavutil-55.so )
add_library( swresample-2
SHARED
IMPORTED )
set_target_properties( swresample-2
PROPERTIES IMPORTED_LOCATION
../../../../libs/armeabi/libswresample-2.so )
add_library( swscale-4
SHARED
IMPORTED )
set_target_properties( swscale-4
PROPERTIES IMPORTED_LOCATION
../../../../libs/armeabi/libswscale-4.so )
include_directories( libs/include )
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
target_link_libraries( # Specifies the target library.
VideoPlayer
android
avcodec-57
avformat-57
avutil-55
swresample-2
swscale-4
# Links the target library to the log library
# included in the NDK.
${log-lib} )
6.引用SO