为什么 Android aapt 会删除 asset 的 .gz 文件扩展名?

发布于 2024-10-11 17:29:43 字数 358 浏览 5 评论 0原文

当我将 GZIP 压缩文件添加到 Android 项目的资产中时,打包项目时“.gz”扩展名将被删除。 (因此,例如,我的资产文件夹中的“foo.gz”需要使用 getAssets().open("foo") 在代码中访问。)这似乎不会发生在其他情况下我正在使用的扩展名(例如“.html”)。该资源仍然是 GZIP 编码的(我必须将输入流包装在 GZIPInputStream 中才能读取它)。

这是标准行为还是错误?如果它是标准的,是否有任何关于删除哪些扩展以及保留哪些扩展的文档?

编辑:我明显错误地陈述了事情。我在使用 Eclipse 插件时遇到了这个问题。我还没有尝试直接运行 aapt 来查看问题是否出在该工具本身或插件如何使用它。

When I add a GZIP-ed file to my Android project's assets, the ".gz" extension is stripped when the project is packaged. (So, for instance, "foo.gz" in my assets folder needs to be accessed in code using getAssets().open("foo").) This doesn't seem to happen with other extensions (e.g., ".html") that I'm using. The asset is still GZIP-ed (I have to wrap the input stream in a GZIPInputStream to read it).

Is this standard behavior or a bug? If it's standard, is there any documentation about which extensions are stripped and which are preserved?

EDIT: I misstated things sightly. I'm experiencing this problem with the Eclipse plug-in. I haven't tried running aapt directly to see if the problem is with the tool itself or with how the plug-in is using it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坠似风落 2024-10-18 17:29:43

这里我如何解决它,只需在构建钩子之前做一个科尔多瓦。
https://gist.github.com/josx/fc76006e6d877b17fefd

#!/usr/bin/env node

/**
 * Lets clean up some files that conflicts with aapt.
 * https://osvaldojiang.com/p/137
 * https://github.com/driftyco/ionic/issues/4584
 * http://stackoverflow.com/questions/4666098/why-does-android-aapt-remove-gz-file-extension-of-assets
 * https://forum.ionicframework.com/t/android-build-failed-ionic-cordova-unable-to-add-asset-file-file-already-in-archive/41146
 */

var glob = require('glob');
var fs = require('fs');
var path = require('path');

var deleteFilesFromFolder = function(globExp) {
  // Find files
  glob(globExp, function(err,files) {
    if (err) throw err;
    files.forEach(function(item, index,array) {
      console.log(item + " found");
    });

    // Delete files
    files.forEach(function(item, index,array) {
      fs.unlink(item, function(err) {
        if (err) throw err;
          console.log(item + " deleted");
      });
    });
  });
};

var globExp = path.resolve(__dirname, '../../www/lib') + '/**/*.gz';
deleteFilesFromFolder(globExp);

Here How i solve it, just doing a cordova before build hook.
https://gist.github.com/josx/fc76006e6d877b17fefd

#!/usr/bin/env node

/**
 * Lets clean up some files that conflicts with aapt.
 * https://osvaldojiang.com/p/137
 * https://github.com/driftyco/ionic/issues/4584
 * http://stackoverflow.com/questions/4666098/why-does-android-aapt-remove-gz-file-extension-of-assets
 * https://forum.ionicframework.com/t/android-build-failed-ionic-cordova-unable-to-add-asset-file-file-already-in-archive/41146
 */

var glob = require('glob');
var fs = require('fs');
var path = require('path');

var deleteFilesFromFolder = function(globExp) {
  // Find files
  glob(globExp, function(err,files) {
    if (err) throw err;
    files.forEach(function(item, index,array) {
      console.log(item + " found");
    });

    // Delete files
    files.forEach(function(item, index,array) {
      fs.unlink(item, function(err) {
        if (err) throw err;
          console.log(item + " deleted");
      });
    });
  });
};

var globExp = path.resolve(__dirname, '../../www/lib') + '/**/*.gz';
deleteFilesFromFolder(globExp);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文