Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: ShareFileProvider ... defineEntityReplacementText() not supported #2462

Open
8 tasks done
SimonErich opened this issue Dec 15, 2023 · 12 comments
Open
8 tasks done
Assignees
Labels
bug Something isn't working triage

Comments

@SimonErich
Copy link

Platform

Android 12

Plugin

share_plus

Version

7.0.0

Flutter SDK

3.13.9

Steps to reproduce

As soon as I add share_plus > 7.0.0 as a dependency my app crashes on the start in release mode and I get the error message below in logcat.
I checked the install instructions for tags or content to add to AndroidManifest.xml, but could not find anything.

As soon as I remove the share_plus dependency again, everything works fine.

Code Sample

**No code needed**
Adding the dependency without any additional code is enough to crash it

I have the following proguard rules. Is it maybe somehow related to that?
(I did not change anything apart from upgrading share_plus and adding this proguard file)


# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn com.huawei.android.os.BuildEx$VERSION
-dontwarn com.huawei.android.telephony.ServiceStateEx
-dontwarn com.huawei.hianalytics.process.HiAnalyticsConfig$Builder
-dontwarn com.huawei.hianalytics.process.HiAnalyticsConfig
-dontwarn com.huawei.hianalytics.process.HiAnalyticsInstance$Builder
-dontwarn com.huawei.hianalytics.process.HiAnalyticsInstance
-dontwarn com.huawei.hianalytics.process.HiAnalyticsManager
-dontwarn com.huawei.hianalytics.util.HiAnalyticTools
-dontwarn com.huawei.libcore.io.ExternalStorageFile
-dontwarn com.huawei.libcore.io.ExternalStorageFileInputStream
-dontwarn com.huawei.libcore.io.ExternalStorageFileOutputStream
-dontwarn com.huawei.libcore.io.ExternalStorageRandomAccessFile
-dontwarn org.bouncycastle.crypto.BlockCipher
-dontwarn org.bouncycastle.crypto.engines.AESEngine
-dontwarn org.bouncycastle.crypto.prng.SP800SecureRandom
-dontwarn org.bouncycastle.crypto.prng.SP800SecureRandomBuilder
-dontwarn com.huawei.hms.ads.identifier.AdvertisingIdClient$Info
-dontwarn com.huawei.hms.ads.identifier.AdvertisingIdClient


### Logs

```shell
FATAL EXCEPTION: main
                                                                                                    Process: com.myapp.app, PID: 4824
                                                                                                    java.lang.RuntimeException: Unable to get provider dev.fluttercommunity.plus.share.ShareFileProvider: org.xmlpull.v1.XmlPullParserException: defineEntityReplacementText() not supported
                                                                                                    	at android.app.ActivityThread.installProvider(ActivityThread.java:7464)
                                                                                                    	at android.app.ActivityThread.installContentProviders(ActivityThread.java:6976)
                                                                                                    	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6747)
                                                                                                    	at android.app.ActivityThread.access$1500(ActivityThread.java:256)
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2091)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:201)
                                                                                                    	at android.os.Looper.loop(Looper.java:288)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:7870)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
                                                                                                    Caused by: org.xmlpull.v1.XmlPullParserException: defineEntityReplacementText() not supported
                                                                                                    	at android.content.res.XmlBlock$Parser.defineEntityReplacementText(XmlBlock.java:139)
                                                                                                    	at androidx.core.content.b.h(Unknown Source:19)
                                                                                                    	at androidx.core.content.b.e(Unknown Source:11)
                                                                                                    	at androidx.core.content.b.attachInfo(Unknown Source:31)
                                                                                                    	at android.app.ActivityThread.installProvider(ActivityThread.java:7459)
                                                                                                    	at android.app.ActivityThread.installContentProviders(ActivityThread.java:6976) 
                                                                                                    	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6747) 
                                                                                                    	at android.app.ActivityThread.access$1500(ActivityThread.java:256) 
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2091) 
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:201) 
                                                                                                    	at android.os.Looper.loop(Looper.java:288) 
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:7870) 
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 

Flutter Doctor

~ flutter doctor                           
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.13.9, on Pop!_OS 22.04 LTS 6.5.6-76060506-generic, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.85.0)
[✓] Connected device (3 available)
[✓] Network resources

Checklist before submitting a bug

  • I searched issues in this repository and couldn't find such bug/problem
  • I Google'd a solution and I couldn't find it
  • I searched on StackOverflow for a solution and I couldn't find it
  • I read the README.md file of the plugin
  • I'm using the latest version of the plugin
  • All dependencies are up to date with flutter pub upgrade
  • I did a flutter clean
  • I tried running the example project
@SimonErich SimonErich added bug Something isn't working triage labels Dec 15, 2023
@AngeloAvv
Copy link

Hey @SimonErich , do you have minification turned on? Also, did you migrate your Android gradle config to 8.x?

@SimonErich
Copy link
Author

Hello @AngeloAvv ,

yes, we had to upgrade to gradle 8.x because of an SDK needed in our app.
minifyEnabled is not set anywhere in my project, so I guess it is disabled by default.

@AngeloAvv
Copy link

@SimonErich I believe there's a combination of libraries that make the app crash during the startup. I have the very same gradle and share_plus configuration on multiple projects, but one of them is crashing with the error message you reported.

I was able to solve the crash by adding the following row into gradle.properties, looks like the behavior of R8 changed since gradle 8.x:
android.enableR8.fullMode=false

@tao1
Copy link

tao1 commented Mar 2, 2024

I got a similar error using share_plus 7.2.2 :

java.lang.RuntimeException: Unable to get provider dev.fluttercommunity.plus.share.ShareFileProvider: org.xmlpull.v1.XmlPullParserException: Binary XML file line #-1: expected start or end tag (position:Binary XML file line #-1) 
	at android.app.ActivityThread.installProvider(ActivityThread.java:7841)
	at android.app.ActivityThread.installContentProviders(ActivityThread.java:7347)
	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7042)
	at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2261)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:205)
	at android.os.Looper.loop(Looper.java:294)
	at android.app.ActivityThread.main(ActivityThread.java:8248)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #-1: expected start or end tag (position:Binary XML file line #-1) 
	at android.content.res.XmlBlock$Parser.nextTag(XmlBlock.java:378)
	at f0.b.h(Unknown Source:19)
	at f0.b.e(Unknown Source:11)
	at f0.b.attachInfo(Unknown Source:31)
	at android.app.ActivityThread.installProvider(ActivityThread.java:7836)
	at android.app.ActivityThread.installContentProviders(ActivityThread.java:7347) 
	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7042) 
	at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) 
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2261) 
	at android.os.Handler.dispatchMessage(Handler.java:106) 
	at android.os.Looper.loopOnce(Looper.java:205) 
	at android.os.Looper.loop(Looper.java:294) 
	at android.app.ActivityThread.main(ActivityThread.java:8248) 
	at java.lang.reflect.Method.invoke(Native Method) 
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) 
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) 

I tried to add a res/raw/keep.xml file without success:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:keep="@xml/flutter_share_file_paths*" />

only android.enableR8.fullMode=false in gradle.properties fixes this crash.

@tao1
Copy link

tao1 commented Mar 4, 2024

Android Gradle Plugin 8.3 fixes this problem but leads to new one:
java.lang.IncompatibleClassChangeError: Class 'android.content.res.XmlBlock$Parser' does not implement interface 'i7.a' in call to 'int i7.a.next()'

@Fudal

This comment was marked as off-topic.

@vbuberen
Copy link
Collaborator

java.lang.IncompatibleClassChangeError: Class 'android.content.res.XmlBlock$Parser' does not implement interface 'i7.a' in call to 'int i7.a.next()'

This an issue with R8 configuration. By default since Gradle version 8 the R8 works in full mode which is a bit too aggressive and leads to such issues. To resolve it you need to either modify your proguard-rules.pro file or try to turn off the full mode of R8.

Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

@vegaro
Copy link

vegaro commented Jan 28, 2025

I don't think this should be marked as not planned. If there are issues with this plugin when R8 full mode is enabled, this plugin should include a proguard rules file that transitively applies to app's proguard configuration. Not adding this can lead to crashes at runtime and hard to debug issues for other libraries where the source of the issue is unclear. For example

If it's helpful, I was able to fix related issues by adding this to a project's proguard configuration.

-keep class org.xmlpull.v1.** { *; }

@vbuberen
Copy link
Collaborator

I don't think this should be marked as not planned

For sure. It was marked as not planned because of our automated action to close issues without activity and maintainers don't really check every single old issue without activity, so this is why it happened.

If it's helpful, I was able to fix related issues by adding this to a project's proguard configuration.

-keep class org.xmlpull.v1.** { *; }

Yes, this change fixed a similar issue in a few other packages that I use in work related projects.
However, it is strange that I have never seen it in projects with share_plus with R8 in full mode.
I will do some testing with the latest version of share_plus on a clean project and if it confirms will do a fix.

@vbuberen vbuberen reopened this Jan 29, 2025
@vbuberen vbuberen self-assigned this Jan 29, 2025
@vegaro
Copy link

vegaro commented Jan 29, 2025

It might be a bit hard for you to reproduce our exact scenario. The crash happens in combination with our plugin purchases_ui_flutter. Yesterday, I created a brand-new project using the pubspec.yaml from one of our clients and pinpointed the issue to share_plus. As soon as I removed share_plus, the crash stopped occurring.

In our case it was crashing at runtime when creating an Icon passing a R.drawable at this line:

https://github.com/RevenueCat/purchases-android/blob/d68cda40d073ea8c475b03c5eafe71c1f25acbf7/ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/composables/PaywallIcon.kt#L30

Since purchases-android is included as a Maven dependency in our plugin, it’s already compiled when used in our plugin. This likely caused R8 to incorrectly determine that the method was unused and remove it, since R8 only analyzes the code that is compiled in the app itself (including the plugins), not precompiled dependencies.

I would guide you on how to reproduce this using our plugin, but it requires setting up a project at revenuecat.com and opening a paywall, which might take some time.

If you need help testing a branch, a beta release or something like that, I would be happy to help verify it fixes it.

This is the issue in our repository where you can see the stacktrace. And this was the pubspec.yaml I used in case it's helpful. I didn't try removing other dependencies, so I just share the whole thing:

environment:
  sdk: ^3.6.1

dependencies:
  flutter:
    sdk: flutter
  firebase_core: ^3.10.0
  cupertino_icons: ^1.0.8
  flutter_slidable: ^3.1.2
  provider: ^6.1.2
  firebase_auth: ^5.4.0
  loader_overlay: ^5.0.0
  firebase_messaging: ^15.2.0
  font_awesome_flutter: ^10.8.0
  tutorial_coach_mark: ^1.2.12
  cloud_firestore: ^5.6.1
  permission_handler: ^11.3.1
  google_fonts: ^6.2.1
  google_sign_in: ^6.2.2
  shared_preferences: ^2.3.5
  logger: ^2.5.0
  idb_shim: ^2.6.1+7
  xxh3: ^1.2.0
  share_plus: ^10.1.4
  flutter_local_notifications: ^18.0.1
  enum_flag: ^1.0.2
  flutter_settings_ui: ^3.0.1
  purchases_flutter: ^8.4.3
  purchases_ui_flutter: ^8.4.3
  http: ^1.2.2
  mutex: ^3.1.0
  alarm: ^4.1.1
  firebase_crashlytics: ^4.3.0
  firebase_analytics: ^11.4.0
  firebase_app_check: ^0.3.2
  package_info_plus: ^8.1.3
  firebase_remote_config: ^5.3.0
  protobuf: ^3.1.0
  fixnum: ^1.1.1

@github-actions github-actions bot removed the Stale label Jan 30, 2025
@jamesncl
Copy link

I've also run into this bug, for me it manifests when I try to share a file using Share.shareXFiles(...):

Crashed in non-app:
message_codecs.dart in StandardMethodCodec.decodeEnvelope within flutter
method_channel_share.dart in MethodChannelShare.shareXFiles at line 112 within share_plus_platform_interface
android.content.res.XmlBlock$Parser
in getNamespacePrefix at line 179
in onMethodCall at line 158
io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler
in onMessage at line 17
io.flutter.embedding.engine.dart.DartMessenger
in invokeHandler at line 18
io.flutter.embedding.engine.dart.DartMessenger
in lambda$dispatchMessageToQueue$0 at line 41
io.flutter.embedding.engine.dart.DartMessenger

I've just updated my app to use Gradle 8.3 and AGP 8.1.4 compiling with Java 17, only experience the problem in release mode (minification and shrinkResources turned on). I also use Revenue Cat purchases_flutter.

Adding -keep class org.xmlpull.v1.** { *; } to my proguard rules fixes the issue.

I've been trying to create a minimal reproducible example but haven't been able to so far, there must be some special combination of dependencies required which I haven't figured out yet. Here are my dependencies in case it's useful:

pubspec.yaml dependencies
dependencies:

  flutter:
    sdk: flutter

  flutter_localizations:
    sdk: flutter

  animations: ^2.0.11
  app_settings: ^5.1.1
  archive: ^3.6.1
  built_collection: ^5.1.1
  built_value: ^8.9.2
  camera: ^0.11.0+2
  collection: ^1.18.0
  confetti: ^0.8.0
  characters: ^1.3.0
  device_info_plus: ^10.1.2
  duration: ^4.0.3
  envied: ^0.5.4+1
  fimber: ^0.7.0
  flutter_appauth: ^7.0.0
  flutter_embed_unity: ^1.2.3
  flutter_widget_from_html: ^0.15.3
  flutter_local_notifications: ^17.2.2
  flutter_material_color_picker: ^1.2.0
  flutter_portal: ^1.1.4
  flutter_timezone: ^3.0.1
  flutter_redux: ^0.10.0
  flutter_svg: ^2.0.10+1
  http: ^1.2.2
  image: ^4.2.0
  in_app_review: ^2.0.9
  intl: any
  memoize: ^3.0.0
  open_filex:
    git: https://github.com/jamesncl/open_filex_private
  optional: ^6.1.0+1
  package_info_plus: ^8.0.2
  path: ^1.9.0
  path_provider: ^2.1.4
  pdf: ^3.11.1
  permission_handler: ^11.3.1
  protobuf: ^3.1.0
  purchases_flutter: ^8.1.1
  redux: ^5.0.0
  reorderables: ^0.6.0
  reselect: ^0.5.0
  sentry_flutter: ^8.12.0
  shared_preferences: ^2.3.2
  share_plus: ^10.1.2
  sqflite: ^2.3.3+1
  svg_path_parser: ^1.1.2
  timezone: ^0.9.4
  two_dimensional_scrollables: ^0.3.2
  uuid: ^4.5.0
  url_launcher: ^6.3.0
  video_player: ^2.9.2
  wakelock_plus: ^1.2.8
  xml: ^6.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

7 participants