首页 > 解决方案 > Flutter 如何解决找不到具有权限的提供者的元数据以及与 FileProvider 的其他插件冲突的问题?

问题描述

实际上我正在使用open_fileflutter_webview_plugin packages在同一个项目中。运行应用程序时出现如下错误:-

java.lang.IllegalArgumentException: Couldn't find meta-data for provider with authority com.example.fileprovider

然后我找到了一个文档来添加提供者来解决这个问题,所以我添加了Androidmanifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" 
package="com.example">
...
<application>
...
       <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileProvider"
            android:exported="false"
            android:grantUriPermissions="true"
            tools:replace="android:authorities">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"
                tools:replace="android:resource" />
        </provider> 

</application>

添加此提供程序后,也会出现相同的错误。在这两个包中,他们都使用 fileProvider。因此,它正在发生冲突。

所以,帮我配置两个包fileProvider。

dependencies:
  open_file: ^3.0.1
  flutter_webview_plugin: ^0.3.11

提前致谢。

标签: flutterdartandroid-fileprovider

解决方案


是的,经过一整天的冲浪,我已经解决了这个问题,使用自定义文件提供程序来避免与其他插件发生冲突,例如open_file.

请按照flutter_webview_plugin以下步骤解决它。

步骤1

android/src/main/AndroidManifest.xml

消除

android:name="androidx.core.content.FileProvider"

添加

android:name="com.flutter_webview_plugin.FlutterWebviewPluginFileProvider"

第2步

android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPluginFileProvider.java

创建新班级FlutterWebviewPluginFileProvider.java

package com.flutter_webview_plugin;

import androidx.core.content.FileProvider;

public class FlutterWebviewPluginFileProvider extends FileProvider {

}

步骤:3

android/src/main/java/com/flutter_webview_plugin/WebviewManager.java

删除导入

import androidx.core.content.FileProvider;

查找并删除此行

return FileProvider.getUriForFile(context, packageName + ".fileprovider", capturedFile);

添加这个

return FlutterWebviewPluginFileProvider.getUriForFile(context, packageName + ".fileprovider", capturedFile);

Refered by : https://github.com/fluttercommunity/flutter_webview_plugin/commit/aeda1e80effd59afdb526b11608cb232a83a6bab

谢谢


推荐阅读