tags:

views:

190

answers:

2

I configured my android project to use ant. When building using the keyword release it fails with this message:

java.lang.NullPointerException
at com.android.ant.ApkBuilderTask.execute(ApkBuilderTask.java:239)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)

It fails on build.xml line 249 which is included here:

<macrodef name="package-helper">
        <attribute name="sign.package" />
        <element name="extra-jars" optional="yes" />
        <sequential>
            <apkbuilder
                    outfolder="${out.absolute.dir}"
                    basename="${ant.project.name}"
                    signed="@{sign.package}"
                    debug="${manifest.debuggable}"
                    verbose="${verbose}">  **LINE 249 IS HERE**
                <file path="${intermediate.dex.file}" />
                <sourcefolder path="${source.absolute.dir}" />
                <sourcefolder refid="android.libraries.src" />
                <jarfolder path="${external.libs.absolute.dir}" />
                <jarfolder refid="android.libraries.libs" />
                <nativefolder path="${native.libs.absolute.dir}" />
                <nativefolder refid="android.libraries.libs" />
                <extra-jars/>
            </apkbuilder>
        </sequential>
    </macrodef>

That is called from line 401 which contains these lines:

<target name="-package-release" depends="-dex, -package-resources">
    <package-helper sign.package="false" />
</target>

It looks like there is some problem with ApkBuilderTask.java but I don't know how/where to get the source of ApkBuilderTask.java. Has anyone run into this problem and found a solution? I'm using android SDK tools revision 7 if that helps.

Note: Running "ant debug" or "ant release" all comes out to the same result.

A: 

Here is the source code for the ant task: http://android.git.kernel.org/?p=platform/sdk.git;a=tree;f=anttasks/src/com/android/ant;h=91c4a8ea64271f32febb9251a7682f191faaa117;hb=tools_r7

Looks like the variable mDexPath is null, and I don't see a <dex> element inside the <apkbuilder>. Did you see this warning anywhere: "WARNING: Using deprecated <file> inner element in ApkBuilderTask."?

Did you create your own ant script to or are you using a project created by the android tool? You might want to copy your source code, resources, AndroidManifest.xml and other libraries/assets into a newly created Android project to fix it.

satur9nine
+1  A: 

This is a change introduced in the r7 tools. You need to update the <apkbuilder> task in your build.xml, in the ways that saturnine points out above.

Given that this error only happens when you customize your build.xml, I think you need to go back and redo the customizations. If you look for $ANDROID_SDK/tools/ant/ant_rules_r3.xml and paste them into your build.xml (replacing the definitions that you pasted in last time), it should fix your problems.

You may be able to get away without customizations, as the new version of the rules are far more customizable, and include -pre-compile and -post-compile hooks.

Dominic Mitchell
That rules file did it so I will mark this as the correct answer. My actual problem ended up being that I created my project using the android tool but I was referencing a library incorrectly (it wasn't an Android library) because my eclipse ADT plugin was old. Updated the plugin, made the new android library and then ran the android command line program and it worked like a charm. Thank you satur9nine and Dominic for the hints that got me in the right direction!
BoredAndroidDeveloper