У меня есть нативный андроид проект CMakeList.txt
все работает. Но теперь мне понадобилось добавить еще нативного кода и нужно это сделать отдельным модулем. Для этого я создаю Android lib
(lib_tet_decoder) File->New->NewModule->AndroidLib
, этот модуль имеет свой CMakeList.txt
который знает как его собрать. Что получается, у меня есть основной нативный модуль который уже работает и теперь мне нужно подключить саб нативный модуль. Для этого мне нужно сконфигурировать основной CMakeList.txt
файл , чтоб он знал что у него есть саб модуль и его код нужно использовать.
Согласно вот этому
https://developer.android.com/studio/projects/configure-cmake#include-other-cmake-projects
я добавляю конфиг в свой смейк
...
# Sets libtetdecoder_src_DIR to the path of the target CMake project.
set(LIBTETDECODER_SRC_DIR ../libtetdecoder)
# Sets lib_build_DIR to the path of the desired output directory.
set(LIBTETDECODER_BUILD_DIR ../libtetdecoder/outputs)
file(MAKE_DIRECTORY ${LIBTETDECODER_BUILD_DIR})
# Adds the CMakeLists.txt file located in the specified directory
# as a build dependency.
add_subdirectory( # Specifies the directory of the CMakeLists.txt file.
${LIBTETDECODER_SRC_DIR}
# Specifies the directory for the build outputs.
${LIBTETDECODER_BUILD_DIR})
# Adds the output of the additional CMake build as a prebuilt static
# library and names it lib_gmath.
add_library(lib_tet_decoder STATIC IMPORTED)
set_target_properties(lib_tet_decoder PROPERTIES IMPORTED_LOCATION
${LIBTETDECODER_BUILD_DIR}/${ANDROID_ABI}/liblibtetdecoder.a)
include_directories(${LIBTETDECODER_SRC_DIR}/include)
target_link_libraries( # Specifies the target library.
...
lib_tet_decoder
...)
...
Вроде все должно получиться, но когда запускаю получаю вот такую ошибку
Build command failed.
Error while executing process C:\Users\co\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe
with arguments
{-C C:\TV_repo\co_android\ar_c\libtetplayer\.cxx\cmake\debug\arm64-v8a libtetcodec libtetdecoder libtetplayer}
ninja: Entering directory `C:\TV_repo\co_android\ar_c\libtetplayer\.cxx\cmake\debug\arm64-v8a'
ninja: error: '../libtetdecoder/outputs/arm64-v8a/liblibtetdecoder.a',
needed by '../../../../build/intermediates/cmake/debug/obj/arm64-v8a/liblibtetplayer.so',
missing and no known rule to make it
Как будто он пробует получить .so liblibtetplayer раньше чем он построен. Насколько я понимаю, после того как я указал, что liblibtetplayer это саб модуль он должен его построить, собрать .so liblibtetplayer и только потом пробовать его включить в основную сборку, но что то идет не по плану.
Что делаю не так?
Правка
основной CMakeList.txt
#A few tips about how to build CMakefile
#https://medium.com/@sourav.bh/build-a-native-android-library-or-module-using-ndk-and-cmake-71988b00b5dd
cmake_minimum_required(VERSION 3.4.1)
# Sets libtetdecoder_src_DIR to the path of the target CMake project.
set(LIBTETDECODER_SRC_DIR ../libtetdecoder)
# Sets lib_build_DIR to the path of the desired output directory.
set(LIBTETDECODER_BUILD_DIR ../libtetdecoder/outputs)
file(MAKE_DIRECTORY ${LIBTETDECODER_BUILD_DIR})
# Adds the CMakeLists.txt file located in the specified directory
# as a build dependency.
add_subdirectory( # Specifies the directory of the CMakeLists.txt file.
${LIBTETDECODER_SRC_DIR}
# Specifies the directory for the build outputs.
${LIBTETDECODER_BUILD_DIR})
# Adds the output of the additional CMake build as a prebuilt static
# library and names it lib_gmath.
add_library(lib_tet_decoder STATIC IMPORTED)
set_target_properties(lib_tet_decoder PROPERTIES IMPORTED_LOCATION
${LIBTETDECODER_BUILD_DIR}/${ANDROID_ABI}/liblibtetdecoder.a)
include_directories(${LIBTETDECODER_SRC_DIR}/include)
# Import the ARCore library.
add_library(arcore SHARED IMPORTED)
set_target_properties(arcore PROPERTIES IMPORTED_LOCATION
${ARCORE_LIBPATH}/${ANDROID_ABI}/libarcore_sdk_c.so
INTERFACE_INCLUDE_DIRECTORIES ${ARCORE_INCLUDE}
)
# Import the glm header file from the NDK.
add_library(glm INTERFACE)
set_target_properties(glm PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${ANDROID_NDK}/sources/third_party/vulkan/src/libs/glm)
set(libplayersource
src/main/cpp/utils/util.cc
src/main/cpp/jni_interface.cc
src/main/cpp/co_application.cc
src/main/cpp/renders/background_renderer.cc
src/main/cpp/renders/plane_renderer.cc
src/main/cpp/renders/point_cloud_renderer.cc
src/main/cpp/opengl_render_manager/opengl_render_mng.cc
)
add_library( # Sets the name of the library.
libtetplayer
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
${libplayersource})
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
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)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_include_directories(libtetplayer PRIVATE src/main/cpp)
target_compile_options(libtetplayer PRIVATE
"$<$<CONFIG:RELEASE>:-O3>"
"$<$<CONFIG:DEBUG>:-O0>")
#target_link_libraries( # Specifies the target library.
# libtetcodec
# android
# ${log-lib})
target_link_libraries( # Specifies the target library.
libtetplayer
lib_tet_decoder
arcore
glm
GLESv2
android
# Links the target library to the log library
# included in the NDK.
${log-lib})
саб CMakeList.txt
#For add OpenCV take a look at this video
#https://www.youtube.com/watch?v=jN9Bv5LHXMk
#https://www.youtube.com/watch?v=0fdIiOqCz3o
#Watch these videos than compare with this file and make the same
#!!IMPORTANT!! IF YOU HAVE BUILD ISSUES (LIKE cmake:missing and don't known rule to make it)
#CHECK pathToOpenCv BELLOW AND ALSO CHECK README.txt
#I wrote there some tips
#Version of OpenCV lib is opencv-3.3.1-android-sdk.zip
#A few tips about how to build CMakefile
#https://medium.com/@sourav.bh/build-a-native-android-library-or-module-using-ndk-and-cmake-71988b00b5dd
cmake_minimum_required(VERSION 3.4.1)
set(pathToOpenCv $ENV{OPEN_CV_PATH})
set(CMAKE VERBOSE MAKEFILE on)
set(CMAKE CXX FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
set(OBOE_DIR ../../oboe)
# Set the path to the parserTet library directory
set(PARSER_TET_DIR ../../../co_main/TV_Infrastructure/Tier1.0/TV_TetFileCodec)
set(PARSER_GWS_DIR ../../../co_main/TV_Infrastructure/Tier1.0/GWStdLib)
include_directories(${pathToOpenCv}/sdk/native/jni/include)
add_library(lib_opencv SHARED IMPORTED)
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION
${pathToOpenCv}/sdk/native/libs/${CMAKE_ANDROID_ARCH_ABI}/libopencv_java3.so)
# Add the Oboe library as a subproject. Since Oboe is an out-of-tree source library we must also
# specify a binary directory
add_subdirectory(${OBOE_DIR} ./oboe-bin)
# Include the Oboe headers and shared sample code
include_directories(${OBOE_DIR}/include ${OBOE_DIR}/samples/shared)
set(libdecodersource
src/main/cpp/test_class.cpp
src/main/cpp/jni_interface_tet_decoder.cpp
src/main/cpp/native_codec/texture_codec.cc
src/main/cpp/utils/util.cc
src/main/cpp/utils/configuration.cc
src/main/cpp/utils/measurer.cc
src/main/cpp/utils/profiling.cc
src/main/cpp/utils/loopers/upload_looper.cc
src/main/cpp/renders/model_render/model/mtr_frame_manager.cc
src/main/cpp/renders/model_render/model/tet_frame_manager.cc
src/main/cpp/renders/model_render/utils/condition_event.cc
src/main/cpp/renders/model_render/utils/geometry_loader.cc
src/main/cpp/renders/model_render/utils/model_render_factory.cc
src/main/cpp/renders/model_render/default_dummy_render.cc
src/main/cpp/renders/model_render/mtr_render.cc
src/main/cpp/renders/model_render/tet_stream_render.cc
src/main/cpp/sound/oboe_engine.cc
src/main/cpp/sound/audio/aasset_data_source.cc
src/main/cpp/sound/audio/NDK_extractor.cc
src/main/cpp/sound/audio/player.cc
)
add_library( # Sets the name of the library.
libtetdecoder
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
${libdecodersource})
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_include_directories(libtetdecoder PRIVATE src/main/cpp)
# libtetcodec
set(tet_codec_source
${PARSER_TET_DIR}/TV_TetDecoder/TV_MtrDecoder.cpp
${PARSER_TET_DIR}/TV_TetDecoder/TV_TetDecoder.cpp
${PARSER_TET_DIR}/TV_TetDecoder/TV_TetDecoderImpl.cpp
${PARSER_TET_DIR}/TV_TetDecoder/TV_TetChunkBuffers.cpp
${PARSER_TET_DIR}/TV_TetShared/TV_TetTexture.cpp
${PARSER_GWS_DIR}/GWS_Basics.cpp)
add_library(libtetcodec SHARED ${tet_codec_source})
# Include parserTet headers
include_directories(${PARSER_TET_DIR})
include_directories(${PARSER_GWS_DIR})
target_compile_options(libtetdecoder PRIVATE
"$<$<CONFIG:RELEASE>:-O3>"
"$<$<CONFIG:DEBUG>:-O0>")
target_compile_options(libtetcodec PRIVATE
"$<$<CONFIG:RELEASE>:-O3>"
"$<$<CONFIG:DEBUG>:-O0>")
target_compile_definitions(libtetcodec PRIVATE IS_LIB_TET_CODEC_DEBUG_MODE=false)
target_link_libraries( # Specifies the target library.
libtetdecoder
libtetcodec
oboe
lib_opencv
mediandk
android
# Links the target library to the log library
# included in the NDK.
ПРАВКА2
#A few tips about how to build CMakefile
#https://medium.com/@sourav.bh/build-a-native-android-library-or-module-using-ndk-and-cmake-71988b00b5dd
cmake_minimum_required(VERSION 3.4.1)
# Sets libtetdecoder_src_DIR to the path of the target CMake project.
set(LIBTETDECODER_SRC_DIR ../libtetdecoder)
# Sets lib_build_DIR to the path of the desired output directory.
set(LIBTETDECODER_BUILD_DIR ../libtetdecoder/outputs)
file(MAKE_DIRECTORY ${LIBTETDECODER_BUILD_DIR})
# Adds the CMakeLists.txt file located in the specified directory
# as a build dependency.
add_subdirectory( # Specifies the directory of the CMakeLists.txt file.
${LIBTETDECODER_SRC_DIR}
# Specifies the directory for the build outputs.
${LIBTETDECODER_BUILD_DIR})
# Import the ARCore library.
add_library(arcore SHARED IMPORTED)
set_target_properties(arcore PROPERTIES IMPORTED_LOCATION
${ARCORE_LIBPATH}/${ANDROID_ABI}/libarcore_sdk_c.so
INTERFACE_INCLUDE_DIRECTORIES ${ARCORE_INCLUDE}
)
# Import the glm header file from the NDK.
add_library(glm INTERFACE)
set_target_properties(glm PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${ANDROID_NDK}/sources/third_party/vulkan/src/libs/glm)
set(libplayersource
src/main/cpp/utils/util.cc
src/main/cpp/jni_interface.cc
src/main/cpp/tetavi_application.cc
src/main/cpp/renders/background_renderer.cc
src/main/cpp/renders/plane_renderer.cc
src/main/cpp/renders/point_cloud_renderer.cc
src/main/cpp/opengl_render_manager/opengl_render_mng.cc
)
add_library( # Sets the name of the library.
libtetplayer
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
${libplayersource})
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
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)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_include_directories(libtetplayer PRIVATE src/main/cpp)
target_compile_options(libtetplayer PRIVATE
"$<$<CONFIG:RELEASE>:-O3>"
"$<$<CONFIG:DEBUG>:-O0>")
#target_link_libraries( # Specifies the target library.
# libtetcodec
# android
# ${log-lib})
target_link_libraries( # Specifies the target library.
libtetplayer
libtetdecoder
arcore
glm
GLESv2
android
# Links the target library to the log library
# included in the NDK.
${log-lib})
CMakeLists.txt
или нет? Если есть, то почему вы не используете имя цели из субмодуля, а вместо этого обращаетесь к библиотеке напрямую? И нет, не должен он собирать его до основной сборки - это не так работает. Если cmake может определить зависимость одной цели от другой - тогда да, но у вас то цели не связаны друг с другомимя цели из сабмодуля
? Вот эти строчки из основного файлаtarget_link_libraries( # Specifies the target library. ... lib_tet_decoder ...)
вот я указываю имя цели из сабмодуля, нет?lib_tet_decoder
, если у вас в субмодуле уже есть нужная цельlibtetdecoder
?