Android 7.0及以上FileProvider巨坑Failed to find configured root that contains

module中AndroidManifest.xml基本配置

<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="${applicationId}.fileProvider"
    android:grantUriPermissions="true"
    android:exported="false">
    <meta-data
        tools:replace="android:resource"
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths" />
</provider>

问题描述

当多个module分别独立使用FILE_PROVIDER_PATHS时,只有一个module的file_paths文件是有效的

例如:有如下依赖,运行发现order module中配置的FILE_PROVIDER_PATHS未被识别,抛出Failed to find configured root that contains异常

app <- mine  <- ptoho
    <- order <- photo

ptoho modulefile_paths文件

<resources>
    <paths>
        <cache-path path="photos/camera" name="photos" />
        <external-cache-path path="photos/camera" name="photos" />
    </paths>
</resources>

mine modulefile_paths文件

<resources>
    <paths>
        <cache-path path="avatar/camera" name="avatar" />
        <external-cache-path path="avatar/camera" name="avatar" />
    </paths>
</resources>

order modulefile_paths文件

<resources>
    <paths>
        <cache-path path="review/camera" name="review" />
        <external-cache-path path="review/camera" name="review" />
    </paths>
</resources>

解决方案

所有配置放在主app module或其中一个子module中

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2024/01/13/android-7-and-above-fileprovider-crater-failed-to-find-configured-root-that-contains/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
Android 7.0及以上FileProvider巨坑Failed to find configured root that contains
module中AndroidManifest.xml基本配置 <provider android:name="android.support.v4.content.FileProvider" android:authorities="……
<<上一篇
下一篇>>
文章目录
关闭
目 录