plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

[Bug]: (share_plus) unable to share files on Android in release-mode only

Open ViscousPot opened this issue 6 months ago • 3 comments

Platform

Android 15

Plugin

share_plus

Version

11.0.0

Flutter SDK

3.7.0

Steps to reproduce

Simply trying to share a file on Android in release mode. Works totally fine in dev, but shows the error in the provided logs in release mode. I could not get any logs in flutter specifically, but only in logcat, filtered to my app

Code Sample

final txtFiles = <XFile>[];
for (final f in files) {
  txtFiles.add(XFile(f.path, mimeType: 'text/plain'));
}

final result = await SharePlus.instance.share(ShareParams(files: txtFiles));
print(result);

Logs

2025-06-13 23:29:21.104 16153-16153 flutter                 com.viscouspot.gitsync               I  PlatformException(Share failed, Class 'android.content.res.XmlBlock$Parser' does not implement interface 'N4.a' in call to 'int N4.a.next()' (declaration of 'v.k' appears in /data/app/~~82eJbKYgSbi4zd01v0v6aA==/com.viscouspot.gitsync-FEod7_LkQBv7I_5qS4poow==/base.apk), java.lang.IncompatibleClassChangeError: Class 'android.content.res.XmlBlock$Parser' does not implement interface 'N4.a' in call to 'int N4.a.next()' (declaration of 'v.k' appears in /data/app/~~82eJbKYgSbi4zd01v0v6aA==/com.viscouspot.gitsync-FEod7_LkQBv7I_5qS4poow==/base.apk)
                                                                                                    	at v.k.e(SourceFile:47)
                                                                                                    	at v.k.c(SourceFile:12)
                                                                                                    	at v.k.d(SourceFile:2)
                                                                                                    	at Z0.i.f(SourceFile:11)
                                                                                                    	at v3.a.onMethodCall(SourceFile:787)
                                                                                                    	at F3.c.d(SourceFile:17)
                                                                                                    	at z3.d.run(SourceFile:136)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:995)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:288)
                                                                                                    	at android.os.Looper.loop(Looper.java:393)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:9535)
                                                                                                    	at java.lang.re

Flutter Doctor

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [1,791ms]
    • Android SDK at /home/kdavidson/Android/Sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: /home/kdavidson/.jdks/jbr-17.0.12/bin/java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment JBR-17.0.12+1-1087.25-nomod (build 17.0.12+1-b1087.25)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome) [23ms]
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✗] Linux toolchain - develop for Linux desktop [193ms]
    ✗ clang++ is required for Linux development.
      It is likely available from your distribution (e.g.: apt install clang), or can be downloaded from
      https://releases.llvm.org/
    • cmake version 4.0.1
    • ninja version 1.11.1
    • pkg-config version 1.8.1

[✓] Android Studio (version 2024.2) [21ms]
    • Android Studio at /opt/android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)

[✓] VS Code (version 1.99.3) [19ms]
    • VS Code at /usr/share/code
    • Flutter extension version 3.112.0

[✓] Connected device (2 available) [189ms]
    • CPH2581 (mobile) • 25de8a50 • android-arm64 • Android 15 (API 35)
    • Linux (desktop)  • linux    • linux-x64     • Linux Mint 22 6.8.0-59-generic

[✓] Network resources [598ms]
    • All expected network resources are available.

! Doctor found issues in 3 categories.

Checklist before submitting a bug

  • [x] I searched issues in this repository and couldn't find such bug/problem
  • [x] I Google'd a solution and I couldn't find it
  • [x] I searched on StackOverflow for a solution and I couldn't find it
  • [x] I read the README.md file of the plugin
  • [x] I'm using the latest version of the plugin
  • [x] All dependencies are up to date with flutter pub upgrade
  • [x] I did a flutter clean
  • [x] I tried running the example project

ViscousPot avatar Jun 13 '25 22:06 ViscousPot

Same on iPhones.

Punisher612 avatar Jun 14 '25 12:06 Punisher612

Any fix?

shebin-tw avatar Jun 16 '25 07:06 shebin-tw

Personally switched to flutter_mailer and am copying the contents of the file into an email, but I understand that is quite different.

No clue what the root cause for this issue is sadly..

ViscousPot avatar Jun 16 '25 07:06 ViscousPot

We were obfuscating the build in release-mode. So, the below solution worked for me. https://github.com/crazecoder/open_file/issues/325#issuecomment-2724366606

shebin-tw avatar Jun 19 '25 04:06 shebin-tw

From the logs that you provided it seems like an issue with R8 fullMode enabled by default since Android Gradle Plugin 8: https://developer.android.com/build/releases/past-releases/agp-8-0-0-release-notes (check the last item in the list). We had a similar issue reported some time ago. Here is the discussion: https://github.com/fluttercommunity/plus_plugins/issues/2462#issuecomment-2618727365

I also bumped into such issue personally with another package slightly more than a year ago.

Back then adding this rule into proguard-rules.pro file helped me with issue with another package:

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

Could you check the suggested rule for R8, add it into your project and check if it works?

vbuberen avatar Jun 23 '25 15:06 vbuberen

Hey, I actually ended up using FlutterMailer instead, since it suits my purpose better.

Happy to close this as resolved 👍🏾

ViscousPot avatar Jun 28 '25 11:06 ViscousPot