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.
Related
We have several dependency libraries in our APK and have enabled proguard and multi dex. We have 3 dex files. We intend to keep the APK size as small as possible.
We are currently trying to integrate a 'new Ads SDK'.
While integrating, we are seeing an abnormal increase in the size of our APK after including the dependency library.
The memory footprint of the library is around ~280 KB in a sample app. But when we add the same dependency in our app, our apk size increases by 595 KB. Their proguard rule keeps all their classes.
On debugging with APK analyzer in android studio and classyshark, we observed that the size of other packages and classes like facebook, google, glide etc in our dex files are increasing in size.
However, their method counts remain same. This could only mean the proguard compression is being compromised. So, APK size increase is like 280 KB (ads sdk) + X [315 KB]. We are trying to eliminate the unnecessary 315 KB increase in the APK size.
Any leads on investing the cause of this abnormal increase in size would be appreciated.
Please share any dex options/proguard optimizations which might help in this scenario.
UPDATE:
The proguard rules of the SDK in question looks like this:
-keep class com.example.** { *; }
-dontwarn com.example.**
Thank you.
What i can infer from your post is most likely some of the rules added in proguard as part of new lib config causes decrease in code shrink for lib like facebook , google. It is difficult to avoid 3rd party sdk rules, however you can still shrink your apk using other approach if that is not yet adopted by your app. If your graphic resources still use PNG change them to webP it would reduce the size of apk.
Also check for common lib if present as part of ads sdk. Once we had seen two version of google play services in our app and we had to exclude the one present in sdk dependency via gradle config.
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 .
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
I'm new with Proguard and I have problem with setting up project to work with it.
Problem is, that the main code is in one library and the "final" project is some empty project used for localization strings, settings only. Where proguard should be enabled - in library or final project or both?
Structure is like this:
ActionBar,Roboguice... libs -> Main Library -> Localized Project (just resources)
Is there option to obfuscate only the main library? It will be more clear to keep one proguard files for one release of XX localized projects.
Thanks in advance for any hint!
You only need to apply ProGuard to the final project. Shrinking, optimizing, and obfuscating the library beforehand doesn't have any added benefit, unless it reduces the library's size a lot, which may reduce the total processing time if you have many final projects.
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.