51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Android编译报错:attribute android:dataExtractionRules not found.解决方法

前言 {#前言}

在工作中遇到以下报错信息:error: attribute android:dataExtractionRules not found.,记录一下,以免后续再次遇到类似的问题:

|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | Android resource linking failed D:\MyWork\android\app\build\intermediates\packaged_manifests\debug\AndroidManifest.xml:13: error: attribute android:dataExtractionRules not found. error: failed processing manifest. |

问题分析 {#问题分析}

打开报错的AndroidManifest.xml文件,内容如下所示:

|---------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <application android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" android:fullBackupContent="@xml/backup_rules" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.AppCompat" tools:targetApi="28"> <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <meta-data android:name="android.app.lib_name" android:value="" /> </activity> </application> </manifest> |

发现第7行代码:android:dataExtractionRules="@xml/data_extraction_rules",有黄色的警告信息:Unknown attribute android:dataExtractionRules

解决方法 {#解决方法}

既然提示未知属性,果断删除后,重新编译通过,问题得到解决。

后记 {#后记}

应用的清单标志
通过在清单文件中使用 android:dataExtractionRules 属性,将您的应用指向新的 XML 配置。当您指向新的 XML 配置时,搭载 Android 12 或更高版本的设备会忽略指向旧配置的 android:fullBackupContent 属性。以下代码示例展示了新的清单文件条目:

|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 | <application ... <!-- The below attribute is ignored. --> android:fullBackupContent="old_config.xml" <!-- You can point to your new configuration using the new dataExtractionRules attribute . --> android:dataExtractionRules="new_config.xml" ...> </application> |

xml/data_extraction_rules.xml 文件内容如下所示:

|---------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <?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 [disableIfNoEncryptionCapabilities="true|false"]> ... <include domain=["file" | "database" | "sharedpref" | "external" | "root"] path="string"/> ... <exclude domain=["file" | "database" | "sharedpref" | "external" | "root"] path="string"/> ... </cloud-backup> <device-transfer> ... <include domain=["file" | "database" | "sharedpref" | "external" | "root"] path="string"/> ... <exclude domain=["file" | "database" | "sharedpref" | "external" | "root"] path="string"/> ... </device-transfer> </data-extraction-rules> |

原因分析 {#原因分析}

由于手动修改的版本号低于Android12导致该属性不支持,因此在低版本中就需要删除android:dataExtractionRules="@xml/data_extraction_rules"配置项。

dataExtractionRules 属性 is available 用于 API 31 (Android 12) 及更高版本。为 API 31 之前的 Android 版本保留 allowBackup 和 fullBackupContent 属性。


赞(1)
未经允许不得转载:工具盒子 » Android编译报错:attribute android:dataExtractionRules not found.解决方法