diff --git a/jni/src/jni_logger.cpp b/jni/src/jni_logger.cpp index d7f8fc60..19264551 100644 --- a/jni/src/jni_logger.cpp +++ b/jni/src/jni_logger.cpp @@ -16,6 +16,18 @@ using odr_jni::make_handle; using odr_jni::to_jstring; using odr_jni::to_string; +/// `JavaVM::AttachCurrentThread` takes a `JNIEnv **` on android and a `void **` +/// on the jdk, and neither pointer converts to the other, so the argument has +/// to be typed per platform. `GetEnv` is `void **` on both and needs none of +/// this. +jint attach_current_thread(JavaVM *const vm, JNIEnv **const env) { +#ifdef __ANDROID__ + return vm->AttachCurrentThread(env, nullptr); +#else + return vm->AttachCurrentThread(reinterpret_cast(env), nullptr); +#endif +} + /// A `JNIEnv` for the calling thread, attaching it if the JVM does not know it /// yet. Log calls arrive on whatever thread the library happens to be working /// on, which is not necessarily one the JVM started. @@ -28,8 +40,7 @@ class ScopedEnv { const jint status = m_vm->GetEnv(reinterpret_cast(&m_env), JNI_VERSION_1_6); if (status == JNI_EDETACHED) { - if (m_vm->AttachCurrentThread(reinterpret_cast(&m_env), - nullptr) == JNI_OK) { + if (attach_current_thread(m_vm, &m_env) == JNI_OK) { m_attached = true; } else { m_env = nullptr;