attribute provider#androidx.core.content.FileProvider@authorities value=(com.xxx.xxx.fileProvider) from AndroidManifest.xml:132:13-70 is also present at AndroidManifest.xml:64:13-64 value=(com.xxx.xxx.fileprovider)
重新继承FileProvider,使用继承的FileProvider在AndroidManifest.xml注册
例如:
public class MyFileProvider extends FileProvider {
}
<provider
android:name=".provider.MyFileProvider"
android:authorities="${applicationId}.fileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/files_paths" />
</provider>
实验看看FileProvider怎样才会产生冲突
主Module
<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>
ModuleA
<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>
ModuleB
<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.1)修改主Module Provider的name参数
主Module name不同
<provider
android:name=".provider.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>
ModuleA、ModuleB
<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.2) 修改主Module name、authorities 不同
主Module name、authorities 不同
<provider
android:name=".provider.MyFileProvider"
android:authorities="${applicationId}.demo.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
ModuleA、ModuleB 保持不变
<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.3) 修改主Module name、authorities 、resource不同
主Module name、authorities 、resource不同
<provider
android:name=".provider.MyFileProvider"
android:authorities="${applicationId}.demo.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_path_demo" />
</provider>
ModuleA、ModuleB 保持不变
<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.1) 修改ModuleA的authorities,ModuleB不变
ModuleA
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.demo.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
ModuleB
<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.xxx.xxx.demo.fileprovider) from…
接下来:尝试修改ModuleA,创建Class继承FileProvider,替换ModuleA下的name
ModuleA
<provider
android:name=".provider.ModuleAFileProvider"
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>
ModuleB
<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) 修改ModuleA的resource,ModuleB不变
ModuleA
<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_demo" />
</provider>
ModuleB
<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_paths_demo) from AndroidManifest.xml … value=(@xml/file_paths).
Suggestion: add ‘tools:replace=“android:resource”’ to element at AndroidManifest.xml to override.
接下来:解决方案如 3.1)
修改ModuleA的name,ModuleB不变
ModuleA
<provider
android:name=".provider.ModuleAFileProvider"
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>
ModuleB
<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>
实验结果:没有产生冲突