I'm facing a little "problem" affecting my APK files built in Android Studio (but the same problem affects my APKs even if I build them from command prompt).
The problem is this: if I rename .apk to .zip to see the files inside, or even if I analyze the .apk with the analyzer tool included in AS, I see in the "res" directory a lot of png files that I didn't include and I don't even use in my application.
I guess that they're standard icons used in Android, but I would like to exclude them from my built apk file.
Those file names are like "abc_ic_restofthefilenamehere.png"
(example: "abc_ic_star_half_black_16dp.png")
I would like to know if there's a way to exclude those file because I don't use them in my activities (my application is very simple, it doesn't even need icons for notifications or other kinds of similar things).
Is it possible to exclude them? Is there a way to do it if I build from the command prompt too (using gradle)?
Thank you very much!
-
Check out the documentation about how to Shrink your resources. This should remove any unused resources in your app.
Note however that some images will seem unused but are actually dependencies (possibly indirect) of a theme you may be depending on, so that's why those would remain.
Related
I have seen that there are decompilers that works pretty well to show on fly code and resources of compiled APK.
I'm wondering if there is a way to edit and rebuild APK classes without export all sources and resources recreating a new project manually adding all libraries resources code etc. Since the APK already contains all the needed dependencies and resources configured to work together should be possible.
Often there are apps that have small bugs that would be easy to fix if only was possible edit and rebuild APK on fly
You can use Virtuous Ten Studio that allows you to import an APK edit smali code and resources and rebuild the edited version of the APK.
(You can also configure it to show Java code but since uses a "smali to Java" approach the generated code is imperfect.)
https://ibotpeaches.github.io/Apktool/
You can use Apktools to extract and compress APK-files
It is possible to manage/edit Smali files. They are similar to Java-files.
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'm trying out cocos2d-js (version 3.0) and even the simplest 'Hello World' project is over 1 gigabyte in size when it is created.
Is this normal? (I have a habit of creating dozens of demo-projects when trying out a new platform, but it looks like I need to get myself a bigger SSD, just for this!)
Also, the size of the apk, when compiled for Android, is about 9 MB. Any ways to reduce this size?
Sadly, yes. I've mentioned this in the community a couple of times to no avail. I believe this files should be referenced/cached in a common location for all projects, but the dev team seems to have other priorities at present.
If you wish to keep your projects you'll be better off heading to their frameworks directory and deleting all folders except cocos2d-html5 (this one should be 5MB only) in there. -
An alternative would be to also delete the cocos2d-html5 folder, place it in a common dir (or use the copy in your install folder) and reference the path properly in your projetc's config file. Keep in mind this option may break code suggesstion/autocomplete in some editors, and throw errors in your webserver when you try to run the project.-
This way, you'll be able to run any of those projects in the browser, and then only add the files neccessary for native compilation in projects you wish to test in the emulator or your device (or compile for publishing). This will sadly take a lot of time to copy and re-generate the files, of course.
As for reducing the size of the .apks... I don't know a way. I know efforts are being made to optimize the binder, and there may be a way to explicitly avoid packaging unused stuff, but I don't know about it.
You can reduce the app size in Cocos2d-js v3.2 released in January. It allows you to exclude the unused modules. Refer to the upgrade guide for more details on how to do this. The minimum apk size for Android is 4.4mb .
I am definitely a noob at understanding this as of now, I noticed usually that the apk file is much smaller than my Android Projects. How is that happening? Is it always like this? I got this doubt while I was compressing an entire project to zip file, it was showing that the disk size is 128MB...(noticed it then the first time) whereas the actual apk is only 22.4 MB. why is this difference?
An APK is an Android application package file. Each Android application is compiled and packaged in a single file that includes all of the application’s code (.dex files), resources, assets, and manifest file. The APK file is basically a .zip file
Your project contains all of your source files and files used only by the IDE. The apk only contains compiled files which are smaller.
Also, images/resources etc are compressed in the apk.
Android projects (in general) contain source code, which gets compiled to class files that end up in the APK.
Compiled files are smaller than the source code - for example they strip all the comments out of the file (you do include comments in your source files don't you!)
In addition to the other answers, you're probably using something called ProGuard which further compresses your project by shortening field names, removing dead (unused) code, merging classes, and dozens of other tricks.
Check out the FAQ for more about ProGuard.
It has to do with how Android compiles your project. It basically dumps the bulk, compresses the resources, and compiles everything into a simple binary. It will happen with almost every type of programming, your final build will usually be smaller than your total project (unless you include outside sources in your build). There is a lot of bulk in code that get's stripped during compilation.
I am trying to publish an app that is currently only configured for English. When I upload my app to the Play store, it says localization for 'Default + 49 languages'? How do I disable all but English?
I've just noticed the same issue and after some investigation found the explanation. Thought I share this in addition to the already existing answer about the consequences:
As soon as your app includes a library that does support additional languages (e.g. the Google Play Services), your created apk is marked to support all those localizations as well!
You can check the properties of an apk by the way even without uploading it to the Google Play Store. Just run the following from the latest build-tools folder inside your Android Apk. For me this is at the moment cd ~ANDROID_HOME/build-tools/19.0.1
./aapt d badging <apk>
As it was suggested before, it is mostly important in which languages your app description is provided cause this is what the users actually see. In addition one can include the list of real supported languages in this description.
If you really would want to get rid of the additional languages you would need to delete the language specific res-folders from all libraries. In case of local copies of the libraries this is easy. I guess using gradle and maven it should be possible as well, but I don't consider it worth doing at the moment.
When you publish your app, if you wrote it only in English it will be published only in English.
If you want to limit your app to specific countries you can do this: On the developer console you have a tab of "PRICING AND DISTRIBUTION". You can choose the countries there. Here how it looks:
As others have pointed out, the issue is that if you include a library that supports other languages, all of those translations get pulled into your app and then the store assumes that you support those languages.
To stop the build tools from pulling in the unsupported languages, you can set filters on the 'aapt' packaging tool so that it will ignore particular files/directories.
The formatting for the filter can be found in the main ant 'build.xml' file in the sdk. (search for aapt.ignore.assets)
The default exclude list is:
!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~
I'd recommend that you keep this list and append any extra filter to the end of it.
e.g. If you wanted to exclude es-US (which is stored in directories with the extension -es-rUS) you would change the exclude list to:
!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~:<dir>*-es-rUS
This will exclude all directories ending in -es-rUS (note that the filters are case-insensitive, so <dir>*-eS-RuS would work just as well)
To do this for the command line:
aapt.exe <All of your normal commands for packaging> --ignore-assets <exclude-list>
For Ant/Eclipse builds add the following to your project's ant.properties file:
aapt.ignore.assets=<exclude-list>