Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type mismatch: inferred type is PluginRegistry? but FlutterEngine was expected

I want to work with Flutter Workmanager, I did the cited configuration in my .kt like this:

package com.example.mybackprocess

import be.tramckrijte.workmanager.WorkmanagerPlugin
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugins.GeneratedPluginRegistrant

class App : FlutterApplication(), PluginRegistry.PluginRegistrantCallback {
    override fun onCreate() {
        super.onCreate()
        WorkmanagerPlugin.setPluginRegistrantCallback(this)
    }

    override fun registerWith(reg: PluginRegistry?) {
        GeneratedPluginRegistrant.registerWith(reg)
    }
}

and I have changed android:name to

android:name=".App"

but it gives me this error:

Launching lib\main.dart on G3212 in debug mode... e:E:\mybackprocess\android\app\src\main\kotlin\com\example\mybackprocess\MainActivity.kt: (15, 48): Type mismatch: inferred type is PluginRegistry? but FlutterEngine was expected

FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:compileDebugKotlin'. Compilation error. See log for more details

Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org

BUILD FAILED in 55s Gradle task assembleDebug failed with exit code 1 Exited (sigterm)

Can someone please help me?

like image 209
Djamila Jada Avatar asked Dec 21 '19 15:12

Djamila Jada


3 Answers

you can fix the issue by replacing the following method in your application.kt

override fun registerWith(registry: PluginRegistry?) {
    registry?.registrarFor("com.iotecksolutions.background_location_fetch.BackgroundLocationFetchPlugin");
}

Note: Replace com.iotecksolutions.background_location_fetch.BackgroundLocationFetchPlugin with your plugin name.

like image 114
Zubair Rehman Avatar answered Nov 03 '22 17:11

Zubair Rehman


Replace the MainActivity.kt with:

import android.os.Bundle
import io.flutter.app.FlutterActivity
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity : FlutterActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        GeneratedPluginRegistrant.registerWith(this)
    }
}
like image 2
B. Stucke Avatar answered Nov 03 '22 17:11

B. Stucke


I used the following code to fix the error GeneratedPluginRegistrant.registerWith(FlutterEngine(applicationContext))

like image 2
Nasir Avatar answered Nov 03 '22 18:11

Nasir