Unpacking from assets does not work when using proguard

I have a 20 MB database stored in apk assets, which are first retrieved for use. For 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); } 

Everything works fine when I export from eclipse (target of Android 2.2) without using proguard. When I export using proguard, unzip starts to work for several seconds (and several progress updates, up to 8%), but then fails with java.io.IOException in java.util.zip.InflaterInputStream.read (..)

It works on an emulator, but crashes on devices (many devices, but I think it always works on Android 4, crashing on Android 2.2). My proguard.cfg is basically the default. Nothing I tried to change seems to help, any ideas?

0
source share
1 answer

Optimization ProGuard can detect errors in the processed code. For example, optimization can potentially change the time of multi-threaded code, causing problems if it is not synchronized properly. You can double check your code. For example, the myInput and myOutput fields that are processed in other threads? Is the problem deterministic?

Optimization ProGuard can also detect errors in the virtual machine or during class execution. You may have encountered a bug fixed in the latest versions of Android.

Since the processed code actually works in the latest versions of Android, it is probably not a bug in ProGuard, but you can check if the latest version has a difference (version 4.7 at the time of writing).

You can report a problem on the ProGuard bug tracker , with a sample that illustrates the problem (at least with a more complete code and a full stack to track). At the same time, you can get around this by turning off optimization.

0
source

All Articles