开发者

Preon on Android

I tried to run a sample Preon application on Android 2.1 without luck. I wonder if running a Preon application on Android is even possible. How hard would it be to make the Preon framework Dalvik friendly?

Preon is a Java l开发者_如何学JAVAibrary for building codecs for bitstream-compressed data in a declarative way. Think JAXB or Hibernate, but then for binary encoded data written by Wilfred Springer.


Below are my finding when trying to run a simple application that uses Preon in Android:

Preon has a dependency on Pecia. Pecia indirectly depends on stax-api which is not supported out of the box in Android. Is the stax-api used in the Preon core processing? Can I exclude the stax-api from the Preon dependencies?

After excluding pecia from the dependencies (without knowing the consequences), I found out that preon brings multiple copies of the log4j.properties file. I suggest moving log4j.properties files to the /src/test/resources directory on the preon and pecia projects to avoid bringing them with the classes.

Because duplicated log4j.properties files, the android-maven-plugin fails at the package goal with the following message:

[INFO] java.util.zip.ZipException: duplicate entry: log4j.properties

[INFO] ------------------------------------------------------------------------

[INFO] BUILD FAILURE

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 19.717s

[INFO] Finished at: Wed Mar 23 14:30:55 PST 2011

[INFO] Final Memory: 7M/62M


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜