Android aapt duplicate files error when building with ant

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.

Answer: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 ...

Answer:2

I need to convert some string date to another format string date String current = "Tue Apr 16 10:59:11 EDT 2019"; I want to get result date String in format ISO-8601 in accordance with the pattern - ...

I have created .so file using android NDK. In xxx.java class I added some native methods to call from c/c++ files. these native methods I am calling in my own methods for example like below, static ...

I am using selenium webdriver with Firefox . driver.navigate().back(); I browse through pages and when I navigate back through page , I get following exception.In Browser it says Document expired. ...

This is my code for my android app which isn't complete package com.example; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import ...