Hello,

I have created an application that dynamically loads plugin style
functionality using a DexClassLoader.  My application is organized as
follows:

- Interface.jar, which defines the interfaces of the plugin classes.
- Implementation.jar, which contains classes that implement the plugin
interfaces, and are compiled into a classes.dex file.
- MyApp.apk, which loads the plugin implementation at runtime using a
DexClassLoader and reflection.  This APK is compiled with
Interface.jar, so that the implementation objects that are created
with reflection can be casted to interface objects and used normally.

This all works great, until I want to extend my interface.  I would
like to be able to, say add functionality to an interface Foo by
creating interface Foo2 which extends Foo.  I could release a new
plugin that implements Foo2 to all of my clients, and those that are
new enough to know about Foo2 can use that interface while the older
ones just use Foo.  I believe this is a pretty common pattern for
plugins outside of Android.

But I am having a problem with how I compile the new interface classes
into my plugin.  If I compile Interface.jar into Implementation.jar,
when I use the DexClassLoader to load the implementation classes I get
the error "java.lang.IllegalAccessError: Class ref in pre-verified
class resolved to unexpected implementation".  This happens even if I
haven't extended the interface, so I initially just compiled
Implementation.jar without Interface.jar.  I believe this is the
Dalvik VM complaining that it now has to definitions for the same
class.  But, if I don't include the new Interface.jar, when an old
client tries to dynamically instantiate a class that implements Foo2,
I will get a ClassNotFoundException because there will be no
definition for Foo2.

Am I doing something wrong?  I feel like I can't be the only person
that is trying to design an extensible plugin framework like this on
Android, but I can't find any information on how to get this to work.
Thanks in advance for any help.

-- 
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

Reply via email to