[英]How to include library projects in Android Studio that are stored in a separate git repository?
[英]How to Include other CMake projects in Android Studio
最近在用Android studio開發一個原生的c++項目,需要一些其他的外部開源庫。 我想通過使用 CMake 的 add_subdirectory 命令來簡化我的代碼管理,將這些庫(例如,hello 庫)包含在 Android Studio 項目中。 我參考了https://developer.android.com/studio/projects/configure-cmake的在線指南文檔,但不完全。 具體來說,我將以下項目添加到我的頂級 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} )
一切都完成了,我構建了這個項目,我希望看到的是 /Users/dependencies/hello 目錄中的 libhello.a ,但只有一些與 Cmake 相關的文件,如下所示:
在hello目錄及其子目錄中沒有找到libhello.a,看來我的hello庫根本沒有編譯。 下圖是我的hello項目的CMakeList.txt: 我確定這個hello項目可以編譯,因為我試過用cmake命令直接編譯它,沒問題。
那么,為什么頂級 CMakeLists.txt 中的 add_subdirectory 不起作用? 我錯過了一些其他設置嗎? 順便說一句,這個頂級 CMakeLists.txt 是在我創建原生 C++ 項目時由 Android Studio 自動生成的,我只是在其中添加了一些內容。
好吧,原來是Android Studio的bug,它只能生成synamic libraries(.so),如果你把庫指定為static,它不會編譯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.