Google Android SDK allows developers to write Java code in order to create Android applications. Instead of a regular Java Virtual Machine that executes this code, a special-purpose virtual machine named Dalvik is being used in order to comply with mobile platform requirements. Dalvik does not use Java bytecode format, but, a tool named dx, included in the Android SDK, transforms the Java class files of Java classes compiled by a regular Java compiler into another class file format (the .dex format) (the conversion is not done at runtime).
Although Felix, since version 1.0.3, has built in support for Android, there are still some things needed to be done in order to successfully make use of it ( you will need to install Android SDK and you should have <android_SDK_HOME>/tools added to system PATH variable). The zip file available for download has been created in the same manner.
Step 1: Each JAR file you use, either as a Felix library or as a bundle, should contain its DEX equivalent. This means that you must first create a DEX file for your JAR:
Then you must add the DEX file to your JAR file:
Step 2: The processed JARs should be made available to Android by transferring them to the emulator:
Step 3: Referring to the sample project for a concrete example, these steps are preformed:
Prepare the Felix JAR:
Prepare the bundle JARS:
Transfer all of them to the emulator (note that you need some kind of unix-like shell, such as the Mac OS X terminal or Linux):
Once you've done that, you should be able to launch Felix and the bundles on Android: start emulator shell, change directory to the location of your Felix files and execute felix.sh.
felix.sh contains a Unix shell command that launches Felix main class using the actual runtime of the emulator.
If all went well, you should see the Felix command line shell now. Type "help" for further instructions.
You may now install and launch EnglishDictionary, FrenchDictionary, and SpellChecker bundles to test how Felix is working. These are all examples from the Apache Felix OSGi tutorial and correspond to Apache Felix Tutorial Example 2, Apache Felix Tutorial Example 2b, and Apache Felix Tutorial Example 5 respectively.
- EnglishDictionary - supplies a Dictionary service implementation with the following collection of words "welcome", "to", "the", "osgi", "tutorial"
- FrenchDictionary - supplies a Dictionary service implementation with the following collection of words "bienvenue", "au", "tutoriel", "osgi"
- SpellChecker - supplies a spell checker that retrieves the first Dictionary implementation it finds and checks if the word you've entered is in the dictionary or not.
Apache Felix can also be integrated with an Android application. To achieve this, you need to embed Felix into onCreate() method of your Activity class (see Android docs for more details on how to use an Activity) and process your bundles as shown above.
The project zip file osgi-android.zip