【问题标题】:Android NDK Build failing for simple native functionAndroid NDK Build 对于简单的本机功能失败
【发布时间】:2013-04-12 20:51:18
【问题描述】:

我正在尝试使用 ndk-build 构建一个非常简单的本机函数并收到以下错误。

DriverAdapter.cpp:6:69: error: expected ',' or '...' before 'this'

以下是我的 .mk 和 .cpp 文件

DriverAdapter.cpp

#include <jni.h>
#include <string.h>
#include <android/log.h>
#define DEBUG_TAG "NDK_AndroidNDK1SampleActivity"

void Java_com_ihearhtpi_MainActivity_helloLog(JNIEnv * env, jobject this, jstring logThis)
{
   jboolean isCopy;
    const char * szLogThis = (*env)->GetStringUTFChars(env, logThis, &isCopy);
    __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:LC: [%s]", szLogThis);
    (*env)->ReleaseStringUTFChars(env, logThis, szLogThis);
}

Android.mk

LOCAL_PATH := $(call my-dir)

include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE    :=driver
LOCAL_SRC_FILES :=DriverAdapter.cpp
include $(BUILD_SHARED_LIBRARY)

不知道为什么会这样。

【问题讨论】:

    标签: android c++ android-ndk makefile build-error


    【解决方案1】:

    问题是this 是c++ 关键字。而且你不能使用关键字作为变量名。

    【讨论】:

    • 常用的有以下几种:thiz、self、me、_pThis...选择一个:)
    【解决方案2】:

    你不能将你的论点命名为“this”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-30
      • 1970-01-01
      • 1970-01-01
      • 2012-03-15
      • 2018-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多