0

由于我的要求是我的应用程序具有从服务器创建自定义贴纸和贴纸的功能,因此单个内容提供程序会导致问题,我尝试了很多添加多个内容提供程序,这会在编辑配置中导致问题 如下所示 在此处输入图像描述

  • 这就是我尝试在清单中添加提供程序的方式

         <provider
         android:name=".whats_app_based_code.provider.StickerContentProvider"
         android:authorities="${contentProviderAuthority}"
         android:enabled="true"
         android:exported="true"
         android:readPermission="com.whatsapp.sticker.READ">
     </provider>
     <provider
         android:name=".whats_app_based_code.provider.StickerContentProviderServer"
         android:authorities="${contentProviderAuthority}"
         android:enabled="true"
         android:exported="true"
         android:readPermission="com.whatsapp.sticker.READ">
     </provider>
    
  • 应用级 Gradle

安卓 {

compileSdkVersion 30
buildToolsVersion "29.0.3"
defaultConfig {
    applicationId "com.numan.stickersapp"
    minSdkVersion 21
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
    def contentProviderAuthority = applicationId + ".WhatsAppLicensedCode.StickerContentProvider"
    def contentProviderAuthority2 =applicationId+".WhatsAppLicensedCode.StickerContentProviderServer"
    // Creates a placeholder property to use in the manifest.
    manifestPlaceholders = [contentProviderAuthority: "\"${contentProviderAuthority}\""]
    manifestPlaceholders = [contentProviderAuthorityserver: "\"${contentProviderAuthority2}\""]
    // Adds a new field for the authority to the BuildConfig class.
    buildConfigField("String", "CONTENT_PROVIDER_AUTHORITY", "\"${contentProviderAuthority}\"")
    buildConfigField("String","CONTENT_PROVIDER_AUTHORITY_SERVER","\"${contentProviderAuthority2}\"")
    buildConfigField 'String', 'STICKERS_BASE_URL', "\"https://firebasestorage.googleapis.com/\""


}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
    debug {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
4

1 回答 1

0

最后,我做了这一部分,我正在添加我的方法来实现这一点,因为像我这样的人可能想在他们的应用程序中添加这样的功能:我实际上做的是:

  • 我只在App Level Gradle中添加了一个内容提供程序并删除了另一个

  • 我通过清单添加了第二个内容提供程序,并对完整的提供程序包进行了硬编码,如下所示:

         <provider
         android:name=".whats_app_based_code.provider.StickerContentProvider"
         android:authorities="${contentProviderAuthority}"
         android:enabled="true"
         android:exported="true"
         android:readPermission="com.whatsapp.sticker.READ">
     </provider>
     <provider
         android:name=".whats_app_based_code.provider.StickerContentProviderServer"
         android:authorities="com.numan.stickersapp.whats_app_based_code.provider.WhatsAppLicensedCode.StickerContentProviderServer"
         android:enabled="true"
         android:exported="true"
         android:readPermission="com.whatsapp.sticker.READ">
     </provider>
    
于 2020-11-10T09:32:33.467 回答