Android adb - 如何在不保留数据的情况下重新安装应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12483720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
adb - How to reinstall an app, without retaining the data?
提问by SatheeshJM
adb install foo.apk
When using this command, if the apk exists, I should get the error *Failure [INSTALL_FAILED_ALREADY_EXISTS]*
使用此命令时,如果 apk 存在,我应该得到错误 *Failure [INSTALL_FAILED_ALREADY_EXISTS]*
adb install -r myapp-release.apk
In this case,the existing apk will be replaced, by retaining old data according to the docs,
在这种情况下,现有的 apk 将被替换,根据文档保留旧数据,
'-r' means reinstall the app, keeping its data
“-r”表示重新安装应用程序,保留其数据
Now how do I reinstall the app, but all previous data should be erased?
现在如何重新安装应用程序,但应删除所有以前的数据?
EDIT
编辑
I know we can do this
我知道我们可以做到
adb uninstall com.package.foo & adb install foo.apk
I just wanted to know if there is a command or something in adb itself.
我只是想知道 adb 本身是否有命令或其他东西。
采纳答案by Ryan Amaral
Before the installation clean the datalike this:
在安装之前,像这样清理数据:
adb shell pm clear com.package.foo
then you can install normally using:
然后您可以使用以下方法正常安装:
adb install foo.apk
or just run through your IDE
或者只是运行你的 IDE
回答by Alexander Kulyakhtin
Try adb uninstall yourpackage.whatever.com
, then install again. Or select Clear data on the phone for that application.
尝试adb uninstall yourpackage.whatever.com
,然后重新安装。或者为该应用程序选择清除手机上的数据。
回答by Smeterlink
It's adb uninstall com.package.foo && adb install foo.apk
, however the uninstall won't work if the app is a system app, which can't be uninstalled. There's the command adb shell pm clear packageName
to clear a certain app's data, however it may require root. To reinstall the apk as usual adb install -r app.apk
是的adb uninstall com.package.foo && adb install foo.apk
,但是如果该应用程序是无法卸载的系统应用程序,则卸载将不起作用。有adb shell pm clear packageName
清除某个应用程序数据的命令,但它可能需要root。像往常一样重新安装apkadb install -r app.apk
回答by NickUnuchek
adb install [-l] [-t] [-r] [-s] <file> - push this package file to the
device and install it
('-t' uses for install debug apk)
('-l' means forward-lock the app)
('-r' means reinstall the app, keeping its data)
('-s' means install on SD card instead of internal storage)
adb uninstall [-k] <package> - remove this app package from the device
('-k' means keep the data and cache directories)
If you want to install debug.apk
file without clear the data
:
如果你想安装debug.apk
没有clear the data
:
adb install -t -r D:/debug.apk
If you want to install debug.apk
file with clear the data
:
如果要安装debug.apk
文件clear the data
:
adb shell pm clear com.package.app
adb install -t D:/debug.apk
And to start the app on Device via adb command:
并通过 adb 命令在设备上启动应用程序:
adb shell am start -n com.package.app/com.package.app.activity.MainActivity
回答by Sam Dozor
No. There is no (documented) way to do that with the adb install
command. Instead, you should do this:
不。没有(记录在案的)方法可以用adb install
命令来做到这一点。相反,你应该这样做:
adb uninstall com.your.package
adb install foo.apk