Dev-hwang / flutter_foreground_task

This plugin is used to implement a foreground service on the Android platform.
https://pub.dev/packages/flutter_foreground_task
MIT License
152 stars 111 forks source link

com.pravera.flutter_foreground_task.service.RebootReceiver Exception #283

Closed jaypokar closed 1 month ago

jaypokar commented 1 month ago

Fatal Exception: java.lang.RuntimeException Unable to start receiver com.pravera.flutter_foreground_task.service.RebootReceiver: android.content.pm.PackageManager$NameNotFoundException: ComponentInfo{partner.dropon.delivery/com.pravera.flutter_foreground_task.service.a}

Dev-hwang commented 1 month ago

hello, @jaypokar

try this

  1. The service name (android:name) should be as below.

    <!-- Warning: Do not change service name. -->
    <service 
    android:name="com.pravera.flutter_foreground_task.service.ForegroundService"
    android:foregroundServiceType="dataSync|remoteMessaging"
    android:exported="false" />
  2. goto android/app/proguard-rules.pro -> add -keep class com.pravera.flutter_foreground_task

    
    -keep class io.flutter.app.** { *; }
    -keep class io.flutter.plugin.**  { *; }
    -keep class io.flutter.util.**  { *; }
    -keep class io.flutter.view.**  { *; }
    -keep class io.flutter.**  { *; }
    -keep class io.flutter.plugins.**  { *; }
    -dontwarn io.flutter.embedding.**

-keep class com.pravera.flutter_foreground_task.* { ; }

jaypokar commented 1 month ago

I am not using the service at all, not even starting the service from this. I am using this only to check that my app is in foreground or to launch the app when it's in background that's it.

Dev-hwang commented 1 month ago

@jaypokar

I think this plugin does not suit your purpose.

You will need to add the service tag in manifest for this plugin to work properly.

jaypokar commented 1 month ago

actually I have updated this to latest version but it was working well before in flutter_foreground_task: ^6.5.0, which I have been using.

Dev-hwang commented 1 month ago

@jaypokar

you're right. In the new version, i check whether to restart the service by looking at the status of the service tag.

https://github.com/Dev-hwang/flutter_foreground_task/blob/dc012e5b1b0263f263b969af154d2d39b5264443/android/src/main/kotlin/com/pravera/flutter_foreground_task/service/RebootReceiver.kt#L23

An exception occurs if the component name cannot be found here.

https://github.com/Dev-hwang/flutter_foreground_task/blob/dc012e5b1b0263f263b969af154d2d39b5264443/android/src/main/kotlin/com/pravera/flutter_foreground_task/utils/ForegroundServiceUtils.kt#L14

However, the lower the possibility of exceptions occurring, the better, so this part will be handled as an exception in the next version.

Dev-hwang commented 1 month ago

You can fork this project and use it until a new version is published.

db2abe4a569b818978fabcfb25902101d0053050

Dev-hwang commented 1 month ago

@jaypokar

Version 8.10.4 has been published.

Please check and let me know if there are any problems.