I’m trying to run my Native C++ project on Android Studio and i need to compile my C++ part using cmake.
I need to use this repository for reading json:
https://github.com/nlohmann/json
NOTE: Using it with this command is not my intention and I cannot use this solution:
find_package(nlohmann_json 3.11.3 REQUIRED)
I have to use the whole repo code in my project.
My problem is that when I try to build it I get the follwing error:
C:/Users/XXXXXXXXXX/AndroidStudioProjects/nav/app/src/main/cpp/nlohmann/json.hpp:34:10:fatal error: 'nlohmann/adl_serializer.hpp' file not found #include <nlohmann/adl_serializer.hpp>
The adl_serializer.hpp file is there 100%. The problem is that i call this include from nlohmann/json.hpp which already is in the nlohmann directory and therefore I think it is looking for something like nlohmann/nlohmann/adl_serializer.hpp.
I already tried to update my cmake:
cmake_minimum_required(VERSION 3.22.1)
project(nav)
set(djinni_dir ../../../../djinni)
# Path to djinni support-lib code
set(support_dir ${djinni_dir}/djinni-support-lib/djinni/jni)
# Path to Djinni-generated files
set(DJINNI_GENERATED_SRC_DIR "${CMAKE_SOURCE_DIR}/../../")
# Path to the nlohmann directory for JSON read
set(NLOHMANN_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/nlohmann")
# Path to the generated code and our own c++ implementations
set(include_dirs
${DJINNI_GENERATED_SRC_DIR}/cpp
${DJINNI_GENERATED_SRC_DIR}/jni
${NLOHMANN_INCLUDE_DIR}
)
# Djinni support code that need to be compiled
file(
GLOB_RECURSE support_srcs
${support_dir}/*.cpp)
# Collect all generated and source files
file(GLOB_RECURSE lib_srcs
${DJINNI_GENERATED_SRC_DIR}/cpp/*.cpp
${DJINNI_GENERATED_SRC_DIR}/jni/*.cpp
)
# All the implementation files that make up our library
set(complete_srcs ${support_srcs} ${lib_srcs})
add_library( # Sets the name of the library.
navigator
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp
nav.cpp
${complete_srcs})
target_include_directories(
navigator
PUBLIC
${include_dirs}
${support_dir})
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.
navigator
# Links the target library to the log library
# included in the NDK.
${log-lib})
and tried changing this line:
set(NLOHMANN_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/nlohmann")
for that:
set(NLOHMANN_INCLUDE_DIR "${CMAKE_SOURCE_DIR}")
But it doesn’t solve my case.
Another issue is that I probably shouldn’t use <> instead of “” around #includes, but changing this now didn’t solve my problem as well.