Question

I follow this tutorial to embed OSGi into my Android application. However, after installing and starting a bundle, its state became RESOLVED (4), not ACTIVE (32) as it must be. When I try to start once again, it throws an exception:

Bundle#1 start failed
java.lang.ClassNotFoundException: org.knopflerfish.tutorial.simplebundle.impl.Activator
org.knopflerfish.framework.BundleImpl.start0(BundleImpl.java:421)
org.knopflerfish.framework.BundleThread.run(BundleThread.java:145)

This bundle is sample bundle from Knopflerfish examples source. It works well when installed in Knopflerfish destop (framework.jar)

I already thought of dex, but it is no use to merge the jar file and its dex file, it still doen't work.

What is problem here? Thank you very much!

Was it helpful?

Solution

After several day I have found the solution for this problem. I post it here for anyone who may concern.

First of all, this problem is related to dex file. The dex file can not be found make the BundleClassLoader can not find the Activator class. In jar file after executing dx and aapt commands, the *.dex must be situated in the top path. You can check this by extracting the jar file and see.

bundler.jar
----META-INF
----org
----classes.dex

Another point you need to consider if your app still doesn't work. In Android newer version, the dex file can not be located in external storage (as explained here http://developer.android.com/reference/dalvik/system/DexClassLoader.html), so you need to modify the code that set org.osgi.framework.storage property.

Instead of:

Map<String, String> fwprops = new Hashtable<String, String>();
fwprops.put("org.osgi.framework.storage", Environment.getExternalStorageDirectory().getAbsolutePath() + "/fwdir");

I use this:

Map<String, String> fwprops = new Hashtable<String, String>();
File dexOutputDir = getDir("dex", 0);
fwprops.put("org.osgi.framework.storage", dexOutputDir.getAbsolutePath());

Hope this help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top