Skip to content

Commit 828eabd

Browse files
huextratvonovak
andauthored
fix: unique FileProvider name to prevent conflict (#929)
* fix: unique FileProvider name to prevent conflict Addresses a potential conflict with other libraries by using a unique authority name for the FileProvider. Introduces a custom FileProvider to avoid conflicts during manifest merging with other libraries' providers. Updates the authority in the manifest. * chore: add changeset * Update .changeset/fileprovider-conflict.md --------- Co-authored-by: Vojtech Novak <vonovak@gmail.com>
1 parent 027bbc7 commit 828eabd

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-native-documents/viewer": major
3+
---
4+
5+
fix: use unique FileProvider name to prevent conflict with other FileProvider

packages/document-viewer/android/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<application>
55
<!-- android:authorities needs to be unique to an app, so we cannot hardcode it -->
66
<provider
7-
android:name="androidx.core.content.FileProvider"
8-
android:authorities="${applicationId}.reactnativedocumentviewer.fileprovider"
7+
android:name=".DocumentViewerFileProvider"
8+
android:authorities="${applicationId}.fileprovider"
99
android:exported="false"
1010
android:grantUriPermissions="true">
1111
<meta-data
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.reactnativedocumentviewer;
2+
3+
import androidx.core.content.FileProvider
4+
5+
/**
6+
* Empty subclass of [FileProvider] used so this library's provider has a unique
7+
* [android:name] in the manifest. That prevents the manifest merger from merging
8+
* this provider with another library's FileProvider,
9+
* which would cause an "Attribute provider@authorities value=... is also present at..."
10+
* conflict.
11+
*/
12+
class DocumentViewerFileProvider : FileProvider()

packages/document-viewer/android/src/main/java/com/reactnativedocumentviewer/RNDocumentViewerModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class RNDocumentViewerModule(reactContext: ReactApplicationContext) : NativeDocu
6161
// Package name may not be the same as applicationId but usually is.
6262
// Also see document-viewer/android/src/main/AndroidManifest.xml
6363
val applicationId = androidApplicationId ?: reactApplicationContext.packageName
64-
val authority = "$applicationId.reactnativedocumentviewer.fileprovider"
64+
val authority = "$applicationId.fileprovider"
6565
val uri = Uri.parse(bookmarkOrUri)
6666
val uriPath = uri.path ?: throw IllegalArgumentException("file:// uri must have a path")
6767
val fileUri = FileProvider.getUriForFile(

0 commit comments

Comments
 (0)