【发布时间】:2017-02-15 04:28:21
【问题描述】:
我使用Android Studio 2.2的cmake来构建原生代码,在原生代码中我调用了ffmpeg api,所以要打包ffmpeg库。我的CMakelists.txt如下:
cmake_minimum_required(VERSION 3.4.1)
include_directories(libs/arm/include)
link_directories(libs/arm/lib/)
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
# Associated headers in the same location as their source
# file are automatically included.
src/main/cpp/native-lib.cpp )
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.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
add_library(avcodec-57 SHARED IMPORTED)
set_target_properties(avcodec-57 PROPERTIES IMPORTED_LOCATION C:/Users/tony/Desktop/MyApplication/app/libs/arm/lib/libavcodec-57.so)
target_link_libraries(native-lib avcodec-57)
target_link_libraries(native-lib avformat-57)
target_link_libraries(native-lib avutil-55)
target_link_libraries(native-lib avfilter-6)
在这种情况下,我可以成功制作项目,但是当我将 apk 安装到模拟器并运行时,它失败并显示找不到“libavcodec-57.so”。 然后我用工具(analyze apk)查看了apk,发现ffmpeg库没有打包。
【问题讨论】:
-
我们有同样的问题。经过进一步调查,我们发现根本没有找到静态或共享库。您可以使用“find_library”和直接路径搜索来测试它。
-
我使用 find_library(avcodec-lib NAMES avcodec-57 HINTS C:/Users/tony/Desktop/MyApplication/app/libs/armeabi/lib/) 但失败了。
-
只是我们取消了进一步的调查,因为这似乎是与 Android Studio 相关的问题。我找到了code.google.com/p/android/issues/detail?id=211927。
-
您可以尝试在问题 211927 中报告并绕过参数。例如。 find_library(avcodec-lib NAMES avcodec-57 HINTS C:/Users/tony/Desktop/MyApplication/app/libs/armeabi/lib/CMAKE_FIND_ROOT_PATH_BOTH NO_DEFAULT_PATH) 但对我们来说这也行不通。我们现在将切换到使用 Android.mk 和 Application.mk 的旧方法
-
它仍然无法工作。也许我只能切换到旧方法。
标签: android android-studio cmake