使用ProGuard时,从资产解压不起作用 [英] Unzip from assets doesn't work when using proguard
问题描述
我存储在apk的资产,这在第一次运行时提取使用20MB的数据库。要做到这一点,我用
I have a 20MB database stored in the apk's assets, which on first run is extracted for use. To do this I use
PackageManager pm = context.getPackageManager();
String apkFile = pm.getApplicationInfo(context.getPackageName(), 0).sourceDir;
ZipFile zipFile = new ZipFile(apkFile);
ZipEntry entry = zipFile.getEntry("assets/FILENAME");
myInput = zipFile.getInputStream(entry);
myOutput = new FileOutputStream(file);
byte[] buffer = new byte[1024*4];
int length;
int total = 0;
int counter = 1;
while ((length = myInput.read(buffer)) > 0) {
total += length;
counter++;
if (counter % 32 == 0) {
publishProgress(total);
}
myOutput.write(buffer, 0, length);
}
当我从月食(Android 2.2的目标)不导出使用ProGuard一切工作正常。当我使用ProGuard出口时,解压缩开始几秒钟的工作(以及一些最新进展,为8%),但随后崩溃
java.io.IOException异常在java.util.zip.InflaterInputStream.read(..)
All works fine when I export from eclipse (android 2.2 target) without using proguard. When I export with proguard, the unzip starts to work for a few seconds (and a few progress updates, to 8%), but then crashes with java.io.IOException at java.util.zip.InflaterInputStream.read(.. )
它的工作原理在模拟器,但在设备上崩溃(许多设备,但我认为始终工作在的Android 4.0,Android 2.2中崩溃)。我proguard.cfg基本上是默认的。
没有什么我试图改变似乎帮助,任何想法?
It works on the emulator, but crashes on devices (many devices, but I think always works in Android 4, crashes in Android 2.2). My proguard.cfg is basically the default one. Nothing I have tried changing seems to help, any ideas?
推荐答案
ProGuard的优化可能会发现在所处理的code错误。例如,优化可以潜在地改变多线程code的定时,造成的问题,如果它不正确同步。你可以仔细检查你的code。例如,被myInput和myOutput字段,即在其他线程操纵?该问题是确定性的?
ProGuard optimizations may uncover bugs in the code that is processed. For instance, optimizations can potentially change the timing of multi-threaded code, causing problems if it is not synchronized properly. You could double-check your code. For instance, are myInput and myOutput fields, that are manipulated in other threads? Is the problem deterministic?
ProGuard的优化还可以发现臭虫在虚拟机或运行时类。这有可能是你碰到的是已被固定在近期的Android版本的bug。
ProGuard optimizations may also uncover bugs in the virtual machine or in run-time classes. It's possible that you've run into a bug that has been fixed in recent versions of Android.
由于处理code并在最新版本的Android的工作,它可能不是在ProGuard的一个bug,但如果最新版本使得(在这个时候写的版本4.7)的差别,你可以检查。
Since the processed code does work on recent versions of Android, it's probably not a bug in ProGuard, but you could check if the latest release makes a difference (version 4.7 at this time of writing).
您可以报告的ProGuard的 bug跟踪中的问题,用一个样本这说明了这个问题(至少较完整的code和一个完整的堆栈跟踪)。在此期间,您可以通过关闭优化解决它。
You can report the problem on ProGuard's bug tracker, with a sample that illustrates the problem (at least with more complete code and a complete stack trace). In the meanwhile, you can work around it by switching off optimization.
这篇关于使用ProGuard时,从资产解压不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!