JNI_CreateJavaVM() is the method that returns the reference to JVM
which can then be used to attach a native thread to JVM. This method
is listed in "jni.h" but when I try to compile the library, it gives
me "undefined reference" error for JNI_CreateJavaVM(). I searched
through some older posts and found out that this API is part of
libdvm.so library. However, I can't find this library in either NDK or
SDK directories.
Can someone please let me know where can I find libdvm.so and how can
I add it to my JNI build?
Thanks
B
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
Thanks
B
On Mar 17, 3:23 pm, David Turner <di...@android.com> wrote:
> I'm sorry, but this function is not exposed by the NDK. Do not try to link
> to libdvm.so because this library
> might change names in future releases of the platform. There may be other
> ways to get a reference to the
> VM though that use the other JNI facilities.
>
> On Wed, Mar 17, 2010 at 2:56 PM, B Zen <biren...@gmail.com> wrote:
> > I am writing an application that creates a native thread using pthread
> > library. I need to then invoke a Java method from this native thread.
> > As per my understanding, the native thread needs to be attached to JVM
> > in order to invoke a Java method from native thread.
>
> > JNI_CreateJavaVM() is the method that returns the reference to JVM
> > which can then be used to attach a native thread to JVM. This method
> > is listed in "jni.h" but when I try to compile the library, it gives
> > me "undefined reference" error for JNI_CreateJavaVM(). I searched
> > through some older posts and found out that this API is part of
> > libdvm.so library. However, I can't find this library in either NDK or
> > SDK directories.
>
> > Can someone please let me know where can I find libdvm.so and how can
> > I add it to my JNI build?
>
> > Thanks
> > B
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-ndk" group.
> > To post to this group, send email to andro...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-ndk...@googlegroups.com<android-ndk%2Bunsu...@googlegroups.com>
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
Appreciate your help.
B
On Mar 17, 4:17 pm, David Turner <di...@android.com> wrote:
> Just call GetJavaVM() from inside a JNI function called from your Java code.
>
> > <android-ndk%2Bunsu...@googlegroups.com<android-ndk%252Buns...@googlegroups.com>
FindClass needs to know which class loader to use. Since there's no
Object associated with the call to FindClass, it loads classes using
the class loader associated with the Java method that called the
native method. Since your thread was attached to the VM from native
code, there is no caller. FindClass falls back on the "system" class
loader. This works out fine if you're interested in a core or
framework class, but it won't find classes associated with your
application.
The easiest way around this is to call a "find and cache the classes
I'm interested in" function from your application during
initialization. You can hold on to the results long-term if you use
NewGlobalRef to get a GC-friendly reference.
See also:
http://android.git.kernel.org/?p=platform/dalvik.git;a=blob_plain;f=docs/jni-tips.html;hb=HEAD