Android 如何在xml中使用gradle占位符applicationId来创建唯一的contentProvider权限

Android 如何在xml中使用gradle占位符applicationId来创建唯一的contentProvider权限,android,android-gradle-plugin,android-contentprovider,Android,Android Gradle Plugin,Android Contentprovider,我有以下可搜索的xml声明: <?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:label="@string/app_name" android:voiceSearch

我有以下可搜索的xml声明:

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:label="@string/app_name"
    android:voiceSearchMode="showVoiceSearchButton"
    android:includeInGlobalSearch="true"
    android:searchMode="queryRewriteFromText"
    android:searchSuggestAuthority="com.mypackage.MyRecentSuggestionsProvider"
    android:searchSuggestSelection=" ?"
    android:hint="@string/search_hint">

</searchable>
现在的问题是我在gradle中有3种风格,因此contentProvider类中定义权限的行使用应用程序ID使其唯一,以便所有3种风格可以同时存在于设备上。我记得,两个应用程序不能有重复的权限

现在谈谈我的问题:我不想在每种风格中覆盖searchable.xml,只是为每种风格声明另一个权限。我宁愿这样做:

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:label="@string/app_name"
    android:voiceSearchMode="showVoiceSearchButton"
    android:includeInGlobalSearch="true"
    android:searchMode="queryRewriteFromText"
    android:searchSuggestAuthority="{applicationId}.MyRecentSuggestionsProvider"
    android:searchSuggestSelection=" ?"
    android:hint="@string/search_hint">

</searchable>


我们经常将android清单作为占位符来执行此操作。无论如何,我是否不必为内容提供者创建不同的xml声明,而是以某种方式使其每种味道都是唯一的

清单占位符在资源中不起作用。但是,您可以:

  • 在Gradle中使用
    resValue
    根据风格为字符串资源定义不同的值,然后让
    android:searchSuggestAuthority
    引用该字符串资源

  • 为每种风格设置源代码集,在其中定义一个字符串资源,然后让android:searchSuggestAuthority引用该字符串资源

  • 每个版本都有源代码集,每个版本都有不同的
    searchable.xml
    ,这是您试图避免的

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:label="@string/app_name"
    android:voiceSearchMode="showVoiceSearchButton"
    android:includeInGlobalSearch="true"
    android:searchMode="queryRewriteFromText"
    android:searchSuggestAuthority="{applicationId}.MyRecentSuggestionsProvider"
    android:searchSuggestSelection=" ?"
    android:hint="@string/search_hint">

</searchable>