lohanidamodar / pdf_viewer

A flutter plugin for handling PDF files. Works on both Android & iOS
https://pub.dev/packages/advance_pdf_viewer
BSD 3-Clause "New" or "Revised" License
61 stars 144 forks source link

v2.0.1 throws MissingPluginException and crashes on Android #96

Open davejlin opened 2 years ago

davejlin commented 2 years ago

MissingPluginException is thrown and crashes my app when I use v2.0.1 on Android. v2.0.0 on Android does not have this issue. v2.0.1 on iOS does not have this issue. Is there something I need to update to use v2.0.1 on Android?

Exception has occurred.
MissingPluginException (MissingPluginException(No implementation found for method getPage on channel flutter_plugin_pdf_viewer))

Thrown from:

/Users/user/fvm/versions/stable/packages/flutter/lib/src/services/platform_channel.dart

  @optionalTypeArgs
  Future<T?> _invokeMethod<T>(String method, { required bool missingOk, dynamic arguments }) async {
    assert(method != null);
    final ByteData? result = await binaryMessenger.send(
      name,
      codec.encodeMethodCall(MethodCall(method, arguments)),
    );
    if (result == null) {
      if (missingOk) {
        return null;
      }
      throw MissingPluginException('No implementation found for method $method on channel $name');
    }
    return codec.decodeEnvelope(result) as T?;
  }

Call stack:

MethodChannel._invokeMethod (/Users/user/fvm/versions/stable/packages/flutter/lib/src/services/platform_channel.dart:165)
<asynchronous gap> (Unknown Source:0)
PDFDocument.get (/Users/user/.pub-cache/hosted/pub.dartlang.org/advance_pdf_viewer-2.0.1/lib/src/document.dart:97)
<asynchronous gap> (Unknown Source:0)
_PDFViewerState._loadPage (/Users/user/.pub-cache/hosted/pub.dartlang.org/advance_pdf_viewer-2.0.1/lib/src/viewer.dart:151)
<asynchronous gap> (Unknown Source:0)

flutter doctor -v:

[✓] Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-x64, locale en-US)
    • Flutter version 2.8.1 at /Users/user/Documents/Projects/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 77d935af4d (3 weeks ago), 2021-12-16 08:37:33 -0800
    • Engine revision 890a5fca2e
    • Dart version 2.15.1

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/user/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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 11.0.10+0-b96-7281165)

[✓] VS Code (version 1.63.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.32.0

[✓] Connected device (2 available)
    • Nexus 5X (mobile) • 0256574f4c681f87 • android-arm64  • Android 8.1.0 (API 27)
    • Chrome (web)      • chrome           • web-javascript • Google Chrome 96.0.4664.110
erainer commented 2 years ago

I am also receiving this exception on version 2.0.1 of advance_pdf_viewer using my Android device.

E/flutter ( 8502): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method getPage on channel flutter_plugin_pdf_viewer) E/flutter ( 8502): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:165:7) E/flutter ( 8502): E/flutter ( 8502): #1 PDFDocument.get (package:advance_pdf_viewer/src/document.dart:97:18) E/flutter ( 8502): E/flutter ( 8502): #2 _PDFViewerState._loadPage (package:advance_pdf_viewer/src/viewer.dart:151:18) E/flutter ( 8502):

flutter doctor -v:

[✓] Flutter (Channel stable, 2.8.0, on macOS 11.6 20G165 darwin-x64, locale en-US) • Flutter version 2.8.0 at /Users/emilyrainer/Developer/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision cf44000065 (4 weeks ago), 2021-12-08 14:06:50 -0800 • Engine revision 40a99c5951 • Dart version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0-rc5) • Android SDK at /Users/emilyrainer/Library/Android/sdk • Platform android-31, build-tools 31.0.0-rc5 • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.0) • Xcode at /Applications/Xcode.app/Contents/Developer • CocoaPods version 1.10.1

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3) • Android Studio at /Applications/Android Studio.app/Contents • 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 11.0.10+0-b96-7281165)

[✓] IntelliJ IDEA Community Edition (version 2018.1.6) • IntelliJ at /Applications/IntelliJ IDEA CE.app • 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

[✓] VS Code (version 1.63.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.29.0

[✓] Connected device (2 available) • SM G991U1 (mobile) • R5CR50YYD5T • android-arm64 • Android 11 (API 30) • Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.110

jlahamz commented 2 years ago

same here

I downgraded back to 2.0.0 and it works ok, just throws the Android Deprecated old error

willianmascimiano commented 2 years ago

same here

I downgraded back to 2.0.0 and it works ok, just throws the Android Deprecated old error

i had the same issue, but for me even downgrade to 2.0.0 won't work. Wen I tap the button to open PDF the screen just close and the app close, with the same message.

willianmascimiano commented 2 years ago

After I change advance_pdf_viewer: ^2.0.0 to advance_pdf_viewer: 2.0.0 works.

nileshkmahant commented 2 years ago

same here

I downgraded back to 2.0.0 and it works ok, just throws the Android Deprecated old error

same here.

ahsan4444 commented 2 years ago

Having the same issue on android when I upgraded to 2.0.1. Does anyone know how to resolve it? Kindly tell.

cinder92 commented 2 years ago

same issue here

I/System.out( 9379): Already closed
W/System.err( 9379): java.lang.IllegalStateException: Already closed
W/System.err( 9379):    at android.graphics.pdf.PdfRenderer.throwIfClosed(PdfRenderer.java:267)
W/System.err( 9379):    at android.graphics.pdf.PdfRenderer.close(PdfRenderer.java:185)
W/System.err( 9379):    at pt.tribeiro.flutter_plugin_pdf_viewer.FlutterPluginPdfViewerPlugin.getPage(FlutterPluginPdfViewerPlugin.java:206)
W/System.err( 9379):    at pt.tribeiro.flutter_plugin_pdf_viewer.FlutterPluginPdfViewerPlugin.access$100(FlutterPluginPdfViewerPlugin.java:31)
W/System.err( 9379):    at pt.tribeiro.flutter_plugin_pdf_viewer.FlutterPluginPdfViewerPlugin$1.run(FlutterPluginPdfViewerPlugin.java:84)
W/System.err( 9379):    at android.os.Handler.handleCallback(Handler.java:873)
W/System.err( 9379):    at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err( 9379):    at android.os.Looper.loop(Looper.java:193)
W/System.err( 9379):    at android.os.HandlerThread.run(HandlerThread.java:65)
D/PdfViewerPlugin( 9379): Retrieving page failed.
E/AndroidRuntime( 9379): FATAL EXCEPTION: flutterPdfViewer
E/AndroidRuntime( 9379): Process: io.rokt.com.otsuka.mobileapp, PID: 9379
E/AndroidRuntime( 9379): java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: flutterPdfViewer
E/AndroidRuntime( 9379):    at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:1280)
E/AndroidRuntime( 9379):    at io.flutter.embedding.engine.FlutterJNI.invokePlatformMessageEmptyResponseCallback(FlutterJNI.java:933)
E/AndroidRuntime( 9379):    at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:167)
E/AndroidRuntime( 9379):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.notImplemented(MethodChannel.java:248)
E/AndroidRuntime( 9379):    at pt.tribeiro.flutter_plugin_pdf_viewer.FlutterPluginPdfViewerPlugin$1.run(FlutterPluginPdfViewerPlugin.java:87)
E/AndroidRuntime( 9379):    at android.os.Handler.handleCallback(Handler.java:873)
E/AndroidRuntime( 9379):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 9379):    at android.os.Looper.loop(Looper.java:193)
E/AndroidRuntime( 9379):    at android.os.HandlerThread.run(HandlerThread.java:65)
D/TransportRuntime.SQLiteEventStore( 9379): Storing event with priority=HIGHEST, name=FIREBASE_CRASHLYTICS_REPORT for destination cct
D/TransportRuntime.JobInfoScheduler( 9379): Scheduling upload for context TransportContext(cct, HIGHEST, MSRodHRwczovL2NyYXNobHl0aWNzcmVwb3J0cy1wYS5nb29nbGVhcGlzLmNvbS92MS9maXJlbG9nL2xlZ2FjeS9iYXRjaGxvZ1xBSXphU3lCcnBTWVQ0RkZMMDlyZUhKaTZIOUZZZGVpU25VVE92Mk0=) with jobId=-1646578455 in 9803ms(Backend next call timestamp 1642131046115). Attempt 1
nimisharanipabacancy commented 2 years ago

Facing same issue, Any solution for this?

bagus-repository commented 2 years ago

I do have this issue on v.2.1.0 here the log from sentry

java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: flutterPdfViewer
    at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:3)
    at io.flutter.embedding.engine.FlutterJNI.invokePlatformMessageEmptyResponseCallback(FlutterJNI.java:1)
    at io.flutter.embedding.engine.f.b$a.a(DartMessenger.java:2)
    at f.a.d.a.k$a$a.c(MethodChannel.java:1)
    at i.a.a.a$a.run(FlutterPluginPdfViewerPlugin.java:8)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:255)
    at android.os.HandlerThread.run(HandlerThread.java:67)

I think it is fine on 2.0.0 before

RogerBrusamarello commented 2 years ago

This package is working, trying to use it.

https://pub.dev/packages/advance_pdf_viewer_fork

b5710546291 commented 2 years ago

https://github.com/lohanidamodar/pdf_viewer/blob/43ae962390ac51cd79b418f592073b14a871ece1/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java#L177

This line here cause exception on https://github.com/lohanidamodar/pdf_viewer/blob/43ae962390ac51cd79b418f592073b14a871ece1/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java#L203 before return. which result in null being return. Can we get a fix on the official pub?

ncdm-stldr commented 2 years ago

https://github.com/lohanidamodar/pdf_viewer/blob/43ae962390ac51cd79b418f592073b14a871ece1/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java#L177

This line here cause exception on

https://github.com/lohanidamodar/pdf_viewer/blob/43ae962390ac51cd79b418f592073b14a871ece1/android/src/main/java/pt/tribeiro/flutter_plugin_pdf_viewer/FlutterPluginPdfViewerPlugin.java#L203 before return. which result in null being return. Can we get a fix on the official pub?

There is the error you mention, and also there should be a else block after the if here:

                               if (pageResult == null) {
                                    Log.d(TAG, "Retrieving page failed.");
                                    result.notImplemented();
                                }
                                mainThreadHandler.post(new Runnable() {
                                    @Override
                                    public void run() {
                                        result.success(pageResult);
                                    }
                                });

I created a pull request https://github.com/lohanidamodar/pdf_viewer/pull/101

Jamesweng commented 2 years ago

Hi, when will be a new release with fix available?

Thanks!