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);
}
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(.. )
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 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 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.
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).
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.