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

时间:2011-01-12 06:55:36

标签: android file-extension assets aapt gz

当我将GZIP-ed文件添加到我的Android项目的资产时,在打包项目时会剥离“.gz”扩展名。 (例如,我的资产文件夹中的“foo.gz”需要使用getAssets().open("foo")在代码中访问。)这似乎与其他扩展(例如,“。html”)无关。使用。资产仍然是GZIP-ed(我必须将输入流包装在GZIPInputStream中以读取它)。

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

编辑:我把事情搞错了。我遇到了Eclipse插件的这个问题。我没有尝试直接运行aapt以查看问题是否与工具本身或插件是如何使用它有关。

1 个答案:

答案 0 :(得分:0)

在这里我如何解决它,只需在构建钩子之前做一个cordova。 the docs

#!/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);
相关问题