Tuesday, May 10, 2011

[android-developers] Re: directly loading dynamically created classes (in dex format)

It turns out that VMClassloader defineClass() methods do nothing, but
throw the class format error. So how is one supposed to load class
bytes directly from a byte array? Hmmm.

On May 10, 10:50 pm, Tomasz <pulchritud...@gmail.com> wrote:
> Hi friends,
>
> I have an application which dynamically creates classes at runtime (in
> the dex format). Is it possible to load these dex bytes directly
> without saving them to a dex file, and then zipping it (many such
> classes are created). An equivalent of
> ClassLoader.defineClass(className, classDexBytes, 0,
> classDexBytes.length) is what I'd like. I.e. a DexClassLoader that
> doesn't have to reference a physical file, but can be passed byte
> arrays instead.
>
> If I try just extending ClassLoader is get a
> java.lang.UnsupportedOperationException: can't load this type of class
> file
> despite the byte[] definitely being in dex format (it starts with 'd'
> 'e' 'x' bytes). The trace for this is:
> W/System.err(  362): java.lang.UnsupportedOperationException: can't
> load this type of class file
> W/System.err(  362):    at java.lang.VMClassLoader.defineClass(Native
> Method)
> W/System.err(  362):    at
> java.lang.ClassLoader.defineClass(ClassLoader.java:338)
> W/System.err(  362):    at
> java.lang.ClassLoader.defineClass(ClassLoader.java:301)
>
> Thank you very much for your help,
> Tomasz

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate