androidfluttergradle

Error with open_file_plus plugin on Flutter - Compilation Failure (cannot find symbol PluginRegistry.Registrar)


I'm developing a Flutter mobile application where I need to open a PDF file after creating it within the app. I’m using open_file_plus: ^3.4.1+1, which is the latest version, but I consistently encounter a build error related to PluginRegistry.Registrar during compilation.

Here’s the code I'm using to save and open the PDF file:

openFile() async {
    String storeNameForInvoice = '${storeName.value} - $date';
    final invoicesPath = await getTargetDirectoryPath();
    final file = File("$invoicesPath/$storeNameForInvoice.pdf");
    await file.writeAsBytes(await pdf.save());
    await saveInvoiceToFirestore();
    loadInvoicesToCurrentInvoice(storeName.value);

    await OpenFile.open(file.path);
}

1- Configuration Details

Gradle Version In gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip

2- Compile and Target SDK Version: In build.gradle (app-level):

compileSdk = 34
targetSdk = 34

3- Settings.gradle Configuration Here is my settings.gradle setup:

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    id "com.google.gms.google-services" version "4.3.15" apply false
    id "org.jetbrains.kotlin.android" version "1.9.0" apply false
}

include ":app"

Error Message:

The error that appears in the console is as follows:

C:\Users\MQ\AppData\Local\Pub\Cache\hosted\pub.dev\open_file_plus-3.4.1+1\android\src\main\java\com\joutvhu\openfile\OpenFilePlusPlugin.java:66: error: cannot find symbol
    public static void registerWith(PluginRegistry.Registrar registrar) {
                                                  ^
  symbol:   class Registrar
  location: interface PluginRegistry
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':open_file_plus:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
> Run with --info option to get more log output.
> Run with --scan to get full insights.

BUILD FAILED in 1m 20s
Error: Gradle task assembleDebug failed with exit code 1

Additional Information:

I’ve tried several steps to resolve this issue, including:

Running flutter upgrade

Running flutter clean

Executing flutter pub upgrade

Checking outdated packages with flutter pub outdated

Despite these attempts, the issue persists. Additionally, I have tested other libraries such as open_file,url_launcher, open_filex, better_open_file, and open_app_file, but I continue to encounter similar errors with each.

Question:

What might be causing the PluginRegistry.Registrar error, and how can I resolve this issue to successfully open PDF files in my Flutter application?


Solution

  • I found a solution, though it was a bit unusual.

    After trying various fixes like updating and downgrading libraries, and even removing some packages, nothing worked.

    Finally, I decided to:

    1- Completely uninstall Android Studio and Flutter.

    2- Click Invalidate Caches.

    3- Reinstall both Android Studio and Flutter, using the same project and libraries.

    To my surprise, this fixed the issue entirely.

    I’m still unsure of the root cause, but glad the problem is resolved. Hope this helps anyone facing similar challenges!