AndriodStudio集成 FFmpeg环境,报错:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.player-Bhalv81bWdaEyxPpDfXPvg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.player-Bhalv81bWdaEyxPpDfXPvg==/lib/arm64, /system/lib64, /product/lib64]]] couldn't find "libplayer.so"
我的CMakeList文件配置
cmake_minimum_required(VERSION 3.4.1)
# 目录下所有的`.cpp`文件都需要被编译,并保存到全局变量`SOURCE`中。
file(GLOB SOURCE *.cpp)
# 将SOURCE变量中的源文件编译到 player动态库中
add_library(
player
SHARED
${SOURCE})
find_library(
log-lib
log)
#设置头文件的目录。
#编译的时候需要用到的头文件,编译后头文件不会打包到目标库中。这样的话,在native-lib中可以直接引用头文件。
include_directories(include)
# 标志位, clang这个编译期来构建
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${CMAKE_SOURCE_DIR}/../../../libs/${CMAKE_ANDROID_ARCH_ABI}")
# 将armeabi-v7a目录下的静态库文件,链接到动态库`player`中。
# 将会去编译环境目录去找 avfilter avformat ...等静态库,所以需要配置编译环境路径
target_link_libraries(
player
avfilter avformat avcodec avutil swresample swscale
${log-lib})
app的build.gradle文件
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.player"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
abiFilters "armeabi-v7a"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
}
修改 app 的build.gradle文件
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.player"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
abiFilters "armeabi-v7a"
}
}
ndk{
abiFilters "armeabi-v7a"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
}