Muffinresearch Labs by Stuart Colville

Android: Force Moving Apps to an SD Card | 107 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

  • Randy

    Thanks, man. Succeeded on my first try. Now my Android is happy and has more free space. :)

  • Roman

    Thank you. Helped a lot!

  • Wiria

    Work like a charm on my new LG P698, thank you, Stuart!

  • Sophie

    I tried to do it but when I try to execute the command from my windows cmd.. It gives me an error stating “error : device not found”. I have connected my HTC desire on the “Drive Disk” mode.

  • Vishu Singh

    but it doesn’t working Ice Cream Sandwich -Xperia Neo V 

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

    Unfortunately I don’t yet have an ICS device so I can’t verify this for you.

  • kt-claire

    Didn’t work on Sony ericcson xperia?  Seemed to run but made no difference to the installed apps still stuck on my phone

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

Ubuntu: add-apt-repository: command not found|(3)

When you’re using a minimal Ubuntu install if you find the ‘add-apt-repository’ command is missing (it’s useful for adding PPAs and other repositories), then simply run:

sudo apt-get install python-software-properties

Photos on Flickr

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