问题描述
我正在开发一个对Android的全面支持OSGi包。到目前为止,我的previous的问题,我能够使用Android API的OSGi包里面。它工作正常,我试了一下。我使用的菲利克斯框架。
不过,我现在在做一个OSGi包有一个机器人的活动,并启动该活动的任务卡住。我还需要这些活动能够为要求的权限,所以我想我需要一个的AndroidManifest.xml
在OSGi包。
虽然做研究,我能找到只有一个人描述了实现这一他的经验。不幸的是,他提到的步骤是不明确的给我。
在他的问题完整的Android支持OSGI,这里是他说:
我已经找到一种方法来启动搭载Android包拥有的活动:
•Android的包必须是可以使用Eclipse的Android项目来创建一个APK
•您OSGi框架添加一个参考图书馆进入该项目构建路径(在我的情况framework.jar)
•编辑bundle.manifest描述的包。该文件不是APK的一部分,但是将在构建使用
•捆绑的code,尤其是Activator类,必须在同一个包定义在AndroidManifest.xml中和包的符号名称必须与包名称。如果这些条件得到满足,则所有的类都被正确加载。如果不是,它会导致看到java.lang.NoClassDefFoundError的在运行时
•使用Android的工具>出口未签名的Android包
•复制bundle.manifest在无符号的APK为META-INF / MANIFEST.MF
•签署APK使用任何证书,你要
•安装签署APK像任何标准的Android应用程序。需要安装才能有解决的活动。如果没有这种活动不会解决和包将失败
•有OSGi框架加载包APK
在哪里,他说:
•编辑bundle.manifest描述的包。该文件不是APK的一部分,但是将在构建使用
我所做的是创建一个Android项目(APK),并按照前两步。但在这上面第三步,我找不到bundle.manifest
来编辑它。这是根本不存在,所以怎么来的,他说,编辑它?
此外,当我导出未签名的Android Package的
,从哪里到哪里我应该复制清单文件?
最后,是最后签署APK文件我束应该由框架加载?这似乎很奇怪,因为它甚至不是一个jar文件。
如果这些步骤也帮不了我,有人可以使我在正确的方向?谢谢你。
更新:
没有人回答我的问题,所以我做了以下内容:
1。在我的Android应用程序项目(而我试图让它作为一个包),我包括在AndroidManifest.xml中提到的相同的包我的Activator类。 这是我的 Activator.java
类:
包com.example.patient;
进口org.osgi.framework.BundleActivator;
进口org.osgi.framework.BundleContext;
公共类激活实现BundleActivator的{
私有静态的BundleContext上下文;
静态的BundleContext的getContext(){
返回范围内;
}
公共无效启动(BundleContext的的BundleContext)抛出异常{
Activator.context =的BundleContext;
//我想在这里开始活动显示土司消息
的System.out.println(安卓APK包已启动);
}
公共无效停止(的BundleContext的BundleContext)抛出异常{
Activator.context = NULL;
}
}
这是我的的AndroidManifest.xml
< XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.patient
安卓版code =1
机器人:VERSIONNAME =1.0>
<用途-SDK
安卓的minSdkVersion =8
机器人:targetSdkVersion =17/>
<使用-权限的Android:名称=android.permission.INTERNET对/>
<应用
机器人:allowBackup =真
机器人:图标=@可绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme>
<活动
机器人:名称=com.example.patient.View_Patient_File_Activity
机器人:标签=查看病人档案>
< /活性GT;
<活动
机器人:名称=com.example.patient.Enter_Patient_ID_Activity
机器人:标签=查看病人档案>
<意向滤光器>
<作用机器人:名称=android.intent.action.MAIN/>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
< /用途>
< /舱单>
2 - 我加了一个参考图书馆进入该项目构建路径为我的OSGi框架(felix.jar)
3我产生采用Android工具我的项目的一个无符号的副本。
4-我添加了一个文件夹的无符号的副本名为 META-INF
的根目录,这个文件夹里,我增加了一个名为 MANIFEST.MF ,下面是该文件的内容:
清单-版本:1.0
束ManifestVersion:2
束名称:患者
捆绑-SymbolicName:com.example.patient
束版本:1.0.0.qualifier
束激活:com.example.patient.Activator
进口包装:org.osgi.framework;版本=1.3.0
束RequiredExecutionEnvironment:OSGi的/最小-1.0
5我手签使用命令行和jar签名工具签名的副本。是这样的:
的jarsigner -verbose -keystore /path_to_keystore/mykeystore.keystore my_application.apk my_keystore_alias
6我安装在我的电脑和我的选项卡上的亲笔签名。
7。最后,我跑我的应用程序,并让OSGi框架加载相同签名的apk文件。
NO USE ,虽然包的状态是积极的,但我没有看到激活start()方法的消息,这意味着,我的包没有正确加载。哪里我以后不再出问题?请大家帮帮忙。
更新25-11-2013
我确信做正确的步骤,现在我得到这样的:
11-25 17:54:08.600:W / System.err的(2714):org.osgi.framework.BundleException:未发现:com.example.patient.Activator
11-25 19:22:36.590:W / System.err的(6652):抛出java.lang.ClassNotFoundException:产生的原因com.example.patient.Activator不是com.example.patient发现
意思是说我的包不包含Activator类,但我相信它。什么地方出错了?
更新26-11-2013
我使用WinZip打开签署APK。我注意到,不像束我用来建立,签名的APK不包含.class文件包括Activator.class,所以我复制一个包含项目的所有.class文件的com目录,而我粘贴它在签署APK。接下来,我签署了APK了。现在,当我安装APK,我得到了以下日志,其中包含了许多错误:
11-25 23:16:25.651:D / dalvikvm(5617):DexOpt:--- BEGINbundle.jar(引导= 0)---
11-25 23:16:26.271:D / dalvikvm(5617):DexOpt:--- ENDbundle.jar(成功)---
11-25 23:16:26.271:D / dalvikvm(5617):DEX preP'/sdcard/felix-cache-1472376252.tmp/bundle1/version0.0/bundle.jar:解压缩到102ms,改写620ms
11-25 23:16:26.271:W / dalvikvm(5617):一类以意想不到的DEX解决:LCOM /例子/人/活化剂;(0x4074fa08):0x18a7b8文献[Lorg / OSGI /框架/ BundleActivator的] Lorg / OSGI /框架/ BundleActivator的;(0x40714410):0xbd630
11-25 23:16:26.271:W / dalvikvm(5617):(LCOM /例子/人/活化剂,已经使用了不同的Lorg / OSGI /框架/ BundleActivator的;在pre-验证)
11-25 23:16:26.271:I / dalvikvm(5617):无法解析LCOM /例子/人/激活;接口902'Lorg / OSGI /框架/ BundleActivator的;
11-25 23:16:26.271:W / dalvikvm(5617):Link类的LCOM /例子/人/激活;失败
11-25 23:16:26.271:E / dalvikvm(5617):ERROR:的defineClass(0x4074fa08,com.example.patient.Activator,0x4079d468,0,955,0x4073e918)
11-25 23:16:26.271:E /扎伊德日志(5617):问题在安装包:■
11-25 23:16:26.271:W / System.err的(5617):org.osgi.framework.BundleException:激活在束com.example.patient开始误差[1]。
11-25 23:16:26.271:W / System.err的(5617):在org.apache.felix.framework.Felix.activateBundle(Felix.java:2196)
11-25 23:16:26.271:W / System.err的(5617):在org.apache.felix.framework.Felix.startBundle(Felix.java:2064)
11-25 23:16:26.271:W / System.err的(5617):在org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)
11-25 23:16:26.271:W / System.err的(5617):在org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)
11-25 23:16:26.271:W / System.err的(5617):在com.example.patient_application.MainActivity.onCreate(MainActivity.java:136)
11-25 23:16:26.271:W / System.err的(5617):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
11-25 23:16:26.271:W / System.err的(5617):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715)
11-25 23:16:26.271:W / System.err的(5617):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1767)
11-25 23:16:26.271:W / System.err的(5617):在android.app.ActivityThread.access $ 1500(ActivityThread.java:122)
11-25 23:16:26.271:W / System.err的(5617):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1005)
11-25 23:16:26.271:W / System.err的(5617):在android.os.Handler.dispatchMessage(Handler.java:99)
11-25 23:16:26.271:W / System.err的(5617):在android.os.Looper.loop(Looper.java:132)
11-25 23:16:26.271:W / System.err的(5617):在android.app.ActivityThread.main(ActivityThread.java:4028)
11-25 23:16:26.271:W / System.err的(5617):在java.lang.reflect.Method.invokeNative(本机方法)
11-25 23:16:26.271:W / System.err的(5617):在java.lang.reflect.Method.invoke(Method.java:491)
11-25 23:16:26.271:W / System.err的(5617):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:844)
11-25 23:16:26.271:W / System.err的(5617):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
11-25 23:16:26.271:W / System.err的(5617):在dalvik.system.NativeStart.main(本机方法)
11-25 23:16:26.271:W / System.err的(5617):java.lang.UnsupportedOperationException:产生的原因无法加载此类型的类文件
11-25 23:16:26.271:W / System.err的(5617):在java.lang.VMClassLoader.defineClass(本机方法)
11-25 23:16:26.271:W / System.err的(5617):在需要java.lang.ClassLoader.defineClass(ClassLoader.java:319)
11-25 23:16:26.271:W / System.err的(5617):在org.apache.felix.framework.BundleWiringImpl $ BundleClassLoader.findClass(BundleWiringImpl.java:2279)
11-25 23:16:26.271:W / System.err的(5617):在org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1501)
11-25 23:16:26.271:W / System.err的(5617):在org.apache.felix.framework.BundleWiringImpl.access $ 400(BundleWiringImpl.java:75)
11-25 23:16:26.271:W / System.err的(5617):在org.apache.felix.framework.BundleWiringImpl $ BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
11-25 23:16:26.271:W / System.err的(5617):在java.lang.ClassLoader.loadClass(ClassLoader.java:500)
11-25 23:16:26.271:W / System.err的(5617):在org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1374)
11-25 23:16:26.271:W / System.err的(5617):在org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4329)
11-25 23:16:26.271:W / System.err的(5617):在org.apache.felix.framework.Felix.activateBundle(Felix.java:2141)
11-25 23:16:26.271:W / System.err的(5617):17 ...更多
有两个问题,并解决这些问题,我设法最终得到安装在我的APK包,并开始菲利克斯。
1与OSGi bundle了,最终签署了APK不包含的.class
文件。这就是为什么我得到:未发现:com.example.patient.Activator
。通过从我的Android项目手动复制的 COM
目录已签署的APK,然后再在上面签名,我设法解决这个问题。
2 - 通过的 @ slash33 的提到的第二个步骤是:
•您OSGi框架添加一个参考图书馆进入该项目构建路径
是造成我以下错误:
(LCOM /例子/人/活化剂,已经使用了不同的Lorg / OSGI /框架/ BundleActivator的;在pre-验证)
随着this文章中,我只是删除了对库引用,并删除 felix.jar
从我的构建路径。然后,我这样做:建立Path->配置构建Path->项目,然后我说我的申请项目,将加载包,并且已经有 felix.jar
的它的构建路径。这个据我了解将使应用程序和APK包使用相同的 felix.jar
。 (而不是保持不同的一个两个,这让Dalvik的抱怨)。
所以,我认为,正确的步骤来创建的Android APK包,然后将其加载到该框架是:
- 通过创建Eclipse中的Android项目创建普通APK,例如。
- 请你捆绑使用应用程序使用了相同的OSGI框架库:构建Path->配置构建Path->项目,然后添加应用程序项目,将加载包。您的应用程序的项目应包含在其构建路径OSGi框架jar文件,(在我的情况
felix.jar
)。 - 创建包清单文件中描述的包。你可以把它叫做
bundle.manifest
。 - 在说你的应用程序包是
com.acme.helloworld
(此值设置清单:在AndroidManifest.xml中包),你的OSGi bundle的Activator类的必须被放置在包com.acme.helloworld
键,您必须设置捆绑-SymbolicName:COM。 acme.helloworld
在bundle清单。如果这些条件不具备,则将会导致java.lang.NoClassDefFoundError的
上运行。 - 使用的安卓工具>导出未签名的Android Package的的
- 复制
bundle.manifest
来生成的签名APK作为根目录META-INF / MANIFEST.MF
。您可以使用WinZip打开未签名的APK并添加文件夹META-INF
。 - 使用命令签署APK:
的jarsigner -verbose -keystore /path_to_keystore/mykeystore.keystore my_application.apk my_keystore_alias
。 - 复制你的目录,其中包含从您的Android项目已签名的apk的根目录下的
的.class
文件。在我的情况:它是COM
目录 。 - 再次登录你的APK。
- 安装的APK包。
- 有OSGi框架加载和启动APK包(非常相同的APK文件)
I am working on developing OSGI bundles that have a full support for android. So far, by my previous questions, I was able to use android API inside OSGI bundle. It works fine and I tried it. I am using Felix framework.
However, I am stuck now at the mission of making an OSGI bundle to have an android activity and to start that activity. I also need these activities to be able to request permissions so I guess I will need an AndroidManifest.xml
in the OSGI bundle.
While doing a research, I was able to find only one person describing his experience in achieving this. Unfortunately, the steps he mentioned is ambiguous to me.
In his question "Full Android Support for OSGI" , Here's what he said:
I have found a way to start activities owned by android bundles:
•the android bundle MUST be an APK which can be created using Eclipse Android Project
•add a Reference Library entry to the project Build Path for your OSGi framework (in my case framework.jar)
•edit bundle.manifest describing the bundle. The file is not part of the APK but will be used on build
•the bundle's code, especially the Activator class, MUST be in the same package as defined in AndroidManifest.xml AND the symbolic name of the bundle MUST be the package name as well. If these conditions are met then all of the classes will be correctly loaded. If not, it will result in seeing java.lang.NoClassDefFoundError on runtime
•Use Android Tools > Export Unsigned Android Package
•copy bundle.manifest in the unsigned APK as META-INF/MANIFEST.MF
•sign the APK using whatever certificate you want
•install the signed APK like any standard android application. Installation is required in order to have the Activity resolved. Without this the activity won't resolve and the bundle will fail
•have the OSGi framework load the bundle APK
Where he says:
•edit bundle.manifest describing the bundle. The file is not part of the APK but will be used on build
All I did is to create an android project (APK) and to follow the first two steps. But at this third step above, I couldn't find "bundle.manifest"
to edit it. It is not there at all, so how come he says edit it?
Also, when I Export Unsigned Android Package
, from where to where should I copy the manifest file?
Finally, is the final signed APK file my bundle that should be loaded by the framework? This seems odd because It is not even a jar file.
If these steps would not help me, then can someone lead me in the right direction? Thank you.
UPDATE:
No one answers my question, so I did the following:
1- In my android application project (which I am trying to make it act as a bundle), I included my Activator class in the same package mentioned in the AndroidManifest.xml. Here's my Activator.java
class:
package com.example.patient;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
private static BundleContext context;
static BundleContext getContext() {
return context;
}
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
//I WOULD LIKE TO START THE ACTIVITY HERE TO DISPLAY THE TOAST MESSAGE
System.out.println("Android APK Bundle Started");
}
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
}
}
and here's my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.patient"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.patient.View_Patient_File_Activity"
android:label="View Patient File" >
</activity>
<activity
android:name="com.example.patient.Enter_Patient_ID_Activity"
android:label="View Patient File" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
2- I added a Reference Library entry to the project Build Path for my OSGi framework (felix.jar)
3- I generated an unsigned copy of my project using Android Tools.
4- I added a folder to the root directory of the unsigned copy called META-INF
, and inside that folder, I added a file called MANIFEST.MF
, below is the content of that file:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Patient
Bundle-SymbolicName: com.example.patient
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.example.patient.Activator
Import-Package: org.osgi.framework;version="1.3.0"
Bundle-RequiredExecutionEnvironment: OSGi/Minimum-1.0
5- I manually signed the unsigned copy using command line and jar signer tool. Something like:
jarsigner -verbose -keystore /path_to_keystore/mykeystore.keystore my_application.apk my_keystore_alias
6- I installed the signed copy on my PC and on my tab.
7- Finally, I run my application, and let the OSGI framework load the same signed apk file.
NO USE, although the bundle status is active, but I do NOT see the message in the activator start() method, meaning that, my bundle is not loaded correctly. Where did I go worng?Please help.
UPDATE 25-11-2013
I made sure to do the steps correctly, and now I got this:
11-25 17:54:08.600: W/System.err(2714): org.osgi.framework.BundleException: Not found: com.example.patient.Activator
11-25 19:22:36.590: W/System.err(6652): Caused by: java.lang.ClassNotFoundException: com.example.patient.Activator not found by com.example.patient
Meaning that my bundle does not contain the Activator class, but I am sure it does. What could be wrong?
UPDATE 26-11-2013
I opened the signed APK using WinZip. I noticed that unlike the bundles I used to build, the signed APK does not contain the .class files including the "Activator.class", so I copied the com directory that contains all the .class files of the project, and I pasted it in the signed APK. Next, I signed that APK again. Now, when I install the APK, I get the following log which contains many errors:
11-25 23:16:25.651: D/dalvikvm(5617): DexOpt: --- BEGIN 'bundle.jar' (bootstrap=0) ---
11-25 23:16:26.271: D/dalvikvm(5617): DexOpt: --- END 'bundle.jar' (success) ---
11-25 23:16:26.271: D/dalvikvm(5617): DEX prep '/sdcard/felix-cache-1472376252.tmp/bundle1/version0.0/bundle.jar': unzip in 102ms, rewrite 620ms
11-25 23:16:26.271: W/dalvikvm(5617): Class resolved by unexpected DEX: Lcom/example/patient/Activator;(0x4074fa08):0x18a7b8 ref [Lorg/osgi/framework/BundleActivator;] Lorg/osgi/framework/BundleActivator;(0x40714410):0xbd630
11-25 23:16:26.271: W/dalvikvm(5617): (Lcom/example/patient/Activator; had used a different Lorg/osgi/framework/BundleActivator; during pre-verification)
11-25 23:16:26.271: I/dalvikvm(5617): Failed resolving Lcom/example/patient/Activator; interface 902 'Lorg/osgi/framework/BundleActivator;'
11-25 23:16:26.271: W/dalvikvm(5617): Link of class 'Lcom/example/patient/Activator;' failed
11-25 23:16:26.271: E/dalvikvm(5617): ERROR: defineClass(0x4074fa08, com.example.patient.Activator, 0x4079d468, 0, 955, 0x4073e918)
11-25 23:16:26.271: E/Zaid Log(5617): Problem installing the bundle :s
11-25 23:16:26.271: W/System.err(5617): org.osgi.framework.BundleException: Activator start error in bundle com.example.patient [1].
11-25 23:16:26.271: W/System.err(5617): at org.apache.felix.framework.Felix.activateBundle(Felix.java:2196)
11-25 23:16:26.271: W/System.err(5617): at org.apache.felix.framework.Felix.startBundle(Felix.java:2064)
11-25 23:16:26.271: W/System.err(5617): at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)
11-25 23:16:26.271: W/System.err(5617): at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)
11-25 23:16:26.271: W/System.err(5617): at com.example.patient_application.MainActivity.onCreate(MainActivity.java:136)
11-25 23:16:26.271: W/System.err(5617): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
11-25 23:16:26.271: W/System.err(5617): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715)
11-25 23:16:26.271: W/System.err(5617): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1767)
11-25 23:16:26.271: W/System.err(5617): at android.app.ActivityThread.access$1500(ActivityThread.java:122)
11-25 23:16:26.271: W/System.err(5617): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1005)
11-25 23:16:26.271: W/System.err(5617): at android.os.Handler.dispatchMessage(Handler.java:99)
11-25 23:16:26.271: W/System.err(5617): at android.os.Looper.loop(Looper.java:132)
11-25 23:16:26.271: W/System.err(5617): at android.app.ActivityThread.main(ActivityThread.java:4028)
11-25 23:16:26.271: W/System.err(5617): at java.lang.reflect.Method.invokeNative(Native Method)
11-25 23:16:26.271: W/System.err(5617): at java.lang.reflect.Method.invoke(Method.java:491)
11-25 23:16:26.271: W/System.err(5617): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
11-25 23:16:26.271: W/System.err(5617): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
11-25 23:16:26.271: W/System.err(5617): at dalvik.system.NativeStart.main(Native Method)
11-25 23:16:26.271: W/System.err(5617): Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
11-25 23:16:26.271: W/System.err(5617): at java.lang.VMClassLoader.defineClass(Native Method)
11-25 23:16:26.271: W/System.err(5617): at java.lang.ClassLoader.defineClass(ClassLoader.java:319)
11-25 23:16:26.271: W/System.err(5617): at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2279)
11-25 23:16:26.271: W/System.err(5617): at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1501)
11-25 23:16:26.271: W/System.err(5617): at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
11-25 23:16:26.271: W/System.err(5617): at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
11-25 23:16:26.271: W/System.err(5617): at java.lang.ClassLoader.loadClass(ClassLoader.java:500)
11-25 23:16:26.271: W/System.err(5617): at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1374)
11-25 23:16:26.271: W/System.err(5617): at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4329)
11-25 23:16:26.271: W/System.err(5617): at org.apache.felix.framework.Felix.activateBundle(Felix.java:2141)
11-25 23:16:26.271: W/System.err(5617): ... 17 more
There were two problems, and by solving them I managed to finally get my APK bundle installed and started on Felix.
1- Unlike OSGI bundles, the final signed APK does not contain the .class
files. That's why I was getting: Not found: com.example.patient.Activator
. By manually copying the com
directory from my android project to the signed APK, and then signing it again, I managed to solve this problem.
2- The second step mentioned by @slash33 which is:
•add a Reference Library entry to the project Build Path for your OSGi framework
was causing me the following error:
(Lcom/example/patient/Activator; had used a different Lorg/osgi/framework/BundleActivator; during pre-verification)
With help of this post, I simply deleted the reference to the library,and removed felix.jar
from my build path. Then I did this: Build Path->Configure Build Path->Projects, and then I added my application project that will load the bundle, and which already has felix.jar
in its build path. This as far as I understand will make the application and the APK bundle use the same felix.jar
. (Instead of keeping different one in both, which makes Dalvik complains).
Therefore, I believe that the correct steps to create an APK android bundle, and then to load it to the framework would be:
- Create a regular APK, for example by creating Eclipse Android Project.
- Make your bundle use the same OSGI framework library used by your application by:Build Path->Configure Build Path->Projects, and then add your application project that will load the bundle. Your application project should contain the OSGI framework jar file in its build path, (in my case
felix.jar
). - Create the bundle manifest file describing the bundle. You can call it
bundle.manifest
. - Say your application package is
com.acme.helloworld
(this value is set with manifest:package in AndroidManifest.xml), your OSGI bundle's Activator class MUST be placed in the packagecom.acme.helloworld
and you MUST setBundle-SymbolicName: com.acme.helloworld
in the bundle manifest. If any of these conditions is not met then will result in ajava.lang.NoClassDefFoundError
on runtime. - Use Android Tools > Export Unsigned Android Package
- Copy
bundle.manifest
to the root directory of the generated unsigned APK asMETA-INF/MANIFEST.MF
. You can use Winzip to open the unsigned APK and add the folderMETA-INF
. - Sign the APK using the command:
jarsigner -verbose -keystore /path_to_keystore/mykeystore.keystore my_application.apk my_keystore_alias
. - Copy your directory that contains all the
.class
files from your android project to the root directory of your signed apk. In my case: it is thecom
directory. - Sign your APK once again.
- Install the APK bundle.
- Have the OSGi framework load and start the APK bundle (the very same APK file)
这篇关于在OSGI包安卓活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!