1

I am using ant to make a build system for our android project which has two build targets, Dev and Release.

This involves replacing the default -package-resources target with my own one in my build.xml. It goes from this:

<target name="-package-resources" depends="-crunch">
    <!-- only package resources if *not* a library project -->
    <do-only-if-not-library elseText="Library project: do not package resources..." >
        < aapt executable="${aapt}"
                command="package"
                versioncode="${version.code}"
                versionname="${version.name}"
                debug="${build.is.packaging.debug}"
                manifest="${out.manifest.abs.file}"
                assets="${asset.absolute.dir}"
                androidjar="${project.target.android.jar}"
                apkfolder="${out.absolute.dir}"
                nocrunch="${build.packaging.nocrunch}"
                resourcefilename="${resource.package.file.name}"
                resourcefilter="${aapt.resource.filter}"
                libraryResFolderPathRefid="project.library.res.folder.path"
                libraryPackagesRefid="project.library.packages"
                previousBuildType="${build.last.target}"
                buildType="${build.target}"
                ignoreAssets="${aapt.ignore.assets}"
                >
            <res path="${out.res.absolute.dir}" />
            <res path="${resource.absolute.dir}" />
            <!-- <nocompress /> forces no compression on any files in assets or res/raw -->
            <!-- <nocompress extension="xml" /> forces no compression on specific file extensions in assets and res/raw -->
        </aapt>
    </do-only-if-not-library>
</target>

To this :

<target name="-package-resources" depends="-crunch">
    <!-- only package resources if *not* a library project -->
    <echo message="Packaging resources with ${package.internal} as a package name" />
    <do-only-if-not-library elseText="Library project: do not package resources..." >
        <exec executable="${aapt}" failonerror="true">
                <arg value="package" />
                <arg value="-f" />
                <arg value="-v" />
                <arg value="-M" />
                <arg path="${out.manifest.abs.file}" />
                <arg value="-A" />
                <arg path="${asset.absolute.dir}" />
                <arg value="-I" />
                <arg path="${project.target.android.jar}" />
                <arg value="-m" />
                <arg value="-J" />
                <arg path="${out.absolute.dir}" />
                <arg value="-F" />
                <arg path="${out.absolute.dir}/${resource.package.file.name}" />
                <arg value="-S" />
                <arg path="${out.res.absolute.dir}" />
                <arg path="${resource.absolute.dir}" />
                <arg value="--no-crunch" />
        <arg value="--rename-manifest-package" />
        <arg value="${package.internal}" />
        </exec>
    </do-only-if-not-library>
</target>

However, when I launch the build, it fails on this step with the following error:

-package-resources:
     [echo] Packaging resources with dev.appname.android as a package name
     [exec] Found 4 custom asset files in /appname/app/native/android/appname/assets
     [exec] Processing raw dir '/appname/app/native/android/appname/res'
     [exec] /appname/app/native/android/appname/res/drawable/map_marker.png: error: Duplicate file.
     [exec] /appname/app/native/android/appname/bin/res/drawable/map_marker.png: Original is here.

Not sure how to proceed here. My understanding was that the -f flag should take care of overwriting files.

2 Answers 2

1

The problem here is that the same resource file is being found twice.

[exec] /appname/app/native/android/appname/res/drawable/map_marker.png: error: Duplicate file. [exec] /appname/app/native/android/appname/bin/res/drawable/map_marker.png: Original is here.

When running Ant build, it is advisable that you keep Eclipse closed as it automatically dumps res/* to bin

Also make sure you have a clean target that cleans bin before your aapt is run. Hope doing both will resolve your issue ...

When I try and build with the following build.properties it succeeds. The build.properties I have used is as follows ..

sdk.dir=<sdk.dir>
source.dir=src
gen.dir=gen
resource.dir=res 
asset.dir=res/assets
external.libs.dir=libs
out.dir=bin
target=android-10
target.api=android-10

Hope it helps ...

Sign up to request clarification or add additional context in comments.

5 Comments

I stopped eclipse, did an ant clean and then launched the build again. But the result was exactly the same. What is wierd is that the file is being copied across by the crunch target just before.
Could you share target crunch as well, i think it will help
I haven't changed it. It's the one in the build.xml in the tools/ant/ folder of the sdk.
target -crunch it self executes aapt with input as res folder and output as bin folder. So I believe now you need to skip the res folder in target -package-resources
correct me , i was wrong earlier. Looks like there may be an issue with build.properties that you are using as input to build.xml
1

Turns out this was my own fault; the following,

<arg value="-S" />
<arg path="${out.res.absolute.dir}" />
<arg path="${resource.absolute.dir}" />

Should've been:

<arg value="-S" />
<arg path="${out.res.absolute.dir}" />
<arg value="-S" />
<arg path="${resource.absolute.dir}" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.