NDK如何获得DVM点? [英] NDK how to get the dvm point?
问题描述
现在我有一个问题用JNI_GetCreatedJavaVMs。
now I have a question to use "JNI_GetCreatedJavaVMs".
但我不能用JNI_OnLoad方法,因为我的家乡code未provid的Java。
but I couldn't use JNI_OnLoad method because my native code is not provid for java .
void *pHandle = dlopen("/system/lib/libart.so", RTLD_NOW | RTLD_GLOBAL);
JavaVM* m_pJvm = NULL;
void * pFunAddr =dlsym(pHandle, "JNI_GetCreatedJavaVMs");
LOGD("pJNI_GetCreatedJavaVMs = %08X", pFunAddr);
pJNIGetCreatedJavaVMs = (int)pFunAddr - 1;
LOGD("call !!!!!!!");
pJNIGetCreatedJavaVMs(&m_pJvm, 0, &vm_count);
LOGD("pJNIGetCreatedJavaVMs result is %d", result);
当我打电话JNI_GetCreatedJavaVMs,进程崩溃。
when I call the JNI_GetCreatedJavaVMs, process was crashed.
我没有发现IDA发生了什么。
I didn't found what happend in IDA.
谁可以帮我!!!!!!!!!!!!!! THX
who can help me !!!!!!!!!!!!!! THX
PS:JNI_GetCreatedJavaVMs方法是在Android源$ C $ C发现
ps:JNI_GetCreatedJavaVMs method is found in the android source code.
和另一种方法是使用运行时(libart.so)或gdvm(libdvm.so)。
and another method is use runtime(libart.so) or gdvm(libdvm.so).
推荐答案
从我的本机应用程序的一些code,它是建立在AOSP源代码树。
Some code from my native app, it is build in the AOSP source tree.
我不知道它是否能在工作NDK
I am not sure if it could work in NDK
#include <jni.h>
#include <android_runtime/AndroidRuntime.h>
...
JNIEnv *env;
jint res;
JavaVM *jvm = AndroidRuntime::getJavaVM();
assert(jvm != NULL);
res = jvm->AttachCurrentThread(&env, NULL);
assert(res >= 0);
这篇关于NDK如何获得DVM点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!