gpt4 book ai didi

android - AIR for Android 应用程序 - 找不到服务

转载 作者:行者123 更新时间:2023-11-30 04:26:37 26 4
gpt4 key购买 nike

问题:当我发送一个 Intent 以从 Activity 绑定(bind)它时,在执行期间“找不到”名为 PdService 的服务。

[编辑:解决方案]

我不是很清楚围绕解决方案的问题,但是已经找到了解决方案。当我导出主项目(链接到 Android 库项目)的 JAR 时,我选择了将库项目也包含在 JAR 中的选项。这解决了问题。

现在,这很奇怪,因为链接项目的源代码显然在此之前就已放入 JAR 中,只是没有被 Android 运行时“发现”。但出于某种原因,明确包括整个链接项目已经解决了这个问题。这也是一个不幸的解决方法,因为我现在必须在我的 JAR 中包含比我想要的更多的内容,但现在问题已经解决。

[原始问题详情]

详细信息:

  • 该应用是 Android 版 AIR 应用(.SWF + OTHER_STUFF -> .APK)
  • Java 代码(包括 PdService)已打包在 AIR Native Extension (.ane) 中
  • PdService 的 Intent 出现在我们称为 PdContext 的自定义 FREContext(请参阅 AIR Native Extensions)中,特别是在名为 init() 的方法中。
  • 为了完整起见,我在扩展的 Android list 以及 AIR 应用程序的 application.xml 文件中都包含了 PdService 的标记。
  • 扩展包名称为:com.nichemobile.pd.pdextension
  • PdService类路径为:org.puredata.android.service.PdService
  • 最终用户应用程序的 ID (AIR ID) 是:com.nichemobile.pdextension.testapp

我尝试了多种 Intent 组合,包括(thisActivity 是对正在执行的 Activity 的引用):

bindIntent.setClassName(thisActivity, "org.puredata.android.service.PDService");
bindIntent.setClassName(thisActivity, ".org.puredata.android.service.PDService");
bindIntent.setClassName(thisActivity, "..org.puredata.android.service.PDService");
bindIntent.setClassName("org.puredata.android.service", ".org.puredata.android.service.PDService");
bindIntent.setClassName("org.puredata.android.service", "org.puredata.android.service.PDService");
bindIntent.setClassName("", "org.puredata.android.service.PDService");
bindIntent.setClassName(".", "org.puredata.android.service.PDService");

每个 Intent 都会导致一个运行时错误,声称该服务“未找到”。有谁知道如何纠正这个问题?

根据我对 Intents for Services 的理解,这两个参数应该是:包:air.com.nichemobile.pdextension.testapp类:org.puredata.android.service.PDService但是当然,在第一个例子中这并没有奏效。

我目前的理论:

查看编译后的APK中的classes.dex文件,发现在classes.dex文件的根目录下,有3个子目录:

  • air.com.nichemobile.pdextension.testapp(包含 AppEntry Activity )
  • com(包含我们的扩展 Java 类)
  • org.puredata(包含所有 PD 类,包括 PdService)

我想知道应用程序是否无法找到服务,因为它们存在于 classes.dex 文件中的“air.com.nichemobile.pdextension.testapp”目录之外。现在,该应用程序可以在/com 和/org.puredata 目录中的类中执行代码 - 但我想知道在 Android 平台上启动服务的过程是否以某种方式被 classes.dex 中的此类结构干扰文件。

作为我在上面谈论的内容的一个有点令人费解的例子 - 在我尝试绑定(bind)此服务之前的那一行,我可以说:

Log.d(TAG, "PdService package: " + PdService.class.getPackage());
Log.d(TAG, "PdService class name: " + PdService.class.getName());

然后我得到输出:

PdService package: package org.puredata.android.service
PdService class name: org.puredata.android.service.PdService

如有任何说明,我们将不胜感激。

谢谢。

马特

最佳答案

问题在于您的 AIR 应用程序的签名证书和包名称。

Adobe AIR native 扩展规则

规则 1。代码签名证书包必须与 app.xml 中的应用程序 ID 匹配所以如果证书包是com.my.company ,那么air app id必须是<id>com.my.company</id>

规则 2。使用 ADT 为 android 打包 native 扩展时,会在您的包名称中添加一个前缀,因此它看起来像 air.com.my.company .

当 Android ActivityManager 尝试运行您的服务时,它会在 air.com.my.company 中查找它.因此,Service 类必须位于您的 Java 代码中的同一个包中(包括“air”前缀)。正确的 TestService 类定义为 air.com.my.company.TestService

使用以下 list ,它运行得很好!

<application>
<activity android:name=".TestActivity">
<intent-filter>
<action android:name="TestActivity"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>

<service android:enabled="true" android:exported="true" android:name=".TestService">
</service>
</application>

关于android - AIR for Android 应用程序 - 找不到服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8373876/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com