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

module中AndroidManifest.xml基本配置

1
2
3
4
5
6
7
8
9
10
<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异常

1
2
app <- mine  <- ptoho
<- order <- photo

ptoho modulefile_paths文件

1
2
3
4
5
6
<resources>
<paths>
<cache-path path="photos/camera" name="photos" />
<external-cache-path path="photos/camera" name="photos" />
</paths>
</resources>

mine modulefile_paths文件

1
2
3
4
5
6
<resources>
<paths>
<cache-path path="avatar/camera" name="avatar" />
<external-cache-path path="avatar/camera" name="avatar" />
</paths>
</resources>

order modulefile_paths文件

1
2
3
4
5
6
<resources>
<paths>
<cache-path path="review/camera" name="review" />
<external-cache-path path="review/camera" name="review" />
</paths>
</resources>

解决方案

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

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :