How to Include other CMake projects in Android Studio

1k Views Asked by At

Recently, I'v been developing a native c++ project with Android studio, which needs some other external open source libraries. I want to involve these libraries (for example, hello library)inside the Android Studio project by using CMake's add_subdirectory command to ease my code management. I refer the online guide doc from https://developer.android.com/studio/projects/configure-cmake, but not completely. Concretly, I add the following items to my top level CMakeList.txt:

set( lib_src_DIR /Users/dependencies/hello-1.1.1 )
set( lib_build_DIR /Users/dependencies/hello )
file(MAKE_DIRECTORY ${lib_build_DIR})
add_subdirectory( ${lib_src_DIR} ${lib_build_DIR} )

the whole top level CMakeLists.txt post as the following picture: top level CMakeLists.txt

Everything's done, I build this project, what I expect to see is libhello.a in the /Users/dependencies/hello directory, but there's only some Cmake related files, like following: enter image description here

Thers's no libhello.a found in the hello directory and its subdirectories, it seems like my hello library is not compiled at all. The following picture is my hello project's CMakeList.txt: enter image description here I'm sure this hello project can compile because I tried use cmake command to compile it directly, it's ok.

So, why add_subdirectory in the top level CMakeLists.txt don't work? Was I missing some other settings ? By the way, this top level CMakeLists.txt was genereated by the Android Studio automatically when I create the native C++ project, I just add something in it.

1

There are 1 best solutions below

0
candylife9 On

Okay, it turns out that's the Android Studio's bug, it only can generate synamic libraries(.so), if you specify the library as static, it won't compile.