Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [concierge-dev] How to embed concierge in Android

Hi Danny,

There are a few things in Android that make it difficult to run OSGi. First of all, Android uses its own bytecode format (.dex), which makes it impossible to just load .jars with 'regular' java bytecodes in it. Second, Android applications have quite some things statically defined in their Android manifest, for example the activities, (Android) services, etc. This makes it difficult to for example start an OSGi runtime on Android and later start a bundle on it that adds another Activity, since this should be defined in the static xml of the app. Third, I have seen quite often that Android complains when the same class is loaded from multiple .dex files, which means you can run into trouble when running OSGi.

Now, to run Concierge (or in general OSGi) on Android, this is how I do it. This is by no means the only way to do it, nor the "best" way to do it, but just how I got it working and which was good enough for me when I needed it:
- Create an Android project (I have only used Eclipse IDE for this)
- Drop your OSGi framework .jar in the "libs" folder
  (I don't know if the latest concierge built from the source tree will work on Android, I have included a built from my machine that should work)
- Create an Android Activity or Service or whatever you want as starting point for the application
- Initialize and start your OSGi framework from code. The ServiceLoader won't work, so to initialize a Concierge framework do:
        FrameworkFactory frameworkFactory = (FrameworkFactory) Class.forName("org.eclipse.concierge.Factory").newInstance();
   You can create a new Framework instance with a configuration map, which you can start.
- Now you have a OSGi instance running in your Android app. To load OSGi bundles, you'd have to start them from code. Place your OSGi bundles in your assets/ dir for example, so you can load them from there. Note here that these .jar files should contain .dex bytecodes. You can create a classes.dex file using the "dx" command that ships with the Android SDK, and package this file inside the .jar.
If you want to access Android API's from within your OSGi bundles, mark these packages as framework exports.

If you use bnd and bndtools, I once wrote a plugin to make this stuff a bit easier. You basically provide a .bndrun file in your Android project, and the plugin will put the .jars in the right places and also provides an "OSGiActivity" that automatically starts an OSGi runtime together with the bundles provided in the bndrun. It also provides a bnd plugin that automatically packages a .dex file in your jars for the bundles you build in the workspace. It has been a while since I worked on it, but you can find the code as part from my AIOLOS project at https://github.com/aiolos-dev/androsgi An example Android project using that plugin is found https://github.com/aiolos-dev/example/tree/master/org.example.android I have no idea if it still works with the newest Android versions though.

Cheers,

Tim



On 05/27/2015 08:49 PM, Danny Fürniß wrote:
Hi Tim,

we are currently motivated into making an Android system to run the openHAB 2 (Home Automation Project) runtime initiated from Kai Kreuzer (openhab.org). We want to build a kind of a reference architecture for using Android based hardware for SmartHome use cases as supported by openHAB.
As openHAB is based on OSGI we are looking for an OSGI container capable of running on Android with the mobile context in mind - which concierge seems to be a good fit for.

So having you running concierge already in Android looks promising. Jochen Hiller also mentioned that he already made Eclipse SmartHome (base of openHAB2) to work within concierge. I am now trying to fit all these pieces together.

Can you help us with the step to get concierge run on Android? Do you have code or documentation to share? Maybe talking about the pitfalls or the necessary changes to the concierge code also helps.
Our intent is to have this project go open source but we are at the very beginning and constrained in terms of time. 

I would appreciate your help very much.

Cheers,
Danny




2015-05-24 11:14 GMT+02:00 Tim Verbelen <tim.verbelen@xxxxxxxxxxxxxx>:
Hi Danny,

I have some experience running OSGi (and Concierge in specific) on Android. I do not bake it into an Android custom rom though, but I integrate it into a regular Android app.

What exactly is your use case?

Best,

Tim


On 05/23/2015 08:34 PM, Danny Fürniß wrote:
Hi Jochen and Tim,

i am looking for a way to use concierge as a container for Eclipse SmartHome within an Android System.

As i heard it's possible i wanted to ask for any hints on how to accomplish that task.

I have an AOSP build up and running but have currently no clues where and how to start with that concierge sort of thing. I am all new into OSGI and relatively new to Android custom ROM baking.

If you have any suggestions where i can find some help, please let me know.

Cheers,
Danny




_______________________________________________
concierge-dev mailing list
concierge-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/concierge-dev


-- 
Tim Verbelen
Department of Information Technology
Broadband Communication Networks (IBCN)
Ghent University - iMinds
Gaston Crommenlaan 8 (Bus 201), B-9050 Gent, Belgium
T: +32 9 33 14940 ; T Secr: +32 9 33 14900
F: +32 9 33 14899
E: tim.verbelen@xxxxxxxxxxxxxx
W : www.ibcn.intec.UGent.be

_______________________________________________
concierge-dev mailing list
concierge-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/concierge-dev



_______________________________________________
concierge-dev mailing list
concierge-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/concierge-dev


-- 
Tim Verbelen
Department of Information Technology
Broadband Communication Networks (IBCN)
Ghent University - iMinds
Gaston Crommenlaan 8 (Bus 201), B-9050 Gent, Belgium
T: +32 9 33 14940 ; T Secr: +32 9 33 14900
F: +32 9 33 14899
E: tim.verbelen@xxxxxxxxxxxxxx
W : www.ibcn.intec.UGent.be

Attachment: org.eclipse.concierge-0.9.0.20150515141914.jar
Description: application/java-archive


Back to the top