我已经开始在
Android Studio中使用Android NDK进行开发,但由于它没有适当的C支持,所以它很痛苦.所以我尝试创建一个cmake项目来构建我的东西.我已经使用了
android-cmake并且到目前为止效果很好,除了< android / log.h>,< android / native_window.h>可能所有< android / *>夹杂物无法找到. IDE(CLion)也因为它而将它们标记为缺失.我在CMakeLists.txt中遗漏了什么吗?
这是CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.4)
project(App)
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(AndroidNdkGdb)
include(AndroidNdkModules)
android_ndk_gdb_enable()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/src/main/libs/armeabi-v7a)
set(LIBRARY_DEPS GLESv2 android log)
include_directories(${PROJECT_SOURCE_DIR}/src/main/lib/armeabi-v7a/freetype/include/freetype2)
file(GLOB_RECURSE SRCS *.cpp)
file(GLOB_RECURSE HDRS *.h)
add_library(nativeegl SHARED ${SRCS} ${HDRS})
target_link_libraries(nativeegl log android)
android_ndk_gdb_debuggable(nativeegl)
和cmake发射参数:
-DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake \
-DANDROID_NDK=/opt/android-ndk -DCMAKE_BUILD_TYPE=Debug \
-DANDROID_ABI="armeabi-v7a" -DANDROID_STL=gnustl_static \
-DANDROID_NATIVE_API_LEVEL=android-21
这是我在工作室中构建的原始Android.mk工作正常:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := nativeegl
LOCAL_SRC_FILES := $(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/*.cpp))
LOCAL_C_INCLUDES :=
LOCAL_CFLAGS := -std=c++11 -O2 -Wtype-limits -Wmissing-field-initializers -Wreturn-type -Wuninitialized
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2
LOCAL_STATIC_LIBRARIES := android_native_app_glue ndk_helper freetype
include $(BUILD_SHARED_LIBRARY)
$(call import-add-path,$(LOCAL_PATH)/../lib/$(TARGET_ARCH_ABI))
$(call import-module,freetype)
和Application.mk:
APP_STL := gnustl_static
APP_PLATFORM := android-10
APP_ABI := armeabi-v7a
感谢您的帮助.