android手机莫名其妙卸载重装有残留数据

参考文档:
https://developer.android.com/guide/topics/data/autobackup?hl=zh-cn
https://developer.android.com/about/versions/12/backup-restore#xml-changes
https://stackoverflow.com/questions/70365809/how-to-specify-to-not-allow-any-data-backup-with-androiddataextractionrules

问题描述:
最近包括1年前,也都发现了,某一些手机(特别是,有google框架服务的)在卸载后,安装回来,会加载到类似/data/data下面的cache内容,比如database,sharedPref,mmkv等。

问题的根源在于,从android6.0开始就支持一个自动备份。并且在android11,android12,均有更改。
进行影响你配置androidManifest.xml的三个点。

android:allowBackup="false"
android:fullBackupContent="false"
android:dataExtractionRules="@xml/data_extraction_rules"

data_extraction_rules.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
   Sample data extraction rules file; uncomment and customize as necessary.
   See https://developer.android.com/about/versions/12/backup-restore#xml-changes
   for details.
-->
<data-extraction-rules>
    <cloud-backup>
        <exclude domain="root" />
        <exclude domain="file" />
        <exclude domain="database" />
        <exclude domain="sharedpref" />
        <exclude domain="external" />
    </cloud-backup>
    <device-transfer>
        <exclude domain="file" />
        <exclude domain="database" />
        <exclude domain="sharedpref" />
        <exclude domain="external" />
        <exclude domain="root" />
    </device-transfer>
</data-extraction-rules>

其中allowBackup,是老版本android必备。
其中fullBackupContent,是配置android11以下。
其中dataExtractionRules,适配android12以上。

官方文档没有讲明确的是:

  1. 三项都必须得有;
  2. 其中fullBackupContent是可以不用配置xml,直接配置false即可。
  3. dataExtractionRules在android12以上不得不配置,想要移除则参考上述xml编写(不用担心它在低版本被乱解析,他会被自动忽略。androidManifest的黄色提醒也不用care。)

如果想要保留backup功能。自行参考源文档编写第二和第三项。

这个功能,在国内很少能翻到文档的原因,是backup这项功能与google的网盘有账号绑定关系,或者跟adb调试有关。
因此,极少在国内用户出现问题。而一般的应用程序,在重新安装一般都会自行处理各种init数据和需要重新登录。
因此禁用它更为妥当。出海的程序需要小心谨慎该项配置,如果涉及到确实需要备份,请参考研究本文档头的2个文档。