On Jun 11, 11:01 am, garbeam <[email protected]> wrote: > 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 atdefineClass() 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... > > 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?
As the story continued at stackoverflow, here is the solution: http://android.git.kernel.org/?p=platform/dalvik.git;a=blob;f=tests/071-dexfile/src/Main.java;hb=HEAD Thanks a lot for pointing this out! --Anselm -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

