adb - 如何在不保留数据的情况下重新安装应用程序?

Sat*_*hJM 42 android command-prompt adb apk

adb install foo.apk
Run Code Online (Sandbox Code Playgroud)

使用此命令时,如果存在apk,我应该收到错误*失败[INSTALL_FAILED_ALREADY_EXISTS]*

 adb install -r myapp-release.apk
Run Code Online (Sandbox Code Playgroud)

在这种情况下,通过根据文档保留旧数据,将替换现有的apk,

'-r'表示重新安装应用程序,保留其数据

现在我如何重新安装应用程序,但所有以前的数据应该被删除?

编辑

我知道我们可以做到这一点

adb uninstall com.package.foo & adb install foo.apk
Run Code Online (Sandbox Code Playgroud)

我只是想知道adb本身是否有命令或其他内容.

Rya*_*ral 41

在安装之前清理这样的数据:

adb shell pm clear com.package.foo
Run Code Online (Sandbox Code Playgroud)

然后您可以正常安装使用:

adb install foo.apk
Run Code Online (Sandbox Code Playgroud)

或者只是通过IDE运行


Ale*_*tin 10

尝试adb uninstall yourpackage.whatever.com,然后重新安装.或者在手机上选择清除该应用程序的数据.


Nic*_*hek 9

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)
Run Code Online (Sandbox Code Playgroud)

如果你想安装debug.apk没有clear the data:

adb install -t -r D:/debug.apk
Run Code Online (Sandbox Code Playgroud)

如果要安装debug.apk文件clear the data

adb shell pm clear com.package.app
adb install -t D:/debug.apk
Run Code Online (Sandbox Code Playgroud)

并通过 adb 命令在设备上启动应用程序:

adb shell am start -n com.package.app/com.package.app.activity.MainActivity
Run Code Online (Sandbox Code Playgroud)


Sme*_*ink 8

adb uninstall com.package.foo && adb install foo.apk,但是卸载不会,如果应用程序是一个系统应用程序,它不能被卸载工作.有adb shell pm clear packageName清除某个应用程序数据的命令,但它可能需要root.像往常一样重新安装apkadb install -r app.apk