rekabhq / background_locator

A Flutter plugin for updating location in background.
MIT License
288 stars 329 forks source link

Unresolved reference: setPluginRegistrant #202

Closed dimas0211 closed 3 years ago

dimas0211 commented 3 years ago

Hi, @mehdok ! I'm trying to use a code in MainActivity.kt:

` import io.flutter.app.FlutterApplication import io.flutter.plugin.common.PluginRegistry import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback import io.flutter.plugins.pathprovider.PathProviderPlugin import io.flutter.view.FlutterMain import rekab.app.background_locator.IsolateHolderService

class Application : FlutterApplication(), PluginRegistrantCallback { override fun onCreate() { super.onCreate() IsolateHolderService.setPluginRegistrant(this) FlutterMain.startInitialization(this) }

  override fun registerWith(registry: PluginRegistry?) {
      if (!registry!!.hasPlugin("io.flutter.plugins.pathprovider")) {
          PathProviderPlugin.registerWith(registry.registrarFor("io.flutter.plugins.pathprovider"))
      }
  }

} `

but I receive an error: ' Unresolved reference: setPluginRegistrant' Could you please help me with that?

mehdok commented 3 years ago

Did you register your Application class in the Manifest file?

<application
        android:name=".Application"
        android:label="app_name"
        android:icon="@mipmap/ic_launcher"

Please look at the Use other plugins in callback.

dimas0211 commented 3 years ago

Did you register your Application class in the Manifest file?

<application
        android:name=".Application"
        android:label="app_name"
        android:icon="@mipmap/ic_launcher"

Please look at the Use other plugins in callback.

I have it as .MainActivity cuz the file name is MainActivity.kt

<activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme"

dimas0211 commented 3 years ago

Did you register your Application class in the Manifest file?

<application
        android:name=".Application"
        android:label="app_name"
        android:icon="@mipmap/ic_launcher"

Please look at the Use other plugins in callback.

changing it to .Application didnt help

mehdok commented 3 years ago

Can you share your manifest file?

dimas0211 commented 3 years ago

Can you share your manifest file?

Sure!

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

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:name="io.flutter.app.FlutterApplication"
    android:label="appName"
    android:icon="@mipmap/ic_launcher">
    <meta-data android:name="com.google.android.geo.API_KEY"
        android:value="AIzaSyAPAfxD0c_Q9O0qp8xGJfoiE7-DlPkScxc"/>
    <activity
        android:name=".Application"
        android:label="appName"
        android:icon="@mipmap/ic_launcher"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">

        <meta-data
          android:name="io.flutter.embedding.android.NormalTheme"
          android:resource="@style/NormalTheme"
          />

        <meta-data
          android:name="io.flutter.embedding.android.SplashScreenDrawable"
          android:resource="@drawable/launch_background"
          />
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>

    </activity>
    <receiver android:name="rekab.app.background_locator.LocatorBroadcastReceiver"
        android:enabled="true"
        android:exported="true"/>
    <service android:name="rekab.app.background_locator.LocatorService"
        android:permission="android.permission.BIND_JOB_SERVICE"
        android:exported="true"/>
    <service android:name="rekab.app.background_locator.IsolateHolderService"
        android:permission="android.permission.FOREGROUND_SERVICE"
        android:exported="true"
        />
    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />
</application>

`

mehdok commented 3 years ago

OK, there is one simple mistake, you have to declare your Application in <application tag, like this:

<application
    android:name=".Application"

and revert the <activity tag like what it looked like before.

dimas0211 commented 3 years ago

thanks! good point!

but even after applying changes still receive the same error image

mehdok commented 3 years ago

Which version of the plugin you are using?

I can see you have LocatorBroacastReceiver in your Manifest which is removed from the latest version.

dimas0211 commented 3 years ago

ahh I see updated the package to latest version and removed LocatorBroacastReceiver so this error doesn't show anymore. Thank you!

but instead of it I started receiving errors like this: image

Do you know what it can be?

mehdok commented 3 years ago

Hmm, not sure, but it would be nice to switch to the latest version of Kotlin and do a flutter clean

dimas0211 commented 3 years ago

Yeah, worked out! Thank you a lot!