Execute Java from native code

2,147 views
Skip to first unread message

Denis Gorodetskiy

unread,
Sep 3, 2009, 10:39:04 PM9/3/09
to android-ndk
Is there any way to display a AlertDialog ui message to user from
native code?

koba

unread,
Sep 3, 2009, 11:44:45 PM9/3/09
to android-ndk
You can call java methid via JNI.

Denis Gorodetskiy

unread,
Sep 6, 2009, 9:26:39 PM9/6/09
to android-ndk
could you please provide some example code
I have no experience with JNI

kobayashi tetsuyuki

unread,
Sep 6, 2009, 10:14:39 PM9/6/09
to andro...@googlegroups.com

Denis Gorodetskiy

unread,
Sep 7, 2009, 8:02:08 PM9/7/09
to android-ndk
But is it possible to execute Java code from native app if my app is a
stand-alone native app?

Dianne Hackborn

unread,
Sep 7, 2009, 8:21:14 PM9/7/09
to andro...@googlegroups.com
The NDK is not for building stand-alone native apps; it is for implementing native code as part of a .apk.  If you are creating a native app, you must be doing this as part of platform-level work, so you may get more help on android-porting.

At any rate, to execute Java code -inside- your app, you will need to compile the Dalvik interpreter into it, and initialize the interpreter before running the code.  Note also that doing this will cause you to miss out on some of the really important optimizations (in particular zygote) in the platform.


On Mon, Sep 7, 2009 at 5:02 PM, Denis Gorodetskiy <nou...@gmail.com> wrote:

But is it possible to execute Java code from native app if my app is a
stand-alone native app?





--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

David Turner

unread,
Sep 8, 2009, 9:22:59 AM9/8/09
to andro...@googlegroups.com
On Mon, Sep 7, 2009 at 5:02 PM, Denis Gorodetskiy <nou...@gmail.com> wrote:

But is it possible to execute Java code from native app if my app is a
stand-alone native app?

No, it is not supported.
 


Denis Gorodetskiy

unread,
Sep 9, 2009, 7:54:52 PM9/9/09
to android-ndk
even if I link libdvm.so into my code and use JNI_CreateJavaVM() and
stuff?

Doug Schaefer

unread,
Sep 9, 2009, 9:00:31 PM9/9/09
to andro...@googlegroups.com
There is no libdvm.so in the NDK. How did you link it in using the NDK?

As entertaining as it is to watch the Android team respond to these questions, could we please limit the discussion in this android-ndk group to the actual contents of, or at least plans for the NDK. Sorry to pick on this one, but there has been just way too many off topic conversations make their way through my overcrowded inbox.

David Turner

unread,
Sep 9, 2009, 9:17:53 PM9/9/09
to andro...@googlegroups.com
libdvm.so is not part of the stable native ABIs provided by the NDK.
We could rename it in the future to libAwesomeDvm.so, and your app would break badly.
Or we could split it (e.g. libdvm-int.so, libdvm-jit.so, whatever), same result.

Harsh

unread,
Sep 14, 2009, 11:29:22 AM9/14/09
to android-ndk
Sorry, because it would relate to android-platform group i guess, but
since this is active here.
Would the below scenario work?
1) Make a class Prog.java
2) A simple native-application calling JNI_CreateJavaVM and linking to
libdvm.so.
3) Loading Prog.class

I am somehow not able to load a class file even if I give some pre-
defined path. It shows below error.

java.lang.NoClassDefFoundError: Prog
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Prog in loader
dalvik.system.PathClassLoader@4001b448
at dalvik.system.PathClassLoader.findClass
(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
... 1 more

Please Note:
1) I pushed Prog.java to /data [by adb push]
2) I used "-Djava.class.path=/data" in the options to the
CreateJavaVm.


I would be glad if someone tells what i am doing wrong.
Thanks.

Harsh

unread,
Sep 14, 2009, 3:00:05 PM9/14/09
to android-ndk
Sorry for the double post.
I was able to do what i required.. :)
just silly mistake.



On Sep 10, 6:17 am, David Turner <di...@android.com> wrote:

keerthi rao

unread,
Sep 11, 2013, 8:21:45 AM9/11/13
to andro...@googlegroups.com, hars...@gmail.com
Hi Harsh

Can you please elaborate on how it got working for you?

Sarker Tanveer Ahmed Rumee

unread,
Jan 1, 2014, 7:54:29 PM1/1/14
to andro...@googlegroups.com, hars...@gmail.com
Hi, Could you please explain how you did it?

Bonly

unread,
Apr 29, 2014, 11:09:24 AM4/29/14
to andro...@googlegroups.com, hars...@gmail.com
I want to know too...

在 2014年1月2日星期四UTC+8上午8时54分29秒,Sarker Tanveer Ahmed Rumee写道:
Reply all
Reply to author
Forward
0 new messages