Hi there,

I'm wondering if and how one can load dex or class files dynamically
in dalvik, some quick'n'dirty test function I wrote was this:

        public void testLoader() {
                InputStream in;
                int len;
                byte[] data = new byte[2048];

                try {
                        in = context.getAssets().open("f.dex");
                        len = in.read(data);
                        in.close();
                        DexFile d;
                        Class c = defineClass("net.webvm.FooImpl", data, 0, 
len);
                        Foo foo = (Foo)c.newInstance();
                } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                } catch (IllegalAccessException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (InstantiationException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }


whereas the Foo interface is this

        public interface Foo {
                int get42();
        }

and f.dex contains some dx'ed implementation of that interface:

        public class FooImpl implements Foo {
                public int get42() {
                        return 42;
                }
        }

I also tried the same test driver code with a plain .class file which
I didn't expect to work in a dalvik context for the obvious reasons,
and it doesn't either.

Anyways, the above test driver throws at defineClass() and it doesn't
work and I investigated the dalvik code and found this:

  
http://www.google.com/codesearch/p?hl=en#atE6BTe41-M/vm/Jni.c&q=Jni.c&sa=N&cd=1&ct=rc&l=1682

So I'm wondering if anyone can enlighten me if this is possible in
some other way or not supposed to be possible. If it is not possible,
can anyone provide reasons why this is not possible?

Kind regards,
Anselm

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to