Ant Build AAPT Crunch 正在从库资源图像中剥离 draw9 信息 [英] Ant Build AAPT Crunch is stripping draw9 information from Library resource images

查看:30
本文介绍了Ant Build AAPT Crunch 正在从库资源图像中剥离 draw9 信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用库项目的项目.图书馆项目有 draw9 (9.png) 文件,当通过 Ant 构建 apk 时,它会剥离可缩放和可填充区域的 draw9 信息.结果是该应用程序只是在不使用 draw9 信息的情况下拉伸图像.在 Android 的 build.xml

I have a project that is using a library project. The Library Project has draw9 (9.png) files and when building the apk via Ant it is stripping the draw9 info on scaleable and fillable areas. The result is that the app just stretches the images without using draw9 info. In Android's build.xml

 <target name="-package-resources" depends="-crunch">

这是调用 crunch,它更新预处理的 PNG 缓存(有人知道这个缓存在哪里吗?).

this is calling crunch, which updates the pre-processed PNG cache (anyone know where this cache is held?).

-crunch 在 aapt 中运行一个名为 crunch 的任务.但我无法找到有关论点的任何信息.它似乎是从 Res 文件夹中取出文件并将其放入 out res 文件夹(默认为 bin/res).

-crunch runs a task in aapt called crunch. But I have not been able to find any information on the arguments. It seems to be taking files from the Res folder and putting it in the out res folder (by default bin/res).

所以我什至清除了任务,这样它就不会运行紧缩,并且静止图像没有正确拉伸.然后我将其替换为直接将 png 文件复制到 out res 文件夹,但仍然存在同样的问题.我什至在这些任务之间尝试过 ant clean ,但我遇到了同样的问题.这让我相信缓存保存在项目区域之外,但在哪里?

So I even cleared the task so it would not run crunch, and still images weren't stretched properly. I then replaced it with a straight copying of the png files to the out res folder, and still same issue. I even tried ant clean in between these tasks and I got the same problem. Which leads me to believe the cache is being held outside the project area, but where?

请注意,当我使用 Eclipse 构建它时一切正常.

Note when I build it with Eclipse all is fine.

另一种对我有用的解决方案是将这些图像从库复制到主项目中,但这不是理想的解决方案.

The other solution that works for me is to copy these images from the Library into the Main Project, but it's not the ideal solution.

其他人似乎对此有问题 在 ant 构建中使用 aapt 压缩/资源打包使用来自其他项目的缓存

Someone else seems to have had issues with this crunch/resource packaging with aapt in ant build uses cache from other projects

在这个错误报告中,他们提到了缓存仅使用时间戳来检查是否更新缓存.

In this bug report they mention about the cache only using timestamps to check whether to update the cache or not.

这似乎是 aapt 的源代码,但我无法通过读取它来找到保存此缓存的位置.

This seems to be the source code for aapt, but I had trouble trying to find where this cache is held from reading it.

找出问题

对我来说,导致问题的原因是我在 Ant 中(有意地)为我的 res、src 和 bin 使用了不同的文件夹.有一个引用 project.library.res.folder.path 被填充到依赖宏中.它指向项目中的默认 res 和 bin 文件夹.所以我所做的是将它们更改为指向我的新文件夹.但在这样做时,我正在改变它们被列出的年龄.它开始将资源文件混合到我在运行 aapt 时使用的不同库项目中.当我修复订单时,它编译得很好.我也是为 project.library.bin.r.file.path 做的.

For me what was causing the problem was that I was using different folders (intentionally) in Ant for my res, src and bin. There is a refernce project.library.res.folder.path which gets filled in dependency macro. It points to the default res, and bin folders from the project. So what I did was to change them to point my new folders. But in doing that I was changing the older they were listed. It started mixing up the resource files into different library project I was using when aapt was being run. When I fixed the order it was compiling fine. I also did it for project.library.bin.r.file.path.

推荐答案

我昨天遇到了完全相同的问题.

I've had exactly the same problem yesterday.

我有一个代码库,用于使用 ant 构建不同风格的应用程序(差异包名称和一些特定资源).

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 工作正常,但在使用应用程序时 9 个补丁被损坏(如您所说,被视为 png 并被拉伸).

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

我将问题归结为 ant 中的 -crunch 任务(就像您所做的那样).

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

就我而言,我使用了两个不同的 res 文件夹,因此我从此更改了原始紧缩任务

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>

到这里

 <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>

但是这产生了提到的 9patch 人工制品(也在像 fb 这样的库中)..所以我想我会改变它来处理 resourceflavor.dir 仅当这不是一个给出正确结果的库(没有9pathc 人工制品)

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.

这篇关于Ant Build AAPT Crunch 正在从库资源图像中剥离 draw9 信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆