Installation error- INSTALL_FAILED_MEDIA_UNAVAILABLE导致error unknown command "setInstallLocation"解决方案

现象

项目组一台测试机被测试组的孩子借过去还回来以后,安装应用出现了Installation error: INSTALL_FAILED_MEDIA_UNAVAILABLE这个错误

问题具体情况类似
http://blog.csdn.net/qhs1573/article/details/8201380

用eclipse编译程序,然后在android手机上运行,报错如下:

[2012-06-21 12:56:17 - xmobile17] Installation error: INSTALL_FAILED_MEDIA_UNAVAILABLE

[2012-06-21 12:56:17 - xmobile17] Please check logcat output for more details.

[2012-06-21 12:56:18 - xmobile17] Launch canceled!

使用logcat查看log,显示错误如下:

NOTE: attach of thread 'Binder Thread #3' failed

原因

原因是某些应用程序(如360、91手机助手)造成手机无法在SD卡上安装程序

解决方案

作者给出来的解决方案

卸载这些垃圾软件,或者使用adb shell让手机自己选择安装在哪里,命令如下:

adb shell

pm setInstallLocation 0

PS.不同的setInstallLocation说明:

pm setInstallLocation 0 由App自行决定软件能否安装在SD卡

pm setInstallLocation 1 强制全部App安装在ROM内

pm setInstallLocation 2 强制全部App安装在SD卡

PS:如果是手机连接PC的模式,选择了存储模式,导致找不到存储卡,也会报此错误

很遗憾,执行pm setInstallLocation 0的时候出现问题了’Error: unknown command ‘setInstallLocation’’

C:\Users\Administrator>adb shell pm setInstallLocation 0
Error: unknown command 'setInstallLocation'
usage: pm list packages [-f] [-d] [-e] [-s] [-3] [-i] [-u] [--user USER_ID] [FIL
TER]
       pm list permission-groups
       pm list permissions [-g] [-f] [-d] [-u] [GROUP]
       pm list instrumentation [-f] [TARGET-PACKAGE]
       pm list features
       pm list libraries
       pm list users
       pm path PACKAGE
       pm dump PACKAGE
       pm install [-l] [-r] [-t] [-i INSTALLER_PACKAGE_NAME] [-s] [-f]
                  [--algo <algorithm name> --key <key -in-hex> --iv <iv -in-hex>]
                  [--originating-uri <uri>] [--referrer </uri><uri>] PATH
       pm uninstall [-k] PACKAGE
       pm clear [--user USER_ID] PACKAGE
       pm enable [--user USER_ID] PACKAGE_OR_COMPONENT
       pm disable [--user USER_ID] PACKAGE_OR_COMPONENT
       pm disable-user [--user USER_ID] PACKAGE_OR_COMPONENT
       pm disable-until-used [--user USER_ID] PACKAGE_OR_COMPONENT
       pm block [--user USER_ID] PACKAGE_OR_COMPONENT
       pm unblock [--user USER_ID] PACKAGE_OR_COMPONENT
       pm grant PACKAGE PERMISSION
       pm revoke PACKAGE PERMISSION
       pm set-install-location [0/auto] [1/internal] [2/external]
       pm get-install-location
       pm set-permission-enforced PERMISSION [true|false]
       pm trim-caches DESIRED_FREE_SPACE
       pm create-user USER_NAME
       pm remove-user USER_ID
       pm get-max-users

pm list packages: prints all packages, optionally only
  those whose package name contains the text in FILTER.  Options:
    -f: see their associated file.
    -d: filter to only show disbled packages.
    -e: filter to only show enabled packages.
    -s: filter to only show system packages.
    -3: filter to only show third party packages.
    -i: see the installer for the packages.
    -u: also include uninstalled packages.

pm list permission-groups: prints all known permission groups.

pm list permissions: prints all known permissions, optionally only
  those in GROUP.  Options:
    -g: organize by group.
    -f: print all information.
    -s: short summary.
    -d: only list dangerous permissions.
    -u: list only the permissions users will see.

pm list instrumentation: use to list all test packages; optionally
  supply <target -PACKAGE> to list the test packages for a particular
  application.  Options:
    -f: list the .apk file for the test package.

pm list features: prints all features of the system.

pm list users: prints all users on the system.

pm path: print the path to the .apk of the given PACKAGE.

pm dump: print system state associated w ith the given PACKAGE.

pm install: installs a package to the system.  Options:
    -l: install the package with FORWARD_LOCK.
    -r: reinstall an exisiting app, keeping its data.
    -t: allow test .apks to be installed.
    -i: specify the installer package name.
    -s: install package on sdcard.
    -f: install package on internal flash.
    -d: allow version code downgrade.

pm uninstall: removes a package from the system. Options:
    -k: keep the data and cache directories around after package removal.

pm clear: deletes all data associated with a package.

pm enable, disable, disable-user, disable-until-used: these commands
  change the enabled state of a given package or component (written
  as "package/class").

pm grant, revoke: these commands either grant or revoke permissions
  to applications.  Only optional permissions the application has
  declared can be granted or revoked.

pm get-install-location: returns the current install location.
    0 [auto]: Let system decide the best location
    1 [internal]: Install on internal device storage
    2 [external]: Install on external media

pm set-install-location: changes the default install location.
  NOTE: this is only intended for debugging; using this can cause
  applications to break and other undersireable behavior.
    0 [auto]: Let system decide the best location
    1 [internal]: Install on internal device storage
    2 [external]: Install on external media

pm trim-caches: trim cache files to reach the given free space.

pm create-user: create a new user with the given USER_NAME,
  printing the new user identifier of the user.

pm remove-user: remove the user with the given USER_IDENTIFIER,
  deleting all data associated with that user

字面意思看,命令用错了,从一大堆提示信息中可以找到

pm set-install-location [0/auto] [1/internal] [2/external]

so,问题解决了,谷歌在升级过程中又偷偷改名字了,pm setInstallLocation 0改成pm set-install-location 0,问题就解决了。

文章目录
  1. 1. 现象
  2. 2. 原因
  3. 3. 解决方案