Dear Felix community,
I'm experiencing trouble running OSGI bundles on Android using latest
Felix 4.6.0.
I have created and dexed a TestBundle.jar implementing a small
dictionary service for testing purposes.
When I run it on Windows/Eclipse against a matching client bundle the
service is working smoothly [1].
Run on Android from a Felix embedded in my client I'm only able to start
the bundle. When I try to access the service, i.e. cast it to its
interface, I encounter a ClassCastException
(java.lang.ClassCastException:
com.example.dictionary.DictionaryBundleImpl cannot be cast to
com.example.dictionary.service.DictionaryService) [4]. This cast however
should be possible as the class DictionaryBundleImpl implements the
exported DictionaryService interface. As the first lines of [4] indicate
this may be due to different class loaders involved.
How can I fix this?
Possibly related to this question I get a
java.lang.reflect.InvocationTargetException [3] when starting Felix with
the code provided in [2].
Thanks for your help!
Best regards
Sascha
[1]
____________________________
Welcome to Apache Felix Gogo
g! felix:install file:C:\\felixtmp\\felixcache\\TestBundle.jar
Bundle ID: 5
g! felix:install file:C:\\felixtmp\\felixcache\\DictionaryClientBundle.jar
Bundle ID: 6
g! felix:start 5
TestBundle finally started
g! felix:start 6
Enter a blank line to exit.
Enter word: maus
"maus" --> "mouse"
Enter word: katze
"katze" --> "cat"
Enter word: hund
"hund" --> "dog"
Enter word:
[2]
Map<String, String> configMap = new HashMap<String, String>();
configMap.put("org.osgi.framework.storage", cacheDir);
configMap.put("felix.embedded.execution", "true");
configMap.put("org.osgi.service.http.port", "9990");
configMap.put("org.osgi.framework.startlevel.beginning", "5");
try {
m_felix = new Felix(configMap); // Now create an instance of the
framework
LogEx("pre start attempt state: " + translateState(m_felix.getState()));
m_felix.start(); // Start Felix instance.
LogEx("pre start attempt state: " + translateState(m_felix.getState()));
} catch (Throwable ex) {
LogEx("could not create framework: " + ex.getMessage());
}
[3]
D/Felix(4355): pre start attempt state: INSTALLED
W/System.err(4355): Problem creating boot delegation class loader:
java.lang.reflect.InvocationTargetException
I/System.out(4355): TestBundle finally started
D/Felix(4355): post start attempt state: ACTIVE
[4]
D/Felix(4355): service is:
com.example.dictionary.DictionaryBundleImpl@ad26664
D/Felix(4355): service is of type: class
com.example.dictionary.DictionaryBundleImpl
D/Felix(4355): ClassLoader of service is: TestBundle [1]
D/Felix(4355): Default ClassLoader is :
dalvik.system.PathClassLoader[DexPathList[[zip file
"/data/app/com.example.hellofelix-1/base.apk"],nativeLibraryDirectories=[/vendor/lib,
/system/lib]]]
D/AndroidRuntime(4355): Shutting down VM
E/AndroidRuntime(4355): FATAL EXCEPTION: main
E/AndroidRuntime(4355): Process: com.example.hellofelix, PID: 4355
E/AndroidRuntime(4355): java.lang.RuntimeException: Unable to start
activity
ComponentInfo{com.example.hellofelix/com.example.hellofelix.MainActivity}:
java.lang.ClassCastException:
com.example.dictionary.DictionaryBundleImpl cannot be cast to
com.example.dictionary.service.DictionaryService
E/AndroidRuntime(4355): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
E/AndroidRuntime(4355): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
E/AndroidRuntime(4355): at
android.app.ActivityThread.access$800(ActivityThread.java:144)
E/AndroidRuntime(4355): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
E/AndroidRuntime(4355): at
android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(4355): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime(4355): at
android.app.ActivityThread.main(ActivityThread.java:5221)
E/AndroidRuntime(4355): at java.lang.reflect.Method.invoke(Native
Method)
E/AndroidRuntime(4355): at
java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime(4355): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
E/AndroidRuntime(4355): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
E/AndroidRuntime(4355): Caused by: java.lang.ClassCastException:
com.example.dictionary.DictionaryBundleImpl cannot be cast to
com.example.dictionary.service.DictionaryService
E/AndroidRuntime(4355): at
com.example.hellofelix.MainActivity.searchBundles(MainActivity.java:274)
E/AndroidRuntime(4355): at
com.example.hellofelix.MainActivity.onCreate(MainActivity.java:65)
E/AndroidRuntime(4355): at
android.app.Activity.performCreate(Activity.java:5933)
E/AndroidRuntime(4355): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
E/AndroidRuntime(4355): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
E/AndroidRuntime(4355): ... 10 more
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]