我有一個AndroidStudio和Gradle開發的Android項目,嵌入並啓動一個基於felix的小OSGi項目。調試我使用Android 8.0,API 26的Nexus 5X仿真器。我使用聲明式服務,因此我的項目基於felix.main,felix.scr和felix.configadmin。所有的包都是脫毒的。安裝軟件包工作正常,但如果我通過bundle.start()啓動軟件包,我得到felix.scr和felix.configadmin(felix.main和我自己的軟件包工作正常 - >狀態處於活動狀態)的以下錯誤消息:在Android中導致OSGi Felix導致UnsupportedOperationException異常:無法加載此類文件
08-03 13:58:00.880 19745-19745/android.cit.tu_berlin.de.helloandroid W/zygote: Skipping duplicate class check due to unrecognized classloader
08-03 13:58:00.881 19745-19745/android.cit.tu_berlin.de.helloandroid E/OSGIService: catch exception while starting bundle:
08-03 13:58:00.881 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: org.osgi.framework.BundleException: Activator start error in bundle org.apache.felix.configadmin [2].
08-03 13:58:00.881 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at org.apache.felix.framework.Felix.activateBundle(Felix.java:2276)
08-03 13:58:00.881 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at org.apache.felix.framework.Felix.startBundle(Felix.java:2144)
08-03 13:58:00.881 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)
08-03 13:58:00.881 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:984)
08-03 13:58:00.881 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at android.cit.tu_berlin.de.helloandroid.OSGIService.startBundle(OSGIService.java:386)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at android.cit.tu_berlin.de.helloandroid.OSGIService.runSensorVisualisationPlugin(OSGIService.java:248)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at android.cit.tu_berlin.de.helloandroid.OSGIService.onStartCommand(OSGIService.java:158)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3539)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at android.app.ActivityThread.-wrap20(Unknown Source:0)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1698)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at android.os.Handler.dispatchMessage(Handler.java:105)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at android.os.Looper.loop(Looper.java:164)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6540)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at java.lang.reflect.Method.invoke(Native Method)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at java.lang.ClassLoader.defineClass(ClassLoader.java:591)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.defineClass(BundleWiringImpl.java:2370)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2154)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1542)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1415)
08-03 13:58:00.882 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4468)
08-03 13:58:00.883 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: at org.apache.felix.framework.Felix.activateBundle(Felix.java:2221)
08-03 13:58:00.883 19745-19745/android.cit.tu_berlin.de.helloandroid W/System.err: ... 15 more
的gradle這個腳本有解決依賴於菲利克斯罐子下面的語句:
provided fileTree(dir: 'src/main/assets/bundles/', include: ['*.jar'])
// for finding Felix.class
compile group: 'org.apache.felix', name: 'org.apache.felix.framework', version: '5.4.0'
,我需要設置以下屬性菲利克斯解決失蹤要求osgi.ee(基於Christian Schneider在那post)回答:
configMap.put(Constants.FRAMEWORK_SYSTEMCAPABILITIES, "osgi.ee; osgi.ee=\"JavaSE\";version:List=\"1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8\"");
如果因爲我不認爲錯誤與該post特別是部分「參考圖書館進入該項目構建路徑」(基於亞歷克B.普拉姆在post答案)我想知道知道爲什麼第一行「我的」錯誤報告中提到
W/zygote: Skipping duplicate class check due to unrecognized classloader
爲什麼重複類?每個lib都在那裏一次,除了gradle以外,沒有其他項目設置或依賴關係鏈接。
我找到了一個類似的post,它通過以下Apache Felix教程步驟解決。很好,但我也是這樣做的,而且還出現了錯誤。
我已經嘗試了很多最後的日子,我讀了很多最後的日子,但我發現我的問題不符合我的問題,我猜。請幫忙!並提前感謝!
更新17年8月8日:
我試圖根據巴拉茲Zsoldos的答案,找到原來的異常,這就是結果: 異常被拋出BundleWiringImpl.class在getClassByDelegation(字符串名稱):
public Class getClassByDelegation(String name) throws ClassNotFoundException {
if(name != null && name.length() > 0 && name.charAt(0) == 91) {
return Class.forName(name, false, this.getClassLoader());
} else if(this.isFiltered(name)) {
throw new ClassNotFoundException(name);
} else {
ClassLoader cl = this.getClassLoaderInternal();
if(cl == null) {
throw new ClassNotFoundException("Unable to load class \'" + name + "\' because the bundle wiring for " + this.m_revision.getSymbolicName() + " is no longer valid.");
} else {
return cl.loadClass(name);
}
}
}
最後一行(cl.loadClass(name))拋出異常。爲了完整起見,這裏的值:
cl = org.apache.felix.configadmin
name = org.apache.felix.cm.impl.ConfigurationManager
可惜我不能調試到那個方法,所以我停在那裏,並設置AndroidStudio捕獲所有異常。下一站是由DexFile.class拋出的異常造成的
cause = java.lang.ClassNotFoundException: java.lang.Object
detailedMessage = Failed resolution of: Ljava/lang/Object
這到底是什麼?爲什麼在DexFile.class中,爲什麼它不可能解析對象類?我查看了捆綁包中的dex文件和它們的入口名(可能是絕對路徑問題,Balazs Zsoldos提到過)。好吧!沒有隱藏的添加。任何人都可以幫助或做任何人有類似的問題和任何想法如何解決?
更新10.08。17
我想知道的是爲什麼只有felix包會拋出異常。費利克斯主束和我自己的工作很好,他們處於活躍狀態。爲什麼有可能我自己的基於聲明性服務的bundle是活動的,即使felix-scr包沒有啓動(狀態已解決)。看來felix-scr並沒有處於激活狀態,不能解決對felix-scr的依賴問題。 無論如何,爲什麼dexified felix庫失敗了,還有我自己的工作?請幫助,我絕望!
更新2017年11月8日
今天我嘗試了物理Android設備上我的項目運行和調試(索尼XPERIA Z2採用Android 4.4.4,API 19)和它的作品。所有包都處於活動狀態。最後幾天我使用Nexus 5X的模擬器與Android 8.0 API 26,所以我編輯了我的帖子以添加該信息。它似乎嚴重依賴於設備和/或Android版本和API。瘋!
非常感謝您的回覆。我將在明天嘗試,希望找到原因。然而,真的很好,知道我可以從哪裏開始發現錯誤!這有很大幫助! – Computerwurm