Gradle NDK cmake construct does not work during binding

I am creating a non-trivial android library using gradle tools for building android v2.2.0 that reference a dozen ready-made .a files, the output should be a .so file. When I try to convert from ndk-build to cmake I can not properly link the .so file, because as a result of the ninja build, it seems that I could not find the headers of the static libraries.

CMakeLists.txt

 cmake_minimum_required(VERSION 3.4.1) set(CMAKE_VERBOSE_MAKEFILE on) include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/prebuilt/include ) add_library(precompiledA STATIC IMPORTED) set_target_properties(precompiledA PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt/dcmtk/lib/libprecompiledA.a) add_library(precompiledB STATIC IMPORTED) set_target_properties(precompiledB PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt/dcmtk/lib/libprecompiledB.a) add_library(precompiledC STATIC IMPORTED) set_target_properties(precompiledC PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt/dcmtk/lib/libprecompiledC.a) add_library( jni-library SHARED hello.cpp ) find_library( log-lib log ) target_link_libraries( jni-library precompiledA precompiledB precompiledC ${log-lib} ) 

build.gradle

 apply plugin: 'com.android.library' android { compileSdkVersion 24 buildToolsVersion "24.0.2" defaultConfig { minSdkVersion 19 targetSdkVersion 24 ndk { abiFilters 'armeabi-v7a' } externalNativeBuild { cmake { arguments '-DANDROID_STL=gnustl_static', '-DANDROID_CPP_FEATURES=exceptions' } } } externalNativeBuild { cmake { path 'src/main/cpp/CMakeLists.txt' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) } 

Error - abbreviated

 ld: error: cannot find -lprecompiledA undefined references galore... 

When it comes to calling gradle, .o files are generated, but during the connection, the headers associated with the static libraries seem to be missing and the connection fails. Is it possible to tell cmake where the static library headers are for reference time?

+5
source share
1 answer

Fix undefined links

The errors I made did not use target_include_directories without specifying the absolute path to the library and without forgetting the ${ANDROID_ABI} variable to get the correct binary version.

 cmake_minimum_required( VERSION 3.4.1 ) set( CMAKE_VERBOSE_MAKEFILE on ) add_library( precompiledA STATIC IMPORTED ) set_target_properties( precompiledA PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/mylib/lib/${ANDROID_ABI}/libprecompiledA.a ) add_library( precompiledB STATIC IMPORTED ) set_target_properties( precompiledB PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/mylib/lib/${ANDROID_ABI}/libprecompiledB.a ) add_library( precompiledC STATIC IMPORTED ) set_target_properties( precompiledC PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/prebuilt_libs/mylib/lib/${ANDROID_ABI}/libprecompiledC.a ) find_library( log-lib log ) target_include_directories( dicom-jni PRIVATE prebuilt_libs/mylib/${ANDROID_ABI}/include ) add_library( jni-library SHARED hello.cpp ) target_link_libraries( jni-library precompiledA precompiledB precompiledC ${log-lib} ) 
0
source

Source: https://habr.com/ru/post/1257574/


All Articles