Disable asset compression with Android aapt

Trying to embed all the assets resources into my final apk was not so easy as I tought.. at least using the ADT Eclipse plugin for building project.
In fact, using AssetManager.openFd to return to the C++ code a FileDescriptor does not work with compressed sources.
When aapt compile the resources into the apk file it compress by default all the files which extensions are not recognized and those which recognize as text files.

These are the extensions not compressed:

[cc]
static const char* kNoCompressExt[] = {
“.jpg”, “.jpeg”, “.png”, “.gif”,
“.wav”, “.mp2”, “.mp3”, “.ogg”, “.aac”,
“.mpg”, “.mpeg”, “.mid”, “.midi”, “.smf”, “.jet”,
“.rtttl”, “.imy”, “.xmf”, “.mp4”, “.m4a”,
“.m4v”, “.3gp”, “.3gpp”, “.3g2”, “.3gpp2”,
“.amr”, “.awb”, “.wma”, “.wmv”
};
[/cc]

I was looking into the .project file of my Eclipse project but it seems that changing things inside that file ( like values into the tag ) does not affect the builder.

The first thing I tried was to remap the aapt executable using a shell script ( and renaming the original aapt file into _aapt ):

[cc]
#!/bin/bash

strParams=””
CWD=’dirname $0’

for i in $@; do
if [ $i = “-S” ]; then
strParams=”$(echo $strParams) -v -0 \”\””
fi
strParams=”$(echo $strParams) $i”
done

tool=”$CWD/_aapt $strParams”
$tool 1>&2
[/cc]

In fact, when building the project in eclipse I could see the whole output, but the files are still being compressed, even if I call the same command in a shell the assets aren’t compressed.
I haven’t yet find a solution so for the meantime I decided to use ant to build my project overriding the default “-package-resources” target in this way:

[cce]

Packaging resources
${asset.absolute.dir}
command=”package”
verbose=”${verbose}”
versioncode=”${version.code}”
manifest=”AndroidManifest.xml”
assets=”${asset.absolute.dir}”
androidjar=”${android.jar}”
apkfolder=”${out.absolute.dir}”
resourcefilename=”${resource.package.file.name}”
resourcefilter=”${aapt.resource.filter}”>

[/cce]

In this way the project is being compiled correctly and all my assets are embedded not compressed!

P.S. my claim token is: 7C8AATS7Q5A3

Update your app VERSION using ant

This is just a quick tip in case someone needs it. Maybe when you compile your flash application or your swc library you want to automatically update the “VERSION” number too without do it manually every time.

This is the way I do. In the “compile” task I’ve added a depends link to this ant task:
<target name="update-version">
<propertyset id="tdate"></propertyset>
<tstamp>
<format property="tdate" pattern="yyyyMMdd"/>
</tstamp>
<buildnumber file="build.number"/>
<echo>updating version to current datetime: ${tdate}</echo>
<replaceregexp byline="true">
<regexp pattern="public static const BUILD_DATE: String = \'([0-9]+)'"/>
<substitution expression="public static const BUILD_DATE: String = '${tdate}'"/>
<fileset dir="src/it/sephiroth/somestuff">
<include name="Library.as"/>
</fileset>
</replaceregexp>
<replaceregexp byline="true">
<regexp pattern="public static const BUILD_NUMBER: String = \'([0-9\.]+)'"/>
<substitution expression="public static const BUILD_NUMBER: String = '${build.number}'"/>
<fileset dir="src/it/sephiroth/somestuff">
<include name="Library.as"/>
</fileset>
</replaceregexp>
</target>
The 2 optional tasks I’ve used are: BuildNumber task and ReplaceRegExp Task. In this way every time I do an ant compile, it will update my build number and modification date.
What this task does is find this 2 lines in my Library.as file:

public static const BUILD_DATE: String = ‘20100131’;

and

public static const BUILD_NUMBER: String = ‘5’;

then replace the BUILD_DATE const with the current date and the BUILD_NUMBER with an incremental build number. After being executed the first time, ant will also create a new file in your directory called “build.number” with the latest build number int.

mxmlc NullPointerException crash

Today I was getting crazy to find out why Flex didn’t want to compile my application.. Clicking on compile it started suddenly to give me an internal compile error and nothing else. So i tried to compile with the mxmlc from a console just to see the error log and the outpuw was:
java.lang.NullPointerException
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:891)
at macromedia.asc.parser.BinaryExpressionNode.evaluate(BinaryExpressionNode.java:38)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:890)
at macromedia.asc.parser.BinaryExpressionNode.evaluate(BinaryExpressionNode.java:38)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:891)
at macromedia.asc.parser.BinaryExpressionNode.evaluate(BinaryExpressionNode.java:38)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:890)
at macromedia.asc.parser.BinaryExpressionNode.evaluate(BinaryExpressionNode.java:38)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:962)
at macromedia.asc.parser.ListNode.evaluate(ListNode.java:27)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:5859)
at macromedia.asc.parser.LiteralXMLNode.evaluate(LiteralXMLNode.java:28)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:3087)
at macromedia.asc.parser.VariableBindingNode.evaluate(VariableBindingNode.java:48)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:962)
at macromedia.asc.parser.ListNode.evaluate(ListNode.java:27)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:2897)
at macromedia.asc.parser.VariableDefinitionNode.evaluate(VariableDefinitionNode.java:32)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:4629)
at macromedia.asc.parser.ClassDefinitionNode.evaluate(ClassDefinitionNode.java:86)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:938)
at macromedia.asc.parser.ArgumentListNode.evaluate(ArgumentListNode.java:28)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:750)
at macromedia.asc.parser.SetExpressionNode.evaluate(SetExpressionNode.java:39)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:580)
at macromedia.asc.parser.MemberExpressionNode.evaluate(MemberExpressionNode.java:31)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:1273)
at macromedia.asc.parser.ExpressionStatementNode.evaluate(ExpressionStatementNode.java:33)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:4407)
at macromedia.asc.parser.ClassDefinitionNode.evaluate(ClassDefinitionNode.java:86)
at macromedia.asc.semantics.FlowAnalyzer.evaluate(FlowAnalyzer.java:2577)
at macromedia.asc.parser.ProgramNode.evaluate(ProgramNode.java:63)
at flex2.compiler.as3.Compiler.analyze2(Compiler.java:436)
at flex2.compiler.mxml.InterfaceCompiler.analyze2(InterfaceCompiler.java:337)
at flex2.compiler.mxml.Compiler.analyze2(Compiler.java:130)
at flex2.compiler.API.analyze(API.java:2360)
at flex2.compiler.API.analyze(API.java:2275)
at flex2.compiler.API.batch2(API.java:337)
at flex2.compiler.API.batch(API.java:1025)
at flex2.compiler.API.compile(API.java:1211)
at flex2.compiler.API.compile(API.java:1114)
at flex2.tools.Compiler.main(Compiler.java:222)

Wow!!
So, how can I find the problem? I can’t find any useful information from this log..
For this reason I had to remove portion of code from my mxml and from all the imported packages.. 2 hours of “debugging” gave me the solution!

A syntax error in a declaration of an XMLList was the problem!  Fixed the line also the compiler started to run again with no problems.

This is a portion of mxml code to reproduce the problem:
;

< ![CDATA[ private var uuid:String = ""; private var menubarXML:XMLList = <>
<>;
]]>