How to use android::AndroidRuntime::getJavaVM() in ndk? -


i've built , run native executable using ndk. regular c++ application no java entry point (e.g., no xyz_activity, int main()). need access methods android runtime through jni, use android::androidruntime::getjavavm() javavm*, returns null. code build in aosp source tree. found androidruntime.cpp , added log code。through log found in other processes can androidruntime :: getjavavm () return correct value, in process androidruntime :: getjavavm () has returned null, , gcurruntime has been null。 leaves me jni_onload called shared libraries. tried splitting project executable , *. file containing jni_onload, guess works when doing explicit system.loadlibrary call. project doesn't contain java code @ all. how obtain reference jvm? searching long time on net. no use. please or try give ideas how achieve this. why in other processes can androidruntime :: getjavavm () return correct value, in process androidruntime :: getjavavm () has returned null?

void* initthread(void* data) {       javavm* jvm = android::androidruntime::getjavavm();     if(! jvm)     {         loge("getenv error");         return null;     }  } void injectinterface(char*arg) {  pthread_t thread_id; pthread_attr_t attr; check_per_logd("injectinterface start!"); pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, pthread_create_detached); pthread_create(&thread_id, &attr, initthread, null); // m_thread_id = thread_id; pthread_attr_destroy(&attr); check_per_logd("injectinterface end !"); return; 

}

int main(int argc) {  injectinterface(char*arg); 

}

android::androidruntime::getjavavm() returns null


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -