bkonyi / FlutterGeofencing

Rough work for Flutter geofencing plugin
BSD 3-Clause "New" or "Revised" License
338 stars 220 forks source link

Failing to initialze: MissingPluginException #6

Closed benjaminchevoor closed 3 years ago

benjaminchevoor commented 5 years ago

I am running my app on an Android emulator device (API 27) and I am getting a exception when invoking await GeofencingManager.initialize();

MissingPluginException(No implementation found for method GeofencingPlugin.initializeService on channel plugins.flutter.io/geofencing_plugin)
MethodChannel.invokeMethod (platform_channel.dart:291)
GeofencingManager.initialize (geofencing.dart:105)

Am I missing anything? Why I don't I see any usages of the callbackDispatcher() method in the callback_dispatcher.dart file?

I believe I have set up everything on the Android project correctly:

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.hammer">

    <!-- The INTERNET permission is required for development. Specifically,
         flutter needs it to communicate with the running application
         to allow setting breakpoints, to provide hot reload, etc.
    -->
    <uses-permission android:name="android.permission.INTERNET"/>

    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
        android:name=".HammerApplication"
        android:label="hammer"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <!-- FOR GEOFENCNING START -->
        <receiver android:name="io.flutter.plugins.geofencing.GeofencingBroadcastReceiver"
            android:enabled="true" android:exported="true"/>

        <service android:name="io.flutter.plugins.geofencing.GeofencingService"
            android:permission="android.permission.BIND_JOB_SERVICE" android:exported="true"/>
        <!-- FOR GEOFENCNING END -->
    </application>
</manifest>

HammerApplication.java

package com.hammer;

import android.content.Context;
import android.support.multidex.*;
import io.flutter.app.FlutterApplication;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.geofencing.GeofencingService;

public class HammerApplication extends FlutterApplication implements PluginRegistrantCallback {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        GeofencingService.setPluginRegistrant(this);
    }

    @Override
    public void registerWith(PluginRegistry registry) {
        GeneratedPluginRegistrant.registerWith(registry);
    }

}

MainActivity.java

package com.hammer;

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

public class MainActivity extends FlutterActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GeneratedPluginRegistrant.registerWith(this);
  }
}

Really appreciate the help! Thanks!

kelegorm commented 5 years ago

Have you tried stop app and run it again? That issue can arise in case when you added dependency in pubspec and made only hot reload.

benjaminchevoor commented 5 years ago

Hi @kelegorm, thanks for the feedback. I did try killing the app and starting again many times while debugging. This didn't seem to have any effect.

kelegorm commented 5 years ago

We have one more receiver in manifest:

        <receiver android:name="io.flutter.plugins.geofencing.GeofencingRebootBroadcastReceiver"
            android:enabled="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"></action>
            </intent-filter>
        </receiver>

Also may be you need:

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>

Also in application fix register like that:

    @Override
    public void registerWith(PluginRegistry registry) {
        GeofencingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.geofencing.GeofencingPlugin"));
    }
bkonyi commented 3 years ago

Closing as stale.