android——CMakeList配置之編譯多個.cpp檔案
上次提到AndroidStudio2.2進行NDK開發超方便的配置方式,不用進行Android.mk 配置,也不用進行Application.mk配置,只要配置CMakeList即可。那麼問題來了,通過該方式生成的配置檔案預設是隻native-lib.cpp一個cpp檔案的,那麼怎麼配置編譯多個.cpp檔案呢?
以之前釋出的
NDK下獲取IEIM並且使用MD5演算法加密
為例,我們另外需要MD5.cpp和IEIM.cpp, 將工程在AndroidStudio2.2中編寫好後,編譯,(⊙o⊙)哦!
密集恐懼症要來了, 忍住,一定要忍住。。。。
這個錯是啥意思 仔細分析 其實就是找不到MD5.cpp和IEIM.cpp中的方法啦。
怎麼解決呢?
Module下有一個CMakeLists.txt 的檔案 預設內容是這樣的,(只貼了需要改動的部分)
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds it for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
# Associated headers in the same location as their source
# file are automatically included.
src/main/cpp/native-lib.cpp )
改為
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds it for you.
# Gradle automatically packages shared libraries with your APK.
file(GLOB native_srcs "src/main/cpp/*.cpp")
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
# Associated headers in the same location as their source
# file are automatically included.
${native_srcs})
哈哈,大功告成!再多個cpp都不成問題啦!快去動手試試吧