3

我试图在 Android 2.1 上运行一个示例 Preon 应用程序,但没有成功。我想知道是否可以在 Android 上运行 Preon 应用程序。让 Preon 框架 Dalvik 友好有多难?

Preon 是一个 Java 库,用于以声明的方式为比特流压缩数据构建编解码器。想想 JAXB 或 Hibernate,然后是 Wilfred Springer 编写的二进制编码数据。


以下是我尝试在 Android 中运行使用 Preon 的简单应用程序时的发现:

Preon 依赖于 Pecia。Pecia 间接依赖于 stax-api,Android 中不支持开箱即用。Preon核心处理中使用的是stax-api吗?我可以从 Preon 依赖项中排除 stax-api 吗?

在从依赖项中排除 pecia 之后(不知道后果),我发现 preon 带来了 log4j.properties 文件的多个副本。我建议将 log4j.properties 文件移动到 preon 和 pecia 项目上的 /src/test/resources 目录,以避免将它们与类一起使用。

由于重复的 log4j.properties 文件,android-maven-plugin 在包目标处失败,并显示以下消息:

[信息] java.util.zip.ZipException:重复条目:log4j.properties

[信息] --------------------------------------------- -------------------------

[信息] 构建失败

[信息] --------------------------------------------- -------------------------

[INFO] 总时间:19.717s

[INFO] 完成于:2011 年 3 月 23 日星期三 14:30:55 PST

[INFO] 最终内存:7M/62M

4

2 回答 2

2

Well, I will answer my own question. It is POSSIBLE to use the Preon framework in Android. However, Preon does not work out of the box. I managed to run a sample application after doing the following changes:
1. I moved all log4.properties in the preon projects to their corresponding /src/test/resources directory.
2. Remove dependency on pecia.
3. Embedded the following interfaces from pecia in preon-binding:
DocumentElement.java
Documenter.java
Para.java
ParaContents.java
4. org.codehaus.preon.code.Codecs:
I commented out the following imports and all its related code (the ones that won't compile after this change):
import javax.xml.stream.XMLStreamException;
import nl.flotsam.pecia.builder.ArticleDocument;
import nl.flotsam.pecia.builder.base.DefaultArticleDocument;
import nl.flotsam.pecia.builder.base.DefaultDocumentBuilder;
import nl.flotsam.pecia.builder.html.HtmlDocumentBuilder;
import nl.flotsam.pecia.builder.xml.StreamingXmlWriter;
import nl.flotsam.pecia.builder.xml.XmlWriter;
5. org.codehaus.preon.codec.ObjectCodeFactory
commented out:
/* target.document(codec.getCodecDescriptor().reference(CodecDescriptor.Adjective.THE, false)); */

Suggestions:

I suggest to refactor preon code to have documentation code separated from runtime dependencies.

Wilfred, If you want, I could contribute to your project.

Oscar.

于 2011-03-28T21:19:06.930 回答
0

you also could take a look at Java Binary Block Parser, the library is compatible with Android 2.1+

于 2015-03-31T08:48:56.890 回答