Android Studio NativeActivity未定义对“输入队列hasEvents”的引用

时间:2018-08-27 16:00:59

标签: android android-studio c++11 cmake android-ndk

我有一个具有本地活动的本地android studio项目,我想处理用户的输入,因此我使用以下内容:

#include <android/input.h>
#include <android_native_app_glue.h>
#include <android/log.h>
#include "Game/Game.h"

#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native- 
activity", __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "native- activity", __VA_ARGS__))

void AInputQueueCreated(ANativeActivity* activity,AInputQueue* queue){
    LOGW("InputQueue created: %p\n", queue);
    AInputEvent* event = NULL;
    while (AInputQueue_getEvent(queue, &event) >= 0) {
        //LOGW("New input event: type=%d\n", AInputEvent_getType(event));
    }
}
__attribute__((visibility("default")))
void ANativeActivity_onCreate(ANativeActivity* activity,void* savedState, 
size_t savedStateSize) {
    LOGW("Creating: %p\n", activity);
    activity->callbacks->onInputQueueCreated=AInputQueueCreated;
}

运行此命令时,我会得到undefined reference to 'AInputQueue_hasEvents',如果删除AInputQueue_getEvent,它将运行没有问题。

这是CMakelist:

cmake_minimum_required(VERSION 3.4.1)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
                ${ANDROID_NDK}/sources/android/native_app_glue/
                src/main/jniLibs)

add_library( app-glue STATIC  
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c )
add_library( cubat SHARED src/main/cpp/main.cpp )

find_library(log-lib log )

target_link_libraries( cubat app-glue ${log-lib} )

1 个答案:

答案 0 :(得分:1)

我在android文件的链接部分添加了CMakeLists.txt,它起作用了

target_link_libraries( cubat app-glue ${log-lib} android)