Ant Build AAPT Crunch is stripping draw9 information from Library resource images

…衆ロ難τιáo~ 提交于 2019-12-05 08:51:13

I've had exactly the same problem yesterday.

I have one codebase which I use to build different flavours of the app (diff package-name and some specific resources) using ant.

build.xml worked fine but 9patches were corrupted while using app (as you say, treated as png and stretched).

I nailed down the problem to -crunch task within ant (just as you did).

In my case I use two different res folders so I changed original crunch task from this

<!-- Updates the pre-processed PNG cache -->
    <target name="-crunch">
        <exec executable="${aapt}" taskName="crunch">
            <arg value="crunch" />
            <arg value="-v" />
        <arg value="-S" />
            <arg path="${resource.absolute.dir}" />
            <arg value="-C" />
            <arg path="${out.res.absolute.dir}" />
        </exec>
    </target>

to this

 <target name="-crunch">
        <exec executable="${aapt}" taskName="crunch">
            <arg value="crunch" />
            <arg value="-v" />
            <arg value="-S" />
            <arg path="${resource.flavour.dir}" />
            <arg value="-S" />
            <arg path="${resource.absolute.dir}" />
            <arg value="-C" />
            <arg path="${out.res.absolute.dir}" />
        </exec>
    </target>

but this produced mentioned 9patch artefacts (also in libraries like fb) .. so I thought I will change this to process resourceflavour.dir only if this is not a library which gave proper result (no 9pathc artefacts)

<target name="-crunch">
    <do-only-if-not-library elseText="Library project: do not package resources..." >
        <exec executable="${aapt}" taskName="crunch">
            <arg value="crunch" />
            <arg value="-v" />
            <arg value="-S" />
            <arg path="${resource.flavour.dir}" />
            <arg value="-C" />
            <arg path="${out.res.absolute.dir}" />
        </exec>
    </do-only-if-not-library>
        <exec executable="${aapt}" taskName="crunch">
            <arg value="crunch" />
            <arg value="-v" />
            <arg value="-S" />
            <arg path="${resource.absolute.dir}" />
            <arg value="-C" />
            <arg path="${out.res.absolute.dir}" />
        </exec>
</target>

This might give you a clue to proper solution in your case.

I think you do have to have crunch the resource of the library project.

Try

aapt crunch -v -S res -C bin/res

in your library's project folder, and rebuild. That helped for me. Now the question is how to automate that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!