Muffinresearch Labs by Stuart Colville

Android: Force Moving Apps to an SD Card | 111 Comments

Posted in Linux/Unix, Mobile on 2nd February 2011, 7:19 pm by

Droids Skateboarding

This isn’t anything new but I thought I would share my experiences of trying to free space on my HTC desire by forcing apps to be movable to the sd card using the android SDK on linux.

WARNING: Ensure you have a backup of any important data before you start in case something goes wrong. Carrying out these instructions is at your own risk.

Running out of space is really the only annoyance I have come across since owning an android phone. Every now and again the low space icon comes up and you have to try and free up some space.

Since Froyo you’ve been able to move certain apps to SD card, but it’s only if the developer allows it. If you’re an android developer and you want to know how to do it, see this post: Enabling the Android Move To SD Card Feature

So if you’re stuck with a bunch of apps you can’t move by default because “Move to SD Card” is greyed out in “Settings -> Applications -> Manage Applications -> Appname” then you might be thinking it’s not possible. However, it is possible to change the default install location to SD card via adb.

Introducing the Android Debug Bridge

Adb is the Android Debug Bridge which comes as part of the SDK. If you don’t have the SDK the first thing you will need to do is install it (get it fromdeveloper.android.com). Once you have the SDK you can find the adb tool in <sdk>/platform-tools/, though in my case I have it at <sdk>/tools/.

Update 2012-01-26: You may find when you unpack the SDK adb isn’t there. If that’s the case you may need to run the “android” program (./android under linux) to be shown a window which provides a way to download platform-tools. once you have installed that you should find adb there.

After you’ve installed the SDK you’ll need to connect your phone to your computer using the USB data cable. You’ll also need to make sure that debugging is possible by visiting “Settings -> Applications -> Development” and checking “USB Debugging”.

Enabling moving of apps to SD card

To change the the install location we are going to run the pm command via the adb shell. Here’s the details of the pm command:

The setInstallLocation command changes the default install location
  0 [auto]: Let system decide the best location
  1 [internal]: Install on internal device storage
  2 [external]: Install on external media

To change the default install location to the SD card (which also enables moving most apps to the SD card.) run the following from the dir containing the adb command:

./adb shell pm setInstallLocation 2

If you at any point hit the following:

error: insufficient permissions for device

Try doing this:

./adb kill-server
sudo ./adb  start-server

You should now find you can run the above commands without error.

Insufficient Storage Available

The other error I had was that when I was trying to move any app after changing the default install location to the SD card was something along the lines of “Unable to move application. Insufficient Storage”.

The way I got around this was to uninstall twitter which was using about 17mb (it was the largest app). After that I re-installed it and it used far less space (naturally as the data would have been removed by the re-install process). After that I was able to successfully move most of my remaining apps (twitter included) to my SD card.

Re-setting the installation location back to auto

I’d strongly recommend re-setting the default installation location when you are done moving apps. The reason for this is that apps will fail to be installed directly to the external location, at least this is what I experienced when trying to re-install the twitter app.

To reset the install location to automatic (let the system decide) use the following:

./adb shell pm setInstallLocation 0

Should you forget where it was left at you can always run:

./adb shell pm getInstallLocation

e.g:

$ ./adb shell pm getInstallLocation
0[auto]

Post Tools

  • Pete

    I am running Windows 7.Pretty much a newbie to Android though. I am able to type ADB and it runs a bunch of stuff… but when I type adb shell…it keeps saying device not found. Again, when I use the LG Update tool…it connects no problem. It is a LG Optimus M. I just got an update not to long ago to 2.2.2. Can that be causing it. I don’t think so since it is supposed to work with even 2.3 ? Again any help would be appreciated. I am trying to free up internal memory.
    Thanks.

  • http://muffinresearch.co.uk Stuart Colville

    @Pete: and did you run adb devices? This will tell you if adb can see your phone. If you can do that and post the output it might help to solve the issue.

    Also you could check that USB storage is turned off.

  • Pete

    How do I run adb devices…sorry…on very familiar with it. I did follow the instructions to a T…and got up to the part to type the command, but got that error message. Again, please let me know how to run adb devices and I will post the output.

  • Pete

    lol…P.S. How do I check if USB storage if off ? Thanks for all you help and patience. I came along way believe it or not.

  • http://muffinresearch.co.uk Stuart Colville

    @pete: To check USB storage is off – it should say it’s connected as a drive on the phone when hooked up via USB. To check the status drag the top of the screen down to reveal the current status.

    Now to get connected under Windows 7:

    First step is to check USB debugging is enabled. On the device, go to Settings > Applications > Development and enable USB debugging.

    On windows you need to have installed USB drivers if you haven’t already – this page lists the USB drivers for most phone hardware manufacturers: http://developer.android.com/sdk/oem-usb.html

    Once you’ve downloaded the driver the install instructions are here: http://developer.android.com/sdk/win-usb.html#Win7

    Once this is done it should just be a case of opening the command window ( In the Start Menu search box area type cmd and press Enter.) Navigate to where you installed the Android SDK and then to “platform-tools” and run adb devices. If connected, you’ll see the device name listed as a “device.”

    Let me know if you get stuck at any point.

  • Pete

    Thanks Stuart for all your help. On a whim, I downloaded another version of Android SDK and IT WORKED ! SUCCESS finally !!!!! Thanks again for you great post and answering me so quickly. If you have an email list and have updates or new ideas, please add me to it. Freed up so much memory !

  • Pete

    Wait…in actuallity in only let me move two apps…is that normal. Like google maps….it won’t let me move it, facebook and a mail app it did ?

  • http://muffinresearch.co.uk Stuart Colville

    @Pete: Yes unfortunately some apps are authored in such a way that prevents moving them even with the install location updated.

    One way to work around this is to root your phone and install CyanogenMod 7 and then use something like simple2ext which allows you to format your SD card and then it can use that for applications. I’ve recently done this on my Desire because whilst you can free some space with the install location method it’s really only a stop-gap measure.

    Naturally this is all a bit more involved and is potentially more risky as you could brick your phone in the process.

  • Pete

    My phone is an LG Optimus M. It just received an update not to long ago from froyo 2.2 to 2.2.2, That I know messed everyone’s root up etc… can that be causing my problem as well. When I enter adb shell I get a $ like other post say then pm InstallLocation 2 I get another $ dollar sign that many other posts say I should get. Then just reboot my phone and voila…well like I said, most of the Bloatware is still unable to be moved ? Please help.

  • Pete

    Sorry for all the posts. It is letting move about 8-10 apps using APP2SD…but the Bloatware I am guessing that is installed my the manufacturer is just impossible to move, at least without rooting, which I had a “pro” try to root my phone and could not…was unable to downgrade back to 2.2 to attempt a root. Will have to wait til someone comes out with a new procedure. Really want Gingerbread if I can figure it out. Oh well, if you just let me know it is normal not to be able to move bloatware. From my reading, it is…and now with being able to move other apps that I couldn’t move before I am guessing that is just the case. Please confirm ?

  • http://muffinresearch.co.uk Stuart Colville

    @Pete: yes that’s correct – see my previous reply – some apps just can’t be moved with this technique.

  • Pete

    As soon as they come out with a technique to root froyo 2.2.2 or I can figure out why I can not downgrade my phone to 2.2…I will definately try rooting again. Thanks for all your help. This little fix gave me about 35MB of free space. Considering my measley old MetroPCS LG Optimus came with 200MB total, I got a decent gain. Thanks again for your help. You’ve been outstanding !

  • Drew

    I did have many problems along the way, but most of them were the same ones as the other people had. Since you answered all their questions, I had practically no problem doing this. My Xperia Play has only 200MB total for me to use, so this is wonderful. This gave me 50MB of free space, which was wonderful. Thank you so much for this!!!

  • Nicole

    Hi,
    I’m still having “permission denied” problems. My device is a Wildfire S and OS is Win 7 Pro.

  • Nicole

    Hi,
    Kindly ignore my previous comment. I’ve successfully completed it, it was just the wrong commands. Big Thank you!

  • Anne

    On my HTC Wildfire S I was able to move some apps, eg. my Swiftkey input which is great. However, it still won’t let me move Facebook or Gmail apps… I can’t root since my phone is S-ON. Do you know of any way to move those big apps to the sd card as well?

    Also, HTC and 3 have installed lots of small useless apps and widgets that I never use, do you know of any way to move these to the simcard?

    Thanks for the clear explanations!

  • http://muffinresearch.co.uk Stuart Colville

    @Anne: Unfortunately pre-installed apps generally cannot be moved (which typically includes things like Gmail/facebook etc). If this is a problem then it’s probably worth looking into rooting your phone and then possibly installing something like Cyanogenmod 7.

    I recently did this on my Desire and found the processes straight forward enough and with a EXT4 partition on a class10 SD card combined with simple2ext (cyanogenmod7 only) running out of space is a thing of the past. That said if you remotely consider rooting/reflashing *do* take care to back everything up and understand the risks inherent in these processes before you start.

  • http://andregp.com André

    Works great in my Samsung Ace. Without any errors. It allows me to move some apps to my SD card, stopping the boring message of lack space.

    Thanks.

  • Prajeesh

    Thanks a lot. Brilliant…

  • Randy

    I’ve been pleasantly surprised at how much I liked my Samsung Admire. The one downfall was the limited internal memory filling up so fast. This has been an ABSOLUTE lifesafer! You rock buddy! Thanks so much!!!!!!

  • joe

    - (set install location to sdcard on source device)
    adb shell pm setInstallLocation 2

    - (download app from Market on source device)

    - (pull app off sdcard)
    adb pull /mnt/asec/com.app.blah
    pull: building file list…
    pull: /mnt/asec/com.app.blah/pkg.apk -> ./pkg.apk
    1 file pulled. 0 files skipped.
    3220 KB/s (1983084 bytes in 0.601s)

    - (hookup target device and install)
    adb install pkg.apk

  • Ahmed

    Hi all i have a problem when i open the adb it open very quickly and the close automatically so any one can help me
    thanks

  • SINEKT

    LG Optimus One P500 – works.

    Had a little trouble finding the USB drivers though, THE ONES IN THE SDK WILL NOT WORK !!! But I found them easily on Google.

    Didn’t help me as much though, yes, you can move many more apps on the SD, but some don’t work on SD, such as widgets and task killers… so it’s one thing to move them on external storage and a whole other thing to make them WORK on SD. :) )

  • Tiago (Brazil)

    I just type de command to set location on SD Card, and work fine. Now i can move may apps to sd using app manager on my Android 2.3.4.
    Phone: Samsung Galaxy ACE.

    Thanks a lot.

  • arvin

    hi stuart

    will it work on windows? thanks in advance.

  • vikas

    it works..but after moving apps to SD card still it acquires phone memory…
    i installed ninja game of size 8mb than i moved it in SD card but my phone memory also reduced to 12mb from 20 mb..every apps i download it is installed in both sd card and phone..
    any solution for it??

    my cell is GALAXY pop mini

  • noah

    i own a mac and whenever i try the command “./adb shell pm setInstallLocation 2″ it says “-bash: ./abd: no such file or directory found…help please?

  • noah

    *edit* everything is working fine, but when I type the command adb shell pm setInstallLocation 2 it says its an unknown command…

  • emperornayan

    Hi,
    For people facing issues with no directory found, or no such commands using this code
    ./adb shell pm setInstallLocation 2
    Is not working because IMHO in the recent updated sdk the adb location has been changed and hence try using this
    adb shell pm setInstallLocation 2
    Hope this solves the problem.

  • phpfreak

    Thanks for the tips. It works on my Samsung Prevail. I haven’t try it on Samsung Galaxy Player 5.0 yet but I will later on. I need to get a bigger storage like (32GB) from a nearest store. I couldn’t wait, even though I supposed to receive a mail package from Amazon supposedly tomorrow.

    After the mod on the default installation (0:auto) to 2:external, most of my apps are ready to be moved. I double check with different apps like SDMove, App2SD Free, and our default Android Application–>Manage applications,

    If you’re using appSaver it will say “These Apps can’t be moved to SDcard”.. However, actually it will once you double tap on any app listed.. lol.. Thanks! Now I am worry free of the tiny 161.18 MB internal system storage partitioned on my Prevail. Hopefully it will work on m 2 GB internal system on my Samsung Galaxy Player 5.0 too.

  • phpfreak

    I forgot to mention this, I am still using Froyo.. 2.2.

    The applications that couldn’t be moved is as listed under SDMove:
    1.Layar
    2.Link2SD
    3.MinaSoftIME
    4.Poynt
    5.SCVNGR”
    6.Twidroyd

    listed under App 2 SD Free
    1. Market
    2. YouTube
    3. Link2SD
    4. Street View
    5. MinaSoftIME

  • Vishal

    Hi, very interesting post, very helpful, I own Htc wildfire S, do I have to put S-off to root the phone, if yes please tell how… Or shud sell off wildfire S & buy sensation or S2 …. I am scared to brick my phone …..

    How do I subscribe to this post?

  • Vishal

    Hi, very interesting topic found thru google. Stuart I really appreciate your & other fellow member’s comments.

    I am looking forward to a reply if anybody can guide me to turn the S-Off on Htc wildfire S the easy way, I am looking forward to root my phone.

    I am scared to brick my phone, should I leave it d way it is n sell off n buy a sensation or S2 …. I really like my wildfire S…

    Awaiting comments…

  • http://muffinresearch.co.uk Stuart Colville

    @Vishal: There’s a comments feed for this post here: http://muffinresearch.co.uk/archives/2011/02/02/android-force-moving-apps-to-an-sd-card/feed/ You can subscribe to that in any feed reader such as Google Reader.

    To force moving android apps to the sdcard you don’t need root. However, if you find the limitations are too restrictive then you can use something like unrevoked (just google it) to unlock your wildfire. If you are at all worried about it after reading the instructions then I’d suggest not doing it. It goes without saying really that rooting your phone is risky and should be carried out if you understand the risks you are taking.

  • fivekitten

    After reading through all the comments, I think I just want to point out two things to people going through this process. 1. If your “adb” command isn’t working, you might need to execute it from a different folder. 2. If adb is working and you’re getting device not found, it could be a usb driver issue even if your usb driver has worked before. My USB driver was up to date, all the debugging, etc., was checked off appropriately, but it needed a different driver to work with Android. Windows would not find it through their search, a google search and manual update through device manager worked.

    Personally, I am now stuck on the install location command not working. Thinking like you said, things may have moved.

    Thank you for posting the commands so clearly above!

    On to more googling…

  • http://muffinresearch.co.uk Stuart Colville

    @fivekitten: This post was originally written with linux users in mind however if you’re using windows you can drop the “./” and use “adb ” and the command should work. The “./” is a linux idiom.

  • wisdom

    Thanks a lot Mr for your useful tutorial :) , I have a question:
    I’ve installed the package specified for linux -using ubuntu- but when it’s extracted I can’t find “adb” file in tools nor in platforms :’(…..is it possible because JDK not installed or something missed ??

  • http://muffinresearch.co.uk Stuart Colville

    @wisdom: Currently if you download and extract the sdk you’ll need to run ./android which will open a window with an option to download platform-tools. Once you’ve downloaded and installed that you should find adb there.

  • wisdom

    Great….that’s done perfectly with “Galaxy mini” :D , but still something confuses me ! even I moved all apps to SD card the internal storage deceased just about 30 MB !! how is it eaten ?!!

  • http://muffinresearch.co.uk Stuart Colville

    @wisdom: This method helps, but cannot move everything to the SD card. This is a known limitation. If you really want to fully utilise the SD card for apps then there are other alternatives out there but you’ll need to root your phone.

    In the end I found the technique detailed in this post helped initially with preventing the out of space messages on my htc desire. However it only put off the inevitable.

    I have since rooted my phone and installed Cyanogenmod along with a 16GB Class 10 SD card utilising simple2ext. Now I have bags of space and performance is fine. However clearly carrying out these steps does not come without risks.

  • wisdom

    sorry for many questions but I don’t know how to thank you for your help :) , Now I get a lot of free internal memory by factory reset my phone then do instructions above to install apps on SD card….my last question is : is it kind of risk if I left default apps installation on SD card ?? I did that and re-install all my apps without any wrong error !

  • http://muffinresearch.co.uk Stuart Colville

    @wisdom: Not sure is the honest answer. Off the top of my head I doubt you’ll see a problem – it will just use up some SD card space.

  • JDC

    I can connect my phone and get the adb shell but no matter what I try the adb command will only run as the shell user so I cannot execute the pm command. I can kill the server using the kill-server command but since I am connected using a Windows 7 machine I cannot use the sudo command. I try executing adb root but when I go back in the shell it is not running as root.
    This is the second phone I am executing this on and I did not have this issue before.
    Thanks

  • http://indopersica.blogspot.com Appu

    Worked like a charm on my Nexus One (Android 2.3.4). Although FB, Gmail etc. won’t move, I was still able to free up 16 MB. Thanks Stuart!

  • aashish

    Thanks , worked like a charm :)
    thanks a ton..

  • Gokul

    Hi… I got everything right…. But after i disconnected the usb my phone keeps restarting continously… Particularly after my sd card is finished reading….. So ive unmounted my sd card now…. But whenever i mount it my phone keeps restarting again…. Tell me what to do

  • http://muffinresearch.co.uk Stuart Colville

    @Gokul: I’d suggest setting the install location back as it was. If that fixes it then it suggests that’s the cause if not it may be something else.

  • Gokul

    @stuart: Thanks for replying but that didn’t work….. I changed it back but it still keeps on restarting…. I have a back up of my apps that i took sometime ago… so i replaced my current .android-secure file with my back up and it worked… but i had to reinstall my other apps… But then again the problem started!! Any ideas?

  • roadrunnerm

    Hi,

    I have Use ADB and my tablet will connect
    I go to the adb shell and typed pm setInstallLocation 2
    After this I reboot and check the setInstallLocation it is set to 2 that is right

    I have only one problem I have no button (next to Delete data) to move the apps to External SD-Card below setting >> Apps

    Is there someone out there that can tell how to get this button

  • Pingback: Two years in, the HTC desire is still a great phone - Roy Tanck's weblog

Insert a tab character in vim when expand tabs is on|(0)

I have vim set-up to use spaces in place of tabs. Sometimes you need to use an actual tab e.g. editing a Makefile. Now whilst it’s possible to change settings so that tabs are used for specific files, a quick tip to remember is to simply type in insert mode:

Ctrl+v tab

That is Ctrl and “V” and hit the tab key, et voila you’ve entered an actual tab.

GNU screen: open tab in current working directory|(1)

A nice trick for having screen open a new tab in the same directory as the one you’re currently in. To use it add it to your .screenrc

# Open new window in current dir.
bind c stuff "screen -X chdir \$PWD;screen^M"
bind ^c stuff "screen -X chdir \$PWD;screen^M"

Hat tip: mteckert on SuperUser.com

Photos on Flickr

© Copyright 2004-13 Stuart Colville, all rights reserved. May contain traces of Muffin. Powered by WordPress. Hosting by Slicehost.com This page was baked in 0.618s.