Flutter:open_file打开本地文件报错问题

相关插件及版本: open_file: ^3.2.1

问题:

项目中一直用的这个插件,突然发现在安卓高版本不能正常使用,报权限问题permissionDenied,断点调试提示相关权限是MANAGE_EXTERNAL_STORAGE,申请权限之后还是不行,报错内容是Failed to find configured root that contains ,如下

bash 复制代码
java.lang.RuntimeException: java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/包名/flutter_app/测试.pdf

open_file插件地址

按说明重新配置filepaths依旧不行,找到了open_file的升级版open_filex

To use this plugin, add open_filex as a dependency in your pubspec.yaml file.

bash 复制代码
dependencies:
  open_filex: ^lastVersion

Example

bash 复制代码
import 'package:open_filex/open_filex.dart';

OpenFilex.open("/sdcard/example.txt");

when Conflict with other plugins about FileProvider, add code below in your /android/app/src/main/AndroidManifest.xml

bash 复制代码
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="xxx.xxx.xxxxx">
    <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/filepaths"
                    tools:replace="android:resource" />
        </provider>
    </application>
</manifest>

furthermore add code below in your /android/app/src/main/res/xml/filepaths.xml

bash 复制代码
<paths>
    <external-path name="external-path" path="."/>
    <external-cache-path name="external-cache-path" path="."/>
    <external-files-path name="external-files-path" path="."/>
    <files-path name="files_path" path="."/>
    <cache-path name="cache-path" path="."/>
    <root-path name="root" path="."/>
</paths>

when Android dependency 'com.android.support:appcompat-v7' has different version for the compile error, add code below in your /android/build.gradle

bash 复制代码
subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "27.1.1"
            }
        }
    }
}

按说明配置问题解决了。

相关推荐
子春一23 小时前
Flutter 2025 性能工程体系:从启动优化到帧率稳定,打造丝滑、省电、低内存的极致用户体验
flutter·ux
子春一24 小时前
Flutter 2025 性能工程体系:从启动优化到帧率稳定,打造丝滑如原生的用户体验
flutter·ux
子春一24 小时前
Flutter 2025 架构演进工程体系:从单体到模块化,构建可扩展、可协作、可持续的大型应用
flutter·架构
renke33645 小时前
Flutter 2025 国际化与本地化工程体系:打造真正全球化的应用体验
flutter
子春一26 小时前
Flutter 2025 可访问性(Accessibility)工程体系:从合规达标到包容设计,打造人人可用的数字产品
前端·javascript·flutter
renke33646 小时前
Flutter 2025 状态管理工程体系:从 setState 到响应式架构,构建可维护、高性能的状态流
flutter
麦客奥德彪6 小时前
Flutter 性能优化完整指南
flutter
麦客奥德彪7 小时前
Flutter 布局组件选择指南
flutter
子春一27 小时前
Flutter 2025 国际化与本地化工程体系:从多语言支持到文化适配,打造真正全球化的应用
前端·flutter
renke336410 小时前
Flutter 2025 模块化与微前端工程体系:从单体到可插拔架构,实现高效协作、独立交付与动态加载的下一代应用结构
前端·flutter·架构