2011-01-12 42 views
6

当我将一个GZIP-ed文件添加到我的Android项目的资产中时,当项目打包时,“.gz”扩展名被剥离。 (因此,例如,我的资产文件夹中的“foo.gz”需要使用getAssets().open("foo")代码进行访问。)对于我正在使用的其他扩展(例如“.html”),似乎不会发生这种情况。资产仍然是GZIP-ed(我必须将输入流包装在GZIPInputStream中才能读取它)。为什么Android aapt移除资产的.gz文件扩展名?

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

编辑:我错误地注视事情。我遇到了Eclipse插件的这个问题。我没有尝试直接运行aapt以查看问题是出在工具本身还是插件使用它的方式。

+1

Android的资产包工具(AAPT)识别。广州文件并将它们添加到该.zip而不需要重新压缩它们(即,它剥去gzip头并将它们落入在“压缩”条目zip归档文件;这是一个编译时间优化)。尽管你描述的行为听起来不同。 – fadden 2011-01-14 23:48:19

+0

剥离.gz扩展名看起来尤其程序员不友好。另外,.apk存档文件与资产文件夹中的相同位置具有任何其他名称。 – 2011-01-30 17:35:55

回答

0

这里我怎么解决它,只是做一个科尔多瓦前建钩。 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);