I want to use firebase notifications in my application. I'm adding Aplication.java for this. After adding this file, the word registry is underlined in red.
GeneratedPluginRegistrant.registerWith(**registry**);
and the application gives built-in error.
and the application gives built-in error.
Launching lib\main.dart on KFAUWI in debug mode...
Running Gradle task 'assembleDebug'...
D:\Desktop\notification_app\android\app\src\main\kotlin\com\example\notification_app\Application.java:18: error: incompatible types: PluginRegistry cannot be converted to FlutterEngine
GeneratedPluginRegistrant.registerWith(registry);
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for 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
BU�LD FAILED in 1m 15s
Finished with error: Gradle task assembleDebug failed with exit code 1
Hi @SinanKanmaz
could you please provide your updated flutter doctor -v
and your flutter build --verbose ?
Also, to better address the issue, would be helpful
if you could post a minimal code sample to reproduce the problem
Thank you
I have the same issue. Adding this meta-data tag to AndroidManifest.xml:
<manifest>
<application>
[...]
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
Above code will make the flutter engine to generate the following GeneratedPluginRegistrant.java:
package io.flutter.plugins;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry;
/**
* Generated file. Do not edit.
* This file is generated by the Flutter tool based on the
* plugins that support the Android platform.
*/
@Keep
public final class GeneratedPluginRegistrant {
public static void registerWith(@NonNull FlutterEngine flutterEngine) {
ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine);
io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(shimPluginRegistry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
io.flutter.plugins.imagepicker.ImagePickerPlugin.registerWith(shimPluginRegistry.registrarFor("io.flutter.plugins.imagepicker.ImagePickerPlugin"));
com.lyokone.location.LocationPlugin.registerWith(shimPluginRegistry.registrarFor("com.lyokone.location.LocationPlugin"));
io.flutter.plugins.pathprovider.PathProviderPlugin.registerWith(shimPluginRegistry.registrarFor("io.flutter.plugins.pathprovider.PathProviderPlugin"));
flutterEngine.getPlugins().add(new io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin());
com.tekartik.sqflite.SqflitePlugin.registerWith(shimPluginRegistry.registrarFor("com.tekartik.sqflite.SqflitePlugin"));
}
}
which obviously takes a parameter of type FlutterEngine. But following the firebase_messaging tutorial, the Application.java should look like this:
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}
And the problem is that PluginRegistry cannot be used as FlutterEngine.
Currently i am commenting out the line with error but i am expecting to find a work around this problem.
Thanks.
I was applying flutter updates immediately. When I encountered this problem, I uninstalled and reinstalled the flutter SDK and resolved the problem. Because the previous version and the new version are different.
When I get this problem that the flutter doctor -v
D:\Desktop\eski flutter\flutter>flutter doctor -v
[√] Flutter (Channel master, v1.12.5-pre.45, on Microsoft Windows [Version 10.0.18362.476], locale tr-TR)
• Flutter version 1.12.5-pre.45 at D:\Desktop\eski flutter\flutter
• Framework revision 73c32545b7 (6 days ago), 2019-11-20 11:02:35 +0000
• Engine revision 176f563296
• Dart version 2.7.0
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at C:\Users\Zeynep\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 3.5)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 41.1.2
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
[√] VS Code (version 1.39.2)
• VS Code at C:\Users\Zeynep\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.5.1
[√] Connected device (3 available)
• KFAUWI • G0W0MA0772451FT7 • android-arm • Android 5.1.1 (API 22)
• Chrome • chrome • web-javascript • Google Chrome 78.0.3904.108
• Web Server • web-server • web-javascript • Flutter Tools
• No issues found!
Now the flutter doctor -v
C:\Users\Zeynep>flutter doctor -v
[√] Flutter (Channel stable, v1.9.1+hotfix.6, on Microsoft Windows [Version
10.0.18362.476], locale tr-TR)
• Flutter version 1.9.1+hotfix.6 at C:\flutter_src\flutter
• Framework revision 68587a0916 (2 months ago), 2019-09-13 19:46:58 -0700
• Engine revision b863200c37
• Dart version 2.5.0
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at C:\Users\Zeynep\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
• All Android licenses accepted.
[√] Android Studio (version 3.5)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 41.1.2
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
[√] VS Code (version 1.39.2)
• VS Code at C:\Users\Zeynep\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.5.1
[√] Connected device (1 available)
• KFAUWI • G0W0MA0772451FT7 • android-arm • Android 5.1.1 (API 22)
• No issues found!
Hi, I found the same problem and solved it like this
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
`class MyApplication : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this)
}
override fun registerWith(registry: PluginRegistry) {
FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
}`
Is @ReniDelonzek's solution a decent one? It seems a bit hacky to call out a paritcular registrant by a particular string.
I've been fighting for most of the day to implement firebase messaging with Flutter and it's been one thing after another. I don't know how implementing a google function on a google made framework could possibly be this difficult...
I have the same error, any solution?
I have put an alternative solution:
https://stackoverflow.com/questions/59446933/pluginregistry-cannot-be-converted-to-flutterengine/59490722#59490722
Hi, I found the same problem and solved it like this
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService`class MyApplication : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this)
}override fun registerWith(registry: PluginRegistry) {FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}}`
This work for me! please update documentation.
Unfortunately any of these solutions didn't completely work for me. They did however helped to remove error of FlutterEngine and PluginRegistry. Now the apk would build successfully but it won't run. I tried copying the apk and installing it manually. Apk was installed successfully but it refused to run. It just flashed a white screen for probably quarter or so, of a second and then disappeared.
Now I am not a flutter expert but I am guessing it happened may be due to changing the tag 'name=.MainActivity' to 'name=.Application'. Now we are not using MainActivity but Application in place of it. Now MainActivity was not there sitting idol that we just replaced it completely with Application.
So, what worked for me was a combination of MainActivity and Application files. I used following code in Application.java file.
package your.package.here;
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.FirebaseCloudMessagingPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugins.GeneratedPluginRegistrant;
import android.os.Bundle;
public class Application extends FlutterActivity implements PluginRegistrantCallback{
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
FirebaseCloudMessagingPluginRegistrant.registerWith(registry);
}
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
I have used here @DomingoMG 's solution for the 'FlutterEngine and PluginRegistry' error.
Notice here that I have copied the 'configureFlutterEngine()' method from MainActivity and now Application is extending FlutterActivity instead of FlutterApplication.
Hope it helps somebody.
I was also facing this error
solved by the following way:
https://stackoverflow.com/a/59490722/10020712
but
is it the recommended way?
Any news on this?
I have put an alternative solution:
https://stackoverflow.com/questions/59446933/pluginregistry-cannot-be-converted-to-flutterengine/59490722#59490722
This works perfectly for me, just follow the steps and do: flutter clean before compile.
Hi @SinanKanmaz
does @DomingoMG solution works for you?
thank you
@iapicca
In the link are the steps to follow.
https://stackoverflow.com/questions/59446933/pluginregistry-cannot-be-converted-to-flutterengine/59490722#59490722
You just have to create the file FirebaseCloudMessagingPluginRegistrant.java
Y
SendNotification.dart
Finally you must modify these two files:
MyApplication.java
AndroidManifest.xml
Please see https://github.com/FirebaseExtended/flutterfire/issues/1467#issuecomment-589575755 for solution. Closing.
package your.package.identifier;
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin;
public class MyApplication extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
// I've only had to add this line to make it work
FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
}
Most helpful comment
Hi, I found the same problem and solved it like this
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
`class MyApplication : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this)
}
FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
}`