8

For a long-term student project, i'm trying to develop a modular application with plugins. Specifically, we would have:

  • A master application where we could search, update, delete and run the plugins. This master application would also store some data from plugins.

  • Several plugins downloaded from a HTTP server with code and GUI components.

For now, i have a master application which is able to download a .apk file from HTTP and to create a new instance from a class defined in this .apk file. I use the way described here: http://android-developers.blogspot.fr/2011/07/custom-class-loading-in-dalvik.html with the DexClassLoader() method.

But i'm unable to see how to display a layout (or any other GUI component) stored as a resource in the plugin .apk file. For instance, i tried without success to create an Intent from the master application by using the plugin classname:

DexClassLoader cl = new DexClassLoader(...);
Class<?> libClass = cl.loadClass("plugin_classname");
Intent intent = new Intent(this.getApplicationContext(), libClass);
startActivity(intent);

And this doesn’t work because the Intent is not declared in the AndroidManifest.xml of the master application. This is also described in this other thread: Android- Using DexClassLoader to load apk file

Does that mean that there is absolutely no way to build a such "dynamic" user interface? More generally, can this type of plugin system be done on Android? Should i try an other method?

Community
  • 1
  • 1
  • 1
    rather than making the Activity dynamic, always use the same activity and use the DexClassLoader to load a fragment instead. – Nathan Schwermann Aug 21 '13 at 16:05
  • How did you build you `plugin.jar`. The jar that implements the interface? I have a jar built by eclipse with `classes.dex` entry but the `loadClass` always throws an exception. – TheRealChx101 Dec 05 '15 at 21:49

2 Answers2

0

I once tried the same thing and found it impossible. If the basic mechanism has not been changed since then (Jan. 2011), it is still impossible. Technical details are described in my blog in both Japanese and English.

Blog: Dynamically add an Activity that is not declared in AndroidManifest.xml (impossible)
http://darutk-oboegaki.blogspot.jp/2011/01/androidmanifestxml-activity.html

Takahiko Kawasaki
  • 18,118
  • 9
  • 62
  • 105
0

See this answer. It is about how to dynamically run Android's 'Activity', 'Service', which did not declared in AndroidManifest.xml, at runtime: https://stackoverflow.com/a/41112682/2801776

Cobain
  • 186
  • 1
  • 8