Proguard + zxing, My APK doesn't shrink - android

Hi I'm building an android app that uses zxing library for QR Scanning only.
I'm using zxing'S proguard file file to shrink and optimize the APK, without success.
My APK always ends up with 133 M of size.
Proguard outputs several warnings stating that some class references are missing (some of them are from rt.jar). I've get rid
of them with: -ignorewarnings
(Maybe this is the problem the APK isn't shrinking)
How can I make the APK to shrink?
Thanks in advance!

Make sure you are referencing the correct proguard file in your project.properties file using the progaurd.congif= property.

You're missing something big here then, because the entire library is nowhere near 133MB. In fact, it is 0.5MB: http://search.maven.org/#artifactdetails%7Ccom.google.zxing%7Ccore%7C3.1.0%7Cjar
The Proguard file you reference is actually the one Android creates, with a minor change to what optimizations are allowed. It's standard.
Are you somehow packaging all of the test images into your APK? That's the only way I can imagine making such a huge artifact. But that is a huge error of course.

We ended up dumping zxing and using a library that only has zxing qr code scanning functionality.
https://github.com/barmstrong/bitcoin-android
Hope this helps someone else.
Regards

Related

Shrinking the size of an apk

All the drawable and raw files have 900kbs all together in my application, but the entire size of the application is comming ouut to be 5.5 Mbs. I am working in eclipse and google play services library along with appcompact_v7 library are attached.
How can i shrink the size of my exported apk file. Because my application is way too simple to have 5.5 Mbs.
Thankyou in advance.
Use Android ProGuard tool. The ProGuard tool shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names. The result is a smaller sized .apk file that is more difficult to reverse engineer.
First, consider switching to Android Studio and using a subset of Google Play Services, for whatever part you are using. The documentation has a "Selectively compiling APIs into your executable" section that covers this.
Second, if you are examining the size of your debug build, bear in mind that release builds use ProGuard to get rid of extraneous Java code, and so your releae APK will be a bit smaller.
Beyond that, Cyril Mottier has a great blog post on "Putting Your APKs on a Diet". However, some of the more powerful techniques, such as eliminating resources from Play Services via resConfigs, require Android Studio.
There are some techniques you could achieve this:
Proguard - to remove unused classes from your final apk
"lint --check UnusedResources " - detect resources that your app has and are not being used
Use helper jar: https://code.google.com/p/android-unused-resources/
You can read this Android official doc for more info : http://tools.android.com/tech-docs/new-build-system/resource-shrinking .

Proguard and Android - no size reduction seen

I have a library project which refers two other library projects (Google Play Services and Appcompat). The referencing project has no code just resources. All the code is in this library project. I added proguard configuration for my library project hoping to reduce the size of my binary. It compiles and generates the signed apk fine using ant build. But I see no reduction in binary size. Its exactly the same size as it was without proguard. Also obfuscation occurs only for few of the classes , not all.
What am I missing? Any help is appreciated.
Figured out myself. I configured proguard for the referencing project instead of configuring it in the library. All referenced libraries were automatically taken care of and i was able to shrink the size of final apk by about 30%.
obfuscation does not occur for all classes, some classes are skipped as they need to remain (normal) mainly, the views, and other classes that need to be accessed by external components
also check Proguard config file,
you some classes might be set as skipped by mistake.

Android Proguard and Android frameworks: is there a conflict?

For the moment I am developing small Android projects to practice with the Android prorgramming. However, once on the market, I would like to obfuscate / optimise the APK thanks to ProGuard. But this tool renames classes to obfuscate the code, so:
Is it safe to use tools like Android Query to write the code?
If it is not safe, what are some framework examples that can be used safely with Pro Guard?
What could be a solution to the problem? Or should I write everything using the good old Android style and forget about a "write less, do more" approach?
How do I identify the tools that are ProGuard-safe from the ones that are not?
I assume you want to use third party libraries (jar files). You could use a 3 step approach:
If the third party jar explicitly supports Android, it will have a proguard configuration. Usually this is a snippet that you merge into your proguard-project.txt.
If there is no such explicit support, you may still try to use the jar, obfuscate and test your app. If errors occur, gradually exclude classes from obfuscation until it works. A common problem is that libraries use reflection to instantiate classes and call methods which breaks after obfuscation.
Exclude the whole library from obfuscation. This will work in any case and proguard will not touch the library at all. (The Android toolchain will still repackage the contents of the jar into your apk which might cause problems.) This will also produce the least obfuscated result and should really be your last resort.
In any case, obfuscation is not a switch that you simply toggle. You'll need to get familiar with proguard config files which involves a learning curve.

Android Proguard - Can I skip it?

I am seeing some weird crashes on my Android application when I turn on proguard obfuscation. I understand I can debug this and skip obfuscation for those classes but my question is - Is it worth the risk of having the application crash on some phone or some code path that I might not have tested/exercised. For e.g this link talks about one such device specific error due to proguard.
I am close to release and am now wondering is it worth introducing proguard at this point. I understand I should have tested with it right from the start ..made a mistake.
Usually, the common problems with Proguard is not setting the correct parameters for third party libraries.
Make sure you've followed the instructions given by the third party providers as to the additions to the proguard.cfg file.
Anyhow, to disable proguard, you can always edit your project.properties file and remove the proguard.config=proguard.cfg line

Optimize the project code

I have been working on one project which is too complex and contain very much space with so many images and Java files as well.
Somewhere I have read about the proguard which optimizes the code.
I have used it, but it's still does not have an effect on my final APK file.
It might be I have made a mistake somewhere. I have the following this like http://developer.android.com/guide/developing/tools/proguard.html.
How can I optimize my code?
You can add it to the default.properties. I've been adding manually without having a problem so far.
If you add the line:
proguard.config=proguard.cfg
As said it will only use ProGuard when exporting signed application (Android Tools => Export Signed Application)
If you start the project with the SDK before Android 2.3 the proguard.cfg file will not be created (next to default.properties as in 2.3>).
To enable automatic creation of it, just simply update to the SDK of Android 2.3 and create a new project with existing sources (which are the sources of the project you currently have).
Automagically the proguard.cfg fill will be created.
Without optimizations the compiler produces very dumb code - each command is compiled in a very straightforward manner, so that it does the intended thing.
The Debug builds have optimizations disabled by default, because without the optimizations the produced executable matches the source code in a straightforward manner.
Please refer this one
From documentation:
ProGuard is integrated into the Android build system, so you do not have to invoke it manually. ProGuard runs only when you build your application in release mode, so you do not have to deal with obfuscated code when you build your application in debug mode.

Categories

Resources