Compiled APK file contains a lot of unknown (A)XML layouts - android

When I unzip the apk file, in the res\layout folder I found the following unknown xml files:
abc_action_bar_title_item.xml
abc_action_bar_up_container.xml
abc_action_menu_item_layout.xml
abc_action_menu_layout.xml
abc_action_mode_bar.xml
abc_action_mode_close_item_material.xml
abc_activity_chooser_view.xml
abc_activity_chooser_view_list_item.xml
abc_alert_dialog_button_bar_material.xml
abc_alert_dialog_material.xml
abc_alert_dialog_title_material.xml
abc_cascading_menu_item_layout.xml
abc_dialog_title_material.xml
abc_expanded_menu_layout.xml
abc_list_menu_item_checkbox.xml
abc_list_menu_item_icon.xml
abc_list_menu_item_layout.xml
abc_list_menu_item_radio.xml
abc_popup_menu_header_item_layout.xml
abc_popup_menu_item_layout.xml
abc_screen_content_include.xml
abc_screen_simple.xml
abc_screen_simple_overlay_action_mode.xml
abc_screen_toolbar.xml
abc_search_dropdown_item_icons_2line.xml
abc_search_view.xml
abc_select_dialog_material.xml
abc_tooltip.xml
notification_template_part_chronometer.xml
notification_template_part_time.xml
select_dialog_item_material.xml
select_dialog_multichoice_material.xml
select_dialog_singlechoice_material.xml
support_simple_spinner_dropdown_item.xml
None of them is my layout file. My layout xml file were there also, but all above listed are unknown to me.
Why are those files in my apk file? Do I need them there? Or is there a way to not having them in my apk file and have my apk file smaller?

Why are those files in my apk file?
You are using AppCompat, or at least added it as a dependency. There are some resources there that might be from other dependencies, but all the abc ones are from AppCompat.
Do I need them there?
If you are using AppCompat, yes. If not, no. If you are not using AppCompat, remove the dependency (and make sure nothing else that you are using needs AppCompat or otherwise pulls in AppCompat as a transitive dependency).
It is possible that some of those resources you will not need, even though you are using other aspects of AppCompat. You can look into the resource shrinking settings of a release build to see if it can identify some to remove.
Or is there a way to not having them in my apk file and have my apk file smaller?
You could not use AppCompat. In modern Android app development, that is rather difficult.

Related

How to exclude default resources from APK buld in Android Studio?

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.

How to edit a compiled Android app class from APK

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.

How to reduce the size of an APK file

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).

Android: Why is the size of apk file smaller than the entire project

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.

Preloaded Android application with .so library file cannot be upgraded

I work for an operator, and we preload applications on Android phones.
However, some preloaded applications, once upgraded from Market, crash.
The problem is this:
- the application contains a .so library file
- in order to preload the complete application on a phone, the .so library file has to be placed separately into the lib directory (/system/lib/libXXXXjni.so)
- when the preloaded application is upgraded from Market and run, instead of the .so library file in the new APK being found, the older preloaded .so file is found first - causing a crash, because the two .so fiels have differing contents
Does anyone have a suggested work-around, or knowledge of the library-searching algorthim which may help me solve this?
One possible solution might be to simply rename the library file, but is that enough?
Thanks in advance...
When you preload, try putting the applications library in:
/data/data/com.package.foobar/lib/libXXXXjni.so
Renaming the library would work. Possibly using the app's version number as the name of the .so file. The build becomes more complicated though.

Categories

Resources