Now I am develop a shared jar lib for third plugin.
The lib will be used in two apk. For example, my main project is A and
the plugin project is B.
B have extends from the interface in lib. So A can load B apk and load
then extends class.
The following the my code:
The shared jar lib is:
public interface Plugin {
String getPluginInfo();
}
In B project:
package com.plugin
public class PluginTest implements Plugin {
public String getPluginInfo() {
return "PluginTest";
}
}
In A project :
Context packageContext = mContext.createPackageContext(packageName,
Context.CONTEXT_INCLUDE_CODE + Context.CONTEXT_IGNORE_SECURITY);
if(packageContext == null) continue;
// Load the class of the plugin
Class <?> pluginClass =
packageContext.getClassLoader().loadClass("com.plguin.PluginTest");
// Create class instance
(Plugin) defaultPluginEntry = (Plugin) (pluginClass.newInstance());
But the cast to Plugin throw a ClassCastException. I have search for
it, and find the exception is caused by the Plugin Interface have been
loaded by to different ClassLoader.
How can I fix it?
Thanks
--
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