Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在APK Bundle中使用android API会给出:;找不到类';android.content.Context';,参考方法com.example.patient.Activator.start“;_Android_Osgi_Bundle_Apk_Apache Felix - Fatal编程技术网

在APK Bundle中使用android API会给出:;找不到类';android.content.Context';,参考方法com.example.patient.Activator.start“;

在APK Bundle中使用android API会给出:;找不到类';android.content.Context';,参考方法com.example.patient.Activator.start“;,android,osgi,bundle,apk,apache-felix,Android,Osgi,Bundle,Apk,Apache Felix,我正在将OSGI框架嵌入Android应用程序中。除了我的android应用程序之外,我还有一个APK捆绑包,我使用以下步骤创建它: 创建常规APK,例如通过创建EclipseAndroid 项目 使您的捆绑包使用与您的应用程序相同的OSGI框架库 应用程序:生成路径->配置生成路径->项目,然后 添加将加载捆绑包的应用程序项目。你的 应用程序项目应该在其内部包含OSGI框架jar文件 构建路径(在我的例子中是felix.jar) 创建描述捆绑包的捆绑包清单文件。你可以打电话 它bundle.

我正在将OSGI框架嵌入Android应用程序中。除了我的android应用程序之外,我还有一个APK捆绑包,我使用以下步骤创建它:

  • 创建常规APK,例如通过创建EclipseAndroid 项目
  • 使您的捆绑包使用与您的应用程序相同的OSGI框架库 应用程序:生成路径->配置生成路径->项目,然后 添加将加载捆绑包的应用程序项目。你的 应用程序项目应该在其内部包含OSGI框架jar文件 构建路径(在我的例子中是
    felix.jar
  • 创建描述捆绑包的捆绑包清单文件。你可以打电话 它
    bundle.manifest
  • 假设您的应用程序包是
    com.acme.helloworld
    (此值为 设置manifest:package in
    AndroidManifest.xml
    ),您的OSGI包的 Activator类必须放在包
    com.acme.helloworld
    中,并且 必须在捆绑包中设置捆绑包符号名称:
    com.acme.helloworld
    显示如果不满足上述任何条件,则将导致 运行时上的java.lang.NoClassDefFoundError
  • 使用Android工具>导出未签名的Android软件包
  • 将bundle.manifest复制到生成的未签名文件的根目录 APK as
    META-INF/MANIFEST.MF
    。您可以使用Winzip打开未签名的 APK并添加文件夹
    META-INF
  • 使用命令对APK进行签名:
    jarsigner-verbose-keystore
    /指向密钥库/mykeystore.keystore my\u application.apk my\u keystore\u别名的路径
  • 复制您的目录,该目录包含您数据库中的所有.class文件 android项目到已签名apk的根目录。就我而言: 它是
    com
    目录
  • 再次签署您的APK
  • 安装APK捆绑包
  • 加载OSGi框架并启动APK包(完全相同 (APK文件)
使用这些步骤,我成功地将APK包加载到Felix框架,并且启动正常

但是,我现在尝试启动APK捆绑包中存在的活动,因此我执行了以下操作:

在我的应用程序项目中,我将应用程序上下文注册为服务,以使其可用于APK捆绑包:

 // Register the application's context as an OSGi service!
    BundleContext bundleContext = m_felix.getBundleContext();
    ServiceRegistration regContext = bundleContext.registerService(Context.class,
      getApplicationContext(), new Hashtable());
在我的APK bundle
start
method()中,在
Activator
类中:

ServiceReference<Context> ref = bundleContext.getServiceReference(Context.class);
final Context ctx = bundleContext.getService(ref);

Intent intent = new Intent();
String pkgName = View_Patient_File_Activity.class.getPackage().getName();
String clssName = View_Patient_File_Activity.class.getName();
intent.setClassName(pkgName, clssName);

// You may add the NEW_TASK flag
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

// Important: do not use startActivity(Context, Class) version because it will fail to resolve the activity
ctx.startActivity(intent);
我在我的应用程序项目中导出了android软件包,如下所示:

static final String ANDROID_FRAMEWORK_PACKAGES = (
            "android,"
            + "android.app,"
            + "android.content,"
            + "android.database,"
            + "android.database.sqlite,"
            + "android.graphics,"
            + "android.graphics.drawable,"
            + "android.graphics.glutils,"
            + "android.hardware,"
            + "android.location,"
            + "android.media,"
            + "android.net,"
            + "android.net.wifi,"
            + "android.opengl,"
            + "android.os,"
            + "android.provider,"
            + "android.sax,"
            + "android.speech.recognition,"
            + "android.telephony,"
            + "android.telephony.gsm,"
            + "android.text,"
            + "android.text.method,"
            + "android.text.style,"
            + "android.text.util,"
            + "android.util,"
            + "android.view,"
            + "android.view.animation,"
            + "android.webkit,"
            + "android.widget");


         m_configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
                ANDROID_FRAMEWORK_PACKAGES);
我将这些包导入我的APK包中。下面是我的
MANIFEST.MF

Manifest-Version: 1.0
Bundle-Vendor: Zaid
Bundle-Version: 1.0.0
Bundle-Name: Patient
Bundle-ManifestVersion: 2
Bundle-Activator: com.example.patient.Activator
Bundle-Description: View Patient File
Bundle-SymbolicName: com.example.patient
Bundle-RequiredExecutionEnvironment: OSGi/Minimum-1.0
Import-Package: android, android.app, android.content, org.osgi.framework
同样的错误一再出现。有人能帮忙吗?多谢各位


注意:我从用户@slash33那里获取了这些想法和代码,他们以前有过这个主题的经验

问题出现在我的
MANIFEST.MF
文件中。我找不到错误,但我使用了文件的旧副本,然后所有错误都消失了。下面是我更新的
MANIFEST.MF
文件

Manifest-Version: 1.0
Bundle-Vendor: Zaid
Bundle-Version: 1.0.0
Bundle-Name: Patient
Bundle-ManifestVersion: 2
Bundle-Activator: com.example.patient.Activator
Bundle-Description: View Patient File
Import-Package: org.osgi.framework, android.content
Bundle-SymbolicName: com.example.patient
Bundle-RequiredExecutionEnvironment: OSGi/Minimum-1.0
我的APK包已成功加载到Felix framework,现在我可以在包内启动活动。感谢上帝

Manifest-Version: 1.0
Bundle-Vendor: Zaid
Bundle-Version: 1.0.0
Bundle-Name: Patient
Bundle-ManifestVersion: 2
Bundle-Activator: com.example.patient.Activator
Bundle-Description: View Patient File
Import-Package: org.osgi.framework, android.content
Bundle-SymbolicName: com.example.patient
Bundle-RequiredExecutionEnvironment: OSGi/Minimum-1.0