Save memory by deleting lib from apks? - Android Q&A, Help & Troubleshooting

This is a work-in-progress report. I found a cool way to save internal memory: one can delete native libraries from apks after the apks have been installed. When an apk is installed, the native libraries are put in /data/data/*/lib, and if you delete the lib from the apk file in /data/app, everything works fine. Signatures don't seem to matter here.
This is particularly useful for apps most of whose memory usage is the native libraries.
OK, I've only tried it with one app.

Ooops: Normally, the /data/data/app.name/lib directory gets deleted on reboot to match the shorn apk file.
But this can be prevented by setting /data/data/app.name/lib and /data/data/app.name/lib/* to read only (chmod 555).
In case anybody wants to try with this, here's how you can do it. Of course, you need root.
Download my Android commandline build of zip. Install it in /bin and make it executable (chmod 755 /bin/zip). If you don't want to or can't make /bin writeable, install it in /data/local, and then call it explicitly as /data/local/zip
In the shell, do:
Code:
su
cd /data/data/app.name
(Where of course "app.name" is the name of the app.) Make sure there is something in the lib/ folder, or you won't save any space. Make the libraries read-only:
Code:
chmod 555 lib lib/*
Then delete the libraries from the apk:
Code:
cd /data/app
zip -d app.name*.apk lib lib/*
(You can replace the first * with a -1 or -2 or the like suffix, which gets added by the installer.)
And you're done. The apk is now thinner, and the libraries are still usable as they've already been extracted to /data/data/app.name/lib
If your app was moved to SD using Froyo (or higher?), you will need to do something a little more complicated. After you've made the libraries read-only, you'll need to remount the app directory read-write, and then zip:
Code:
mount -o rw,remount /mnt/asec/app.name*
cd /mnt/asec/app.name*
zip -d pkg.apk lib lib/*
Run the app, then reboot to see if it still works. If not, uninstall and reinstall the app.
You can save pretty serious amounts of memory this way. The libs in some graphics-intensive apps, like games, are most of the apk. I've seen apks that shrink from about 2mb to about 200k or from about 7mb to about 2mb after this procedure. Particularly bloated are apps that include two different versions of the libraries, for different CPUs.
A happy thing is that you can still move the shorn app to SD (at least with my Force2SD--I haven't tried with the OS's own function).
Interestingly, the uninstaller can still delete the app, despite the procedure, which is nice. I don't yet know what happens when you try to upgrade after this.
It would be easy to write an app that does this, or to integrate it into Force2SD. I am not sure I am going to bother.
For further savings, you can remount your sdcard as exec (I have a utility that does that if anybody is interested), move the library from /data/data/app.name/lib to your sdcard and then link to that. I have a script that automates that procedure. I've done it for a few apps that have large libraries (Angry Birds is a nice example).

Another update: This actually works very reliably. I've deleted the libraries from a bunch of apks using the above method, and things continue to work just fine.

is there an app or a script that can do this?
it is really painfull to do this with +100 apps :silly:

What happens when I update the app using play store. Is it works ?
And if it is working, does it download more data than usual to get an upgrade?
Sent from my HTC Desire X using XDA Free mobile app

ashifashraf5 said:
What happens when I update the app using play store. Is it works ?
And if it is working, does it download more data than usual to get an upgrade?
Sent from my HTC Desire X using XDA Free mobile app
Click to expand...
Click to collapse
When you update, this would need to be done again.
I have no idea if this still works on current Android versions anyway.

@arpruss
I'm doing this to my system apps currently. I use an zip explorer and just move the lib files needed to system/lib and deletes the lib folders from Apk. There is no problem of clearing of lib files at start up for this thogh. I Set the permissions to read write.
Sent from my HTC Desire X using XDA Free mobile app
---------- Post added at 05:21 PM ---------- Previous post was at 05:18 PM ----------
I like to know if the updates download more data than the normal case. What I mean is , when we updates app by play store it only download a portion of files. I like to know if this is affected by removing lib files
Sent from my HTC Desire X using XDA Free mobile app

ashifashraf5 said:
@arpruss
I'm doing this to my system apps currently. I use an zip explorer and just move the lib files needed to system/lib and deletes the lib folders from Apk. There is no problem of clearing of lib files at start up for this thogh. I Set the permissions to read write.
Click to expand...
Click to collapse
If you move the lib files to system/lib, the apps won't upgrade properly.
I have some more observations:
- On 2.3, the /data/data/*/lib directory gets cleared on reboot if the apk has had its libraries deleted. It doesn't matter what the permissions on the libraries are.
- On 4.3 and 4.4, things work great, and you don't need to change permissions at all. (I don't have rooted 4.0-4.2 devices for testing.)
- Many apps from the Amazon Appstore have a security check that makes them fail if the apk is modified.
- Moving the library-shorn apk to SD causes the libraries to disappear. I don't think the permissions matter here (but haven't tested).
It would be nice to have data from rooted 4.0, 4.1 and 4.2 devices. I guess I could play around with an emulator.
I am thinking of integrating this functionality into my Force2SD app. I would probably make this functionality available in the free version.

Anyone has tried this with 4.0 ?

benibela said:
Anyone has tried this with 4.0 ?
Click to expand...
Click to collapse
I think I tried something like this with 4.3 or 4.4 and it worked.

Yes, you said that already.
But I need to know it for 4.0.4. My stupid bank has a must-use-app for online banking with 20 MB libs that are only there to prevent it from running on a rooted device. And if it detects a modification, it self-destructs.
Nevermind. I tried it with my own app and it worked. With permission change, did not try without

I have Android 8.1.0, Xiaomi Redmi 5 Plus.
I am modifying the files in "lib" directories (such as /data/data/com.application.name/lib/) of few specified applications.
Rarely the files from the "lib" directory get overwritten with the content from APK archive of these applications. The "lib" gets restored from APK archive sometimes (maybe after 2 weeks or so).
It's important for my project to learn about the problem of Android restoring the "lib" directory.
I would like see what part of Android is responsible for this. I want to know which script or executable file in Android is responsible for restoration of "lib" directory.
Hopefully someone out there knows something about it.

i found a better way to remove lib folder from apk to get more free space https://forum.xda-developers.com/android/general/guide-t4080131

Related

ok some help understnading apk files

please help this windows guy/android noob figure this out. ok i'm thinking an apk file is equivalent to an msi file.
i download an app from the android store...
it downloads as apk file to /data/app...
ok so is that the final home for the apk file or does this extract and "install" files and folder in other locations on the internal memory or sdcard?
does the app run from this location? when uninstalled, is it removed entirely or are there orphan files that can be left behind? where is the data associated with that app saved? same folder /data/app/?
when titantium backs up an app, does it just copy the apk files from /data/app?
thanks
mark
http://en.wikipedia.org/wiki/APK_(file_format)
thanks, i already saw your link. doesn't really address my questions though. and yeah i do google questions prior to posting.
markkal123 said:
please help this windows guy/android noob figure this out. ok i'm thinking an apk file is equivalent to an msi file.
i download an app from the android store...
it downloads as apk file to /data/app...
ok so is that the final home for the apk file or does this extract and "install" files and folder in other locations on the internal memory or sdcard?
does the app run from this location? when uninstalled, is it removed entirely or are there orphan files that can be left behind? where is the data associated with that app saved? same folder /data/app/?
when titantium backs up an app, does it just copy the apk files from /data/app?
thanks
mark
Click to expand...
Click to collapse
I was in a hurry when I posted the link and that was the best I could do at the time.
apk is more like a java jar file (in fact you can sign your apk with jarsigner in java) or self extracting zip. Don't quote me on it, but you need both the files in /data/app and /data/data to run the application. Some gets left inside the container, and files that get modified a lot are extracted to /data/data (along with data that personalizes the app for you, such as settings and profiles).
The xml manifest file in the apk tells it what permissions to ask for and what systems it can run on and such. If you get this http://code.google.com/p/android-apktool/ you can reverse the apk so you can make sense of the files inside of it.
Titanium backup takes both the app and the data and stores them on the sdcard (unless you only tell it to backup the app, then it only takes from /data/app). The files located under /data/app are the entire application itself though and that will run if you give it to someone else as if you downloaded it from the market.
thanks for the great response.

where to place apps in custom rom

Hello Guys,
I am trying to make/edit my first custom rom (forgive my noob mistakes). As base i am using the Oxygen rom. This rom has all his apps stored in system/app. I inserted an launcher(hololauncher), keyboard(custom htcime) and gallery(quickpick) apk in this folder, but after the rom is flashed these apps are causing fc's and the gallery app isnt even flashed.
I know that not every apk can be placed in the system/app folder, but how can i ensure that these apps will install correctly during flashing.
Depends on apps.
The most common mistake is forgetting to set the permissions to rw-r-r.
Also some apps need their lib files (usually end in .so) in a specific location, like quickpic that can't be turned into a system app just by putting it in system/app address.
Edit: you can ensure these apps are installed correctly by testing.
1 install them normally and convert them to system apps.
2 write down where each of their parts end up (some will always need stuff in data/app or something similar.
4 use a root explorer or adb to copy those files to your pc.
5 modify the flashable zip. Add the files you just copied and modify the updater-script to make sure those files get flashed to the correct location (you might need to include mount data commands if any of the files flash to data/)
6 test!
Some apps might require actual edition by decompiling them, but the above should work for most.
dxppxd said:
Depends on apps.
The most common mistake is forgetting to set the permissions to rw-r-r.
Also some apps need their lib files (usually end in .so) in a specific location, like quickpic that can't be turned into a system app just by putting it in system/app address.
Edit: you can ensure these apps are installed correctly by testing.
1 install them normally and convert them to system apps.
2 write down where each of their parts end up (some will always need stuff in data/app or something similar.
4 use a root explorer or adb to copy those files to your pc.
5 modify the flashable zip. Add the files you just copied and modify the updater-script to make sure those files get flashed to the correct location (you might need to include mount data commands if any of the files flash to data/)
6 test!
Some apps might require actual edition by decompiling them, but the above should work for most.
Click to expand...
Click to collapse
How can I convert it to a system app when it already is installed normally ?
I also saw the option to make a data/app folder, isn't that easier ?
(Take in consideration that I don't use kitchen or adb tools, just winrar and notepadcc )
Sent from my HTC Desire using xda app-developers app
Not talking about adb and kitchen.
there are many app managing apps out there (titanium backup, link2sd) that can convert apps to system apps.
The updater script is in META-INF of the flashable zip (can be edited with notepad).
You only need a rooted device to see where the apps keep their data and copy those files.
dxppxd said:
Not talking about adb and kitchen.
there are many app managing apps out there (titanium backup, link2sd) that can convert apps to system apps.
The updater script is in META-INF of the flashable zip (can be edited with notepad).
You only need a rooted device to see where the apps keep their data and copy those files.
Click to expand...
Click to collapse
Ok that is clear, thanks. What do you think about data/app. Will this work ?
Sent from my HTC Desire using xda app-developers app
winesh said:
Ok that is clear, thanks. What do you think about data/app. Will this work ?
Sent from my HTC Desire using xda app-developers app
Click to expand...
Click to collapse
Yeah, flashing to data app is an option, but if a data wipe or factory reset is applied after flashing the rom (to correct a bootloop for example), those apps are gone.

[Q] FC using keyboard when pushed to system

Hey there, I have an xperia S running rooted stock 4.1.2 jellybean, and I'd like to install a keyboard from the playstore as a system application. The keyboard works fine when installed from the playstore, but when I push it to system (and set the permissions properly) it just force closes and does not work at all.
I've pushed various other apps from the playstore into system and they have worked without fault. Is there something finicky with installing keyboards from the playstore as system applications?
Any help would be appreciated, thanks.
open the apk and copy all lib files to your system lib and reboot,done.
-CALIBAN666- said:
open the apk and copy all lib files to your system lib and reboot,done.
Click to expand...
Click to collapse
Hey, thanks for the answer. I actually have no idea how to grab all the libraries from an apk. Any chance you could give me a rundown on how to do it?
So I realise now that "opening" the apk is as simple as changing the extension to zip and opening it like a normal archive. The apk does not contain and libraries, however. Is there any other way to get it to work?

problems after Pushing user apps into system apps

Hi every one.
I am new here. So I'm writing with all the details I can think of.
I'm using HTC desire x jelly bean in India. I've temp rooted the device. Now I run with a twrp touch screen edition revovery. I run the stock version (with odex) Rom. The only changes I made is removal of some bloatware.
The main reason I've rooted my device is to save space by pushing non movable and frequently used apps to system/app .
Since I only have temp root, The way I'm making user apps as system app is as follows
1. creating a backup Apk file either by manually copying from data/app or by clean master.
2 uninstall the app.
3 after entering the twrp recovery, I move the Apk files to system/app ( I don't create any odex files for the moved app)
4 reboot after wiping dalvik & cache.
Its a working method. But my problem is that several apps both that I frequently uses and high size are cannot converted into system apps. After making such apps as system apps, when I try to open them it force closes, crashes, or misbehaving (eg. Shows No internet connectivity even if I'm connected to web). I tried odexing the user Apk. But it not seems to be the problem. I like to know
1 why is this happening.
2 can I identify such apps before moving it to the /system/app
3 how/can I solve this isue ( I don't own a pc).
4 I am writing a list of apps that I've already tried and failed to convert as system apps. If there is no general methods can you suggest methods for the following apps
Quick pick
Mx player
BS player
Chrome
Adobe reader
Google plus
Opera mini
Opera
Google Maps
RAR
Mozilla Firefox
Freecharge
Advance download manager
Google search
Dolphin browser Jetpack
Chess free
Thanks in advance.
Sent from my HTC Desire X using XDA Free mobile app
Probably those apps have and lib files
e.x
1.With root explorer hit a app and open it in view mode
2.Navigate to lib/armeabi..xxx
3.You will find lib(xxx.so) files
4.Extract them
5.Move those files to system/lib/and set them with rw-r--r-- permissions
6.Move and the app to system app with same permissions
7.Reboot
Sorry for my English..
Superuser_ said:
Probably those apps have and lib files
e.x
1.With root explorer hit a app and open it in view mode
2.Navigate to lib/armeabi..xxx
3.You will find lib(xxx.so) files
4.Extract them
5.Move those files to system/lib/and set them with rw-r--r-- permissions
6.Move and the app to system app with same permissions
7.Reboot
Sorry for my English..
Click to expand...
Click to collapse
Thank you very much for your answer. I was searching it for a very long time. It worked like a magic with my Google play services. Before moving the lib files apps like gmail, inbox by gmail, hangouts were showing "unknown problem with Google play". I couldn't afford the space for an non movable app with about 27 mb staying in my app storage.
I was really having a trouble for the same question in following thread.
http://forum.xda-developers.com/showthread.php?t=2956631
That is why I created this thread.
Sent from my HTC Desire X using XDA Free mobile app
@Superuser_
Can you please give me more advice or thread links regarding this subject.
Sent from my HTC Desire X using XDA Free mobile app
Tried with bs player too. Its really working. :thumbup:
Sent from my HTC Desire X using XDA Free mobile app
OMG the lib files of new Google chrome is about 38 MB.
Sent from my HTC Desire X using XDA Free mobile app
Let's make a lesson...
I don't know with witch method has du move apps in system before and first you must check in system/app folder if have you double apps.
ex.
when you move an update of YouTube.apk, the name of updated app must have exactly the same name of default system app to overwrite it.
check and delete the oldest apks.
when you install a app from play store, that app creates a data folder,a dalvik cache file and perhaps a sdcard folder or a sdcard/android/data/xxx.xxx folder
when you uninstall a app from play store,the app has a script where automatically delete any created file.
when you delete a system app do must manually delete those files.Those files are in:
/data/data /the app data folder
and
/data/cache/dalvik cache or /data/dalvik cache
You can do all this only with root explorer or with one root file manager
the installed apps from play store you can find them in:
/data/app
You can see witch apps are in internal memory installed and you can copy from there...
always check first if the app works without lib files and if not,then move and those libs files
edit:
The play store and Google services apks are updated automatically without your permission and you can see that only in installed apps
All these sounds tricky but with a little practice you will become expert
@Superuser_
When new updates releases should I delete the lib files I just copied along with the app and replace it with the new updated apk's lib file.
Or the lib files I copied for older version works for new versions too?
Sent from my HTC Desire X using XDA Free mobile app
The old copied lib files wil not work in a new version
you must again copy those files and when you paste them will automatically overwrite the old ones
don't forget each time to change the permissions
The thing is I'm temp rooted. (htc desire x). And I use touch version of twrp recovery for jelly bean. I do all the things we were discussing with my recovery. And I assume chmod_66 or something like that is the command to set the read write permission. But I think whenever I copy apps or lib files to system using my recovery it's permission is read write by default. I assume this because I never faced a single problem for not setting any permission. I am not sure about it though. And will you please tell me what is the fix permission option under advanced menu in twrp recovery is used for?
@ashifashraf5
I don't have HTC DX..but a LG p700
Just visited the thread because I was looking if 4.4.4 came out for my girlfriend desire
The only thing I know is, when you are root you are root
Temporary root,I haven't heard before
The permissions can be changed with root explorer app.long press on a apk/permissions
Google it the:
how i can change permissions with root explorer app
@Superuser_
I was testing this method with Google maps. I found more than one subfolders in lib folder. My processor is arm v7. Is it what the armeabi-v7a stands for ?. Should I move all the .so files in lib folder or should I only move the armeabi_v7a subfolder .so files ?
I also attached a screenshot for convenience
Sent from my HTC Desire X using XDA Free mobile app
I think Google maps working in system without libs or not?
The other folders is for different processors
You must copy only the v7 files
@Superuser_
If I delete the libraries from the Apk using an explorer the size of Apk will get reduced. My doubt is , since we are copying the lib files needed , to the system/lib , if I delete the Lib Files from Apk and move it to system/app would there be any problem?
I mean
1. Will the app work properly ?
2. Will there be any difficulty for updating such modified apps through Google play
Sorry for the constant questions. And thanks for helping
Sent from my HTC Desire X using XDA Free mobile app
I've never tried..
try it
work great. lg g2.
Choose armeabi-v7a
Ai type keyboard.
Thank you Superuser! Great. Thank you ashifashraf5 for this question.

Odex file compilation - Android N/7

I'm playing around with installing apps to the system partition before first boot, using a generic installer zip(by Andybones). All I'm doing is taking the apps from /data/app and renaming their directories to something more readable, then installing them to /system/app using the installer zip and setting permissions. I've noticed that some ROMs include odex files in their system partitions, to save time on first boot.
I assume I can just transfer the odex files over with the apk's, but I remember reading that the reason apps install so much faster in Android N is that the apps are no longer fully compiled during the install, but instead do that in the background over time.
Does anyone know if this refers to the odex files? I just don't want to copy over a bunch of odex files if they're incomplete. Any help or advice would be greatly appreciated! =D

Categories

Resources