美文网首页
FileProvider Manifest merger fai

FileProvider Manifest merger fai

作者: 一个冬季 | 来源:发表于2021-03-22 23:13 被阅读0次
参考文章

FileProvider冲突

看看FileProvider怎样才会产生冲突
1、主Model,LibA,LibB 都有相同的provider会冲突么
主Model
 <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
</provider>

LibA
<provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
</provider>

LibB 
<provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

没有产生冲突

2、主Model不同,只有LibA,LibB 相同provider会冲突么
2.1修改主Provider的name参数
LibA、LibB 
<provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

name不同
 <provider
            android:name=".myfileprovider.MyFileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

没有产生冲突

2.2 修改主name、authorities 不同
省略 LibA、LibB
<provider ../>


name、authorities 不同
 <provider
            android:name=".myfileprovider.MyFileProvider"
            android:authorities="${applicationId}.hhhhhhh.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

没有产生冲突

2.3 修改主name、authorities 、resource不同
省略 LibA、LibB
<provider ../>
  <provider
            android:name=".myfileprovider.MyFileProvider"
            android:authorities="${applicationId}.hhhhhhh.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_pathsbbbbbb" />
        </provider>

没有产生冲突

3、主Model没有, LibA不同,LibB不同 provider会冲突么
3.1 修改LibA的authorities,LibB不变
LibA
 <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.aaaaaa.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

LibB
 <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

产生了异常

Manifest merger failed : Attribute provider#androidx.core.content.FileProvider@authorities value=(com.example.myfileprovider.aaaaaa.fileprovider) from [:A_FileProviderlibrary] AndroidManifest.xml:14:13-71
    is also present at [:B_FileProviderLibrary] AndroidManifest.xml:14:13-64 value=(com.example.myfileprovider.fileprovider).
    Suggestion: add 'tools:replace="android:authorities"' to <provider> element at AndroidManifest.xml:12:9-20:20 to override.

尝试修改LibA,创建一个Class继承FileProvider,替换LibA下的name

LibA
<provider
            android:name=".amyfileprovider.AFileProvider"
            android:authorities="${applicationId}.aaaaaa.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

LibB
 <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

发现并没有再次出现异常

3.2 修改LibA的resource,LibB不变
LibA
 <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_pathszzzzzzzz" />
        </provider>

LibB
 <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

产生了异常

Manifest merger failed : Attribute meta-data#android.support.FILE_PROVIDER_PATHS@resource value=(@xml/file_pathszzzzzzzz) from AndroidManifest.xml:27:17-57
    is also present at [:B_FileProviderLibrary] AndroidManifest.xml:19:17-51 value=(@xml/file_paths).
    Suggestion: add 'tools:replace="android:resource"' to <meta-data> element at AndroidManifest.xml to override.

解决方案如3.1

3.3 修改LibA的name,LibB不变
LibA
 <provider
            android:name=".amyfileprovider.AFileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

LibB
 <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

没有产生冲突

总结

1、在2个或者多个Provider中, android:name,android:authorities,android:resource 都相同,不会出现异常
2、在2个或者多个Provider中,其中一个android:name与其它的name都不同,不会出现异常。所以只要保证name不同,就不会出现异常现象,如果name相同了,android:authorities或android:resource其中一个与别人不同,就会出现异常

1616425958(1).jpg

相关文章

网友评论

      本文标题:FileProvider Manifest merger fai

      本文链接:https://www.haomeiwen.com/subject/csithltx.html