Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

error: cannot initialize a parameter of type 'void *' with an rvalue of type 'void (*)(JNIEnv *, jobject)' (aka 'void (*)(_JNIEnv *, _jobject *)') #17

Open
lattice0 opened this issue Oct 28, 2019 · 2 comments

Comments

@lattice0
Copy link

JniHelpers/src/test/cpp/PersistedObject.cpp:35:30: error: cannot initialize a parameter of type 'void *' with an rvalue of type 'void (*)(JNIEnv *, jobject)' (aka 'void (*)(_JNIEnv *, _jobject *)')

Maybe an error because of the new NDK that uses clang?

@nanmi
Copy link

nanmi commented Dec 9, 2020

you should add this (void*) like addNativeMethod("destroy", (void*)&PersistedObject::nativeDestroy, kTypeVoid, NULL);

@rpstw
Copy link

rpstw commented Feb 4, 2021

It seems that this project relies on a parent project which defines macro ANDROID, otherwise code below won't compile.

src/main/cpp/JavaThreadUtils.cpp
66:#ifdef ANDROID
88:#ifdef ANDROID

src/test/cpp/PersistedObject.cpp
34:#if ANDROID

CMakeLists.txt
4:if(ANDROID)
9:endif(ANDROID)

src/main/cpp/JniHelpersCommon.h
82:#if ANDROID
86:#define LOG_DEBUG(...) __android_log_print(ANDROID_LOG_INFO, LOGGING_TAG, __VA_ARGS__)
87:#define LOG_INFO(...) __android_log_print(ANDROID_LOG_INFO, LOGGING_TAG, __VA_ARGS__)
92:#define LOG_WARN(...) __android_log_print(ANDROID_LOG_WARN, LOGGING_TAG, __VA_ARGS__)
93:#define LOG_ERROR(...) __android_log_print(ANDROID_LOG_ERROR, LOGGING_TAG, __VA_ARGS__)

However, since ANDROID is not a standard macro, you probably want to use __ANDROID__ instead.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 90347d7..dfc22b1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,12 +1,12 @@
 cmake_minimum_required(VERSION 2.8)
 project(JniHelpers)
 
-if(ANDROID)
+if (CMAKE_SYSTEM_NAME STREQUAL Android)
   #set(CMAKE_C_CFLAGS "${CMAKE_C_FLAGS} -D__GXX_EXPERIMENTAL_CXX0X__")
   #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
 else()
   find_package(JNI REQUIRED)
-endif(ANDROID)
+endif()
 include_directories(${JNI_INCLUDE_DIRS})
 
 add_subdirectory(src/main/cpp)
diff --git a/src/main/cpp/JavaThreadUtils.cpp b/src/main/cpp/JavaThreadUtils.cpp
index 089aff5..03252c4 100644
--- a/src/main/cpp/JavaThreadUtils.cpp
+++ b/src/main/cpp/JavaThreadUtils.cpp
@@ -63,7 +63,7 @@ JNIEnv* JavaThreadUtils::attachCurrentThreadToJVM(const char* thread_name) {
   args.name = const_cast<char*>(thread_name);
   args.group = NULL;
 
-#ifdef ANDROID
+#ifdef __ANDROID__
   result = sJavaVm->AttachCurrentThread(&env, &args);
 #else
   result = sJavaVm->AttachCurrentThread((void**)(&env), &args);
@@ -85,7 +85,7 @@ JNIEnv* JavaThreadUtils::attachCurrentThreadAsDaemonToJVM(const char* thread_nam
   args.name = const_cast<char*>(thread_name);
   args.group = NULL;
 
-#ifdef ANDROID
+#ifdef __ANDROID__
   result = sJavaVm->AttachCurrentThreadAsDaemon(&env, &args);
 #else
   result = sJavaVm->AttachCurrentThreadAsDaemon((void**)(&env), &args);
diff --git a/src/test/cpp/PersistedObject.cpp b/src/test/cpp/PersistedObject.cpp
index d9bdf0a..4bb3c0d 100644
--- a/src/test/cpp/PersistedObject.cpp
+++ b/src/test/cpp/PersistedObject.cpp
@@ -31,8 +31,8 @@ void PersistedObject::initialize(JNIEnv *env) {
   setClass(env);
   cacheConstructor(env);
   cacheField(env, "i", kTypeInt);
-#if ANDROID
-  addNativeMethod("destroy", &PersistedObject::nativeDestroy, kTypeVoid, NULL);
+#if __ANDROID__
+  addNativeMethod("destroy", (void*)&PersistedObject::nativeDestroy, kTypeVoid, NULL);
 #else
   addNativeMethod("destroy", (void*)&PersistedObject::nativeDestroy, kTypeVoid, NULL);
 #endif

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants