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 .
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.
In android studio's build.gradle file,we can use shrinkresources set to true to shrinkify our app.Also can use minifyenabled and proguard options as well.
But in xamarin, How can I use these options?
I use proguard in my app as it referred in xamarin doc.but didn't find any use of it (I mean my app size didn't get reduced).My simple app is having around 18Mb in size.If anyone have experience using proguard in xamarin,please paste a sample file here also explain how you accomplished this.So others can also benefited.
I know you're asking specifically about the proguard and minifyenabled features of Android Studio but if the intent is specifically to reduce the size of your application, you should configure a more aggressive linking strategy.
Right click android project
Under "Build" select "Android Build" (or "iOS Build")
Select "Link All" for "Linker behavior" dropdown
Make sure this is only for Release or Ad-Hoc configurations, depending on your distribution strategy.
Linker Configuration Workflow:
Run app on a physical device for desired configuration (Release/Ad-Hoc)
Test functionality until "TypeInitializationException" or similar exception occurs
Add the type/field/method to the configuration file
Rinse and repeat until the application is stable
If you don't like the configuration file, you can also use the PreserveAttribute. If the linker is stripping out classes in one of your PCLs that don't have access to this attribute, you can define your own attribute in that PCL called PreserverAttribute because the linker is just looking for an attribute with that name, not necessary of a specific type.
The linker works by analyzing code paths and removing what it believes to be unused references. If you use dependency injection, the linker won't understand which references it needs to keep around so this can take some time but it can drastically reduce the size of your application and you only need to do it once. You can follow the same steps above for iOS as well.
Bonus Make sure "Strip native debugging symbols" is checked in the build options. Its set by default but some disgruntled coworker could have unchecked it.
Additional Resources:
Linking on iOS
Linking on Android
Proguard only can reduce an APK size if it contains a large number of unused classes (e.g. included because of libraries). Therefore it can only reduce the size of the classes.dex file in your APK.
However an APK usually contains a large number of other files - they will not be touched by Proguard.
You should open the generated APK file in a ZIP viewer and see what elements take the space. If it is the classes.dex file it is only a matter of Proguard configuration.
When I create a new android app using Android Studio and export the APK file, the resulting file is 914kb in size. I did not add any code or resources. How can I bring the size to the bare minimum.
Thanks in advance.
Update: Enabled proguard, that brought down the size to 564kb. I extracted the apk and saw there are so many drawable folders in the apk
All these folders contains PNG files with names starting with "abc_ic.." . Is there a way to exclude them?
I think you can 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.
For more details, please refer here.
You can try to remove reference's libary(seem you added android-support-v7 to your project).
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.
I have an Android project that I recently published to the market after running it through obfuscation with ProGuard.
The project exported without any complications, but how do I know it's been obfuscated? Is there anything I could do to verify that obfuscation was successful?
Look for dump.txt, mapping.txt, seeds.txt and usage.txt. They will probably be in a proguard folder at your project directory. These are created when ProGuard is run on your code.
These are filled with information about the obfuscation, especially useful is mapping.txt which shows what ProGuard turned your various member names in to.
Try to reverse engineer your own application. See what you can read in the code.
Use the following questions:
decompiling DEX into Java sourcecode
http://www.taranfx.com/decompile-reverse-engineer-android-apk
DISCALIMER: I am not the owner of decompileandroid.com and I am not paid to promote it. I am a develper, who is satisfied with this service.
There is actually an easier way than acquiring several different tools and passing the output of one of them to the other (this of course gives you a better control of what's going on). You can use the service
decompileandroid.com
Basically you upload and .apk file and it does all of these steps for you.
Then you can download a .zip file, which contains the decompiled sources.
You can first upload your .apk built in debug mode, then upload an .apk built in release mode. Just make sure that the flag minifyEnabled is set to true in your build.gradle file for the release build.
The difference was pretty obvious in my case - most of my classes were named a,b,c, etc in the minified build.