Android NDK,CMake和其他库 [英] Android NDK, CMake with other libraries

查看:106
本文介绍了Android NDK,CMake和其他库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在尝试使用Android Studio上的Android NDK构建和测试CMake.我可以编译我的库,但是它似乎不想拉任何第三方依赖项.我一直在仔细阅读工具链,寻找更好的文档,但是没有运气.有人可以告诉我我是否想念吗?

So I am trying to build and test out a CMake with the Android NDK on Android Studio. I can get my library to compile, but it doesn't seem to want to pull any third-party dependencies over. I've been reading through the toolchain and looking for better documentations, with no luck. Can someone tell me if I am missing?

cmake_minimum_required(VERSION 3.4.1)

set(SFML_PATH ${ANDROID_NDK}/sources/sfml)
set(SFML_LIB_PATH ${SFML_PATH}/lib/${ANDROID_NDK_ABI_NAME})

set(SFML_LIB_SYSTEM ${SFML_LIB_PATH}/libsfml-system.so)
set(SFML_LIB_AUDIO ${SFML_LIB_PATH}/libsfml-audio.so)
set(SFML_LIB_GRAPHICS ${SFML_LIB_PATH}/libsfml-graphics.so)
set(SFML_LIB_NETWORK ${SFML_LIB_PATH}/libsfml-network.so)
set(SFML_LIB_WINDOW ${SFML_LIB_PATH}/libsfml-window.so)
set(SFML_LIB_ACTIVITY ${SFML_LIB_PATH}/libsfml-activity.so)
set(SFML_LIB_MAIN ${SFML_LIB_PATH}/libsfml-main.a)


set(SFML_LIBS ${SFML_LIB_SYSTEM} ${SFML_LIB_GRAPHICS} ${SFML_LIB_AUDIO} ${SFML_LIB_WINDOW} ${SFML_LIB_ACTIVITY})

include_directories(${SFML_PATH}/include)
link_directories(${SFML_LIB_PATH})

add_library(native-lib SHARED
    src/main/cpp/native-lib.cpp)

target_link_libraries(native-lib log ${SFML_LIBS})

#file(COPY ${SFML_LIBS} DESTINATION ${__android_install_path})
FOREACH(SFML_LIB ${SFML_LIB})
    execute_process( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${SFML_LIB}" "${LIBRARY_OUTPUT_PATH}/${SFML_LIB}" RESULT_VARIABLE __fileCopyProcess )
    MESSAGE("Lib: ${SFML_LIB}")
ENDFOREACH(SFML_LIB)

上面是我的CMakeLists.txt.我进行了一些小技巧,使其能够与SFML一起使用这些路径进行编译,因为我尚未找到有关CMake和Android的良好文档.

Above is my CMakeLists.txt. I have done a little hacking to get it to compile with SFML with the paths, as I have not found good documentation with CMake and Android yet.

推荐答案

请为以下内容添加更多信息: 但是它似乎不想拉扯任何第三方的依赖关系."?

May you add more info for: "but it doesn't seem to want to pull any third-party dependencies over."?

这一个:
https://github.com/googlesamples/android-ndk/tree/master/hello-libs 具有静态和共享的第三方库,您可以尝试.

this one:
https://github.com/googlesamples/android-ndk/tree/master/hello-libs has static and shared 3rd party libs, you may try it.

对于共享的依赖库,您需要将它们打包到APK中,这是在gradle中完成的,cmake不会这样做.
上面的示例表明,基本上也需要将它们复制到您的app/src/main/jniLibs中,以便将它们打包到apk中,并推送到您的android手机/平板电脑中.在运行时可以加载它们.
我试图将一组库放在一个目录中,并使用

For the shared dependent lib, you will need to pack them into APK, that is done inside gradle, cmake will not do it.
The above example shows that, basically they need to be copied into your app/src/main/jniLibs too so they will be packed into apk, and pushed to your android phone/tablet. At runtime they could be loaded.
I have tried to put a group of libraries into one directory, and use

  • link_directories(...)

然后将库名称直接放入

  • target_link_libraries(...)

也可以.确保您打算为您的应用程序支持的ABI具有正确的库(看起来您只是在为一个ABI构建).

also works. Make sure you have the right libs for the ABIs you intend to support for your app [looks like you are just building for one ABI].

这篇关于Android NDK,CMake和其他库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆