一、AndroidStudio 混合程式設計流程
1.1 設定支援的arm的類型
在build.gradle中設定arm的類型,如果不設定也就是忽略此步驟,預設支援所有的類型,運作項目後,系統根據自身的arm類型,自動選擇加載
......
android {
defaultConfig {
....
ndk {
// Specifies the ABI configurations of your native
// libraries Gradle should build and package with your APK.
abiFilters 'armeabi-v7a','arm64-v8a'
}
......
}
......
1.2 編譯自定義庫和第三方庫
1.2.1 編譯第三方庫
CMakeList.txt:
#1.設定第三方庫頭檔案所在位置
#此目錄為CMakeList.txt父目錄下的thirdLibrary目錄
include_directories(${PROJECT_SOURCE_DIR}/thirdLibrary/include)
add_library(thirdLibrary
SHARED
IMPORTED)
# 設定第三方動态庫屬性(存儲位置)
#此目錄為CMakeList.txt父目錄下的opus/libs目錄
set_target_properties(thirdLibrary
PROPERTIES IMPORTED_LOCATION
${PROJECT_SOURCE_DIR}/thirdLibrary/libs/${ANDROID_ABI}/libthirdLibrary.so)`
1.2.2 在自定義庫中加載第三方庫
add_library( # Sets the name of the library.
selfLibrary
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
selfLibraryFunction.cpp
}
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.
selfLibrary
thirdLibrary
# Links the target library to the log library
# included in the NDK.
${log-lib} )
二、Eclipse 混合程式設計流程
2.1 編譯自定義庫和第三方庫
2.1.1 編譯第三方庫
Android.mk
#include $(CLEAR_VARS)
#LOCAL_MODULE := thirdLibrary
#LOCAL_SRC_FILES := ./kwPrivateData/libs/armeabi-v7a/libthirdLibrary.so
#include $(PREBUILT_SHARED_LIBRARY)
2.1.2 在自定義庫中加載第三方庫
include $(CLEAR_VARS)
LOCAL_SHARED_LIBRARIES := thirdLibrary
LOCAL_MODULE := selfLibrary
LOCAL_C_INCLUDES := \
$(LOCAL_PATH) \
LOCAL_SRC_FILES := \
selfLibraryFunction.cpp
LOCAL_LDLIBS += -llog
include $(BUILD_SHARED_LIBRARY)