适用于 Android 的 AIR 3 本机扩展 - 我可以/如何包含第 3 方库?
尽管围绕 AIR 3 中的本机扩展支持进行了各种新的宣传,但我还没有发现任何事情可以证实或否认可以在本机 Android 实现中包含和使用外部 JAR。
所有示例基本上都展示了挂钩内置 Android API 的能力。但是,如果有人想使用数百个使它更容易的库之一怎么办?当然,这似乎应该是可能的。我将尝试概述我所做的事情,也许有人会发现一个缺陷:
- 使用来自第 3 方 Android 库 XYZ 的编译导入成功创建了本机 Android 库。
- 将 Android 项目导出为 JAR 文件。 注意:引用的第 3 方 JAR 位于 jar 内的 /lib 中。
- 成功创建 ActionScript 库 (SWC) 以与本机 Android 库交互。
- 从 SWC、extension.xml、Android JAR 和library.swc 创建了 ANE 包(适用于 Android-ARM 平台,从 SWC 中提取)。
注意:还尝试将第 3 方库放入此处概述的文件结构中: http://help.adobe.com/en_US/air/extensions/WSf268776665d7970d-24823354 12ffea65006-8000.html#WSf268776665d7970d-6be13ace1308aaebeca-7fff。我认为这更适合使用 JNI 或其他方式执行运行时类型,因此那篇文章让我有点困惑。 - 在示例 Flex Mobile 项目中使用了 ANE。
- 在测试 DroidX 设备上构建并安装 APK 文件。
- 可以在 LogCat 中成功查看 AIR 应用程序加载(和跟踪语句)
“ActivityManager:显示 com.me.androidapp/.AppEntry”
- 可以成功查看 AIR 应用程序通过运行时调用本机 Android Java 代码来实例化扩展&语境。
"mye_native: MyExtension.initialize", "mye_native: MyExtensionContext.createContext"
- 一旦 AIR 应用程序尝试调用本机函数,它就会崩溃,无法从第 3 方 Android 库找到类:<代码>E dalvikvm:找不到类“com.thirdparty.SomeClass”,从方法引用com.me.nativeExtentions.MyExtensionFunction.call
有什么想法吗?看起来应该是这样的。
我注意到的一件事是,当我从我的纯 Java Android 应用程序(也有第 3 方 Android 库)中拆开 APK 和 Dex 时,似乎第 3 方的类已包含在其中(不仅仅是罐子参考)。 当我对我的 Flex APK 执行同样的操作时,我只发现我自己的 Java 类加上 Adobe 的类,并且找不到我可以看到的第 3 方类。
我在 Adobe 论坛上发布了此内容,但我想我应该尝试一下 SO 智囊团。谢谢。
With all the new hype surrounding native extension support in AIR 3, I haven't found a single thing that confirms or denies it is possible to include and use an external JAR inside the native Android implementation.
All of the examples basically showcase the ability to hook into the built-in Android APIs. But what if someone wants to use one of hundreds of libraries that make it easier? Certainly it seems like this should be possible. I'll try to outline what I've done and maybe someone will spot a flaw:
- Successfully created native Android library, using compiled-in imports from 3rd party Android library XYZ.
- Exported Android project as JAR file.
Note: The referenced 3rd party JAR is in /lib inside the jar. - Successfully created ActionScript library (SWC) to interface with native Android library.
- Created ANE package from SWC, extension.xml, Android JAR, and library.swc (for platform Android-ARM, extracted from SWC).
Note: Have also tried putting the 3rd party library in file structure outlined here: http://help.adobe.com/en_US/air/extensions/WSf268776665d7970d-24823354 12ffea65006-8000.html#WSf268776665d7970d-6be13ace1308aaebeca-7fff. I think this is more geared to runtime type execution with JNI or whatever, so that article has left me a little confused. - Used ANE in example Flex Mobile project.
- Built and installed APK file on test DroidX device.
- Can successfully see AIR application loading (and trace statements) in LogCat
"ActivityManager: Displayed com.me.androidapp/.AppEntry"
- Can successfully see native Android Java code being invoked via runtime by AIR app to instantiate extension & context.
"mye_native: MyExtension.initialize", "mye_native: MyExtensionContext.createContext"
- As soon as AIR app tries to call native function, it blows up, not able to find the classes from 3rd party Android library:
E dalvikvm: Could not find class 'com.thirdparty.SomeClass', referenced from method com.me.nativeExtentions.MyExtensionFunction.call
Any ideas? It seems like it should work this way.
One thing I have noticed is that when I blow apart the APK and Dex from a pure Java Android app of mine (that also has 3rd party android libraries), it appears that the classes from the 3rd party have been included inside it (not just a jar reference).
When I do the same thing with my Flex APK, I find only my own Java classes plus Adobe's, and the 3rd party ones are nowhere to be found that I can see.
I posted this on the Adobe forums, but I thought I'd give the SO think-tank a try. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须将所有罐子合并为一个。类似于 http://code.google.com/p/jarjar/ 或您自己的 Ant脚本会有所帮助。
编辑添加示例:
假设您的主扩展 jar 文件是 extension.jar 并且您正在使用 external.jar 中的代码。然后,您可以使用 Java jar 工具将 external.jar 中的类放入 extension.jar 中:
jar -xf external.jar
这会将 .class 文件提取到包文件夹中。如果顶级包是“com”,那么您可以使用以下命令将它们添加到extension.jar:
jar -uf extension.jar com
(对外部jar中的每个顶级包重复第二个命令。)
You have to combine all your jars into one. Something like http://code.google.com/p/jarjar/ or your own Ant script will help.
Edited to add example:
Suppose your main extension jar file is extension.jar and you are using code in external.jar. Then you can put the classes from external.jar into extension.jar using the Java jar tool:
jar -xf external.jar
This will extract the .class files into package folders. If the top-level package is "com", then you can add those to extension.jar with:
jar -uf extension.jar com
(Repeat the second command for each top-level package in the external jar.)
您还可以通过将库 jar 文件转换为 zip 文件(只需将其重命名为 .zip)来手动合并库 jar,并将类从第 3 方库复制到主库中,然后将该类重命名回 .jar
You could also combine the library jars manually by turning them into zip-files (just rename them to .zip) and copy the classes from the 3rd party library into the main one and rename that one back to .jar