Android: how to clear app cache and keep user data via adb?

前端 未结 1 517
刺人心
刺人心 2020-12-30 02:28

I\'m running some automated tests (with calabash-android) on an Android app and I need to programatically trigger a clear of the app\'s cache, but not user data.

I f

1条回答
  •  礼貌的吻别
    2020-12-30 02:56

    I've been exploring the /data/data/ folder, and found a cache folder inside, which contained the cached files for the app that I wanted to clear the cache of. Then from adb shell I deleted the contents, and the app's cache was reset.

    Most probably you can run adb shell su -c "rm -rf /data/data//cache/*" to delete the cache only for the app (the app might have some custom caching, which isn't affected by this). It worked for me.

    Edit: Of course, your device's adb must be set up to have root access (in Cyanogen, you can enable it).

    Edit: @running-codebase pointed out in the comments, that if your application is compiled with a debug key, you can also use run-as command in adb's shell. So it would look like this: adb shell run-as rm -rf /data/data//cache/* This method does not require root.

    0 讨论(0)
提交回复
热议问题