Why does Android aapt remove .gz file extension of assets?

点点圈 提交于 2020-01-03 09:19:22

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/4666098/why-does-android-aapt-remove-gz-file-extension-of-assets

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