【问题标题】:Why does Android aapt remove .gz file extension of assets?为什么 Android aapt 会删除资产的 .gz 文件扩展名?
【发布时间】:2011-06-07 15:45:08
【问题描述】:

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

这是标准行为还是错误?如果它是标准的,是否有任何关于哪些扩展被剥离和哪些被保留的文档?

编辑:我很明显地误报了事情。我在使用 Eclipse 插件时遇到了这个问题。我没有尝试直接运行 aapt 来查看问题是出在工具本身还是出在插件的使用方式上。

【问题讨论】:

  • Android 资产包工具 (aapt) 识别 .gz 文件并将它们添加到 .zip 中而不重新压缩它们(即,它剥离 gzip 标头并将它们放入“压缩”条目中zip 存档;这是构建时间优化)。不过,您描述的行为听起来不同。
  • 剥离 .gz 扩展名似乎对程序员特别不友好。此外,.apk 存档文件在 assets 文件夹中的位置与其他名称相同。
  • 这似乎是在 aapt 中故意的(仅基于文件名),也许这个想法是,如果它被 gzip 压缩了......然后嗯混淆了人们? google.com/codesearch#uX1GffpyOZk/tools/aapt/…
  • 出于某种奇怪的原因,在我的情况下 .gz 文件的扩展名被剥离,但不需要GZIPInputStream 来读取它们,只需简单的输入流。另一方面,如果我将 .gz 文件重命名为 .dat - 我必须使用 GZIPInputStream 来解压缩它们。
  • 这里是相关 AAPT 源代码行的工作链接:androidxref.com/4.4.4_r1/xref/frameworks/base/tools/aapt/…

标签: android file-extension assets aapt gzip


【解决方案1】:

这里我如何解决它,只是在构建钩子之前做一个科尔多瓦。 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);

【讨论】:

  • 如果我错了,请纠正我,但这看起来只是删除了所有以 .gz 结尾的文件。我为什么要这样做?
猜你喜欢
  • 1970-01-01
  • 2021-01-20
  • 1970-01-01
  • 2012-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-19
  • 2012-06-29
相关资源
最近更新 更多