Plugin system with DexClassLoader() and user interface
Asked Answered
A

2

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?

Aerometer answered 28/11, 2012 at 20:13 Comment(2)
rather than making the Activity dynamic, always use the same activity and use the DexClassLoader to load a fragment instead.Charlot
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.Kalie
L
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

Lowman answered 8/11, 2013 at 10:25 Comment(0)
N
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://mcmap.net/q/1474565/-it-is-possible-to-run-an-application-from-its-apk

Nitrogenous answered 7/11, 2017 at 14:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.