transistorsoft / flutter_background_fetch

Periodic callbacks in the background for both IOS and Android. Includes Android Headless mechanism
MIT License
571 stars 166 forks source link

[BUG] my app stops working after kill the app #127

Closed is10vmust closed 3 years ago

is10vmust commented 4 years ago

Your Environment

MY LOGCAT

2020-06-14 18:44:33.083 1919-1919/com.google.android.gms.persistent E/BeaconBle: Scan couldn't start for Places
2020-06-14 18:44:33.084 1919-1919/com.google.android.gms.persistent W/Places: BLE failure while scanning - code 5
2020-06-14 18:44:33.087 1919-13806/com.google.android.gms.persistent I/Places: ?: Couldn't find platform key file.
2020-06-14 18:44:33.104 2934-13481/com.google.android.googlequicksearchbox:search E/PlaceStateUpdater: Received no places
2020-06-14 18:44:33.106 2934-13481/com.google.android.googlequicksearchbox:search E/PlaceStateUpdater: Received no places
2020-06-14 18:44:33.107 2934-13478/com.google.android.googlequicksearchbox:search E/PlaceStateUpdater: Received no places
2020-06-14 18:44:33.107 2934-13481/com.google.android.googlequicksearchbox:search E/PlaceStateUpdater: Received no places
2020-06-14 18:44:33.109 2934-13481/com.google.android.googlequicksearchbox:search I/chatty: uid=10030(u0_a30) NonUserFacing17 identical 1 line
2020-06-14 18:44:33.109 2934-13481/com.google.android.googlequicksearchbox:search E/PlaceStateUpdater: Received no places
2020-06-14 18:44:33.111 2934-13478/com.google.android.googlequicksearchbox:search E/PlaceStateUpdater: Received no places
2020-06-14 18:44:33.114 2934-13481/com.google.android.googlequicksearchbox:search E/PlaceStateUpdater: Received no places
2020-06-14 18:44:33.114 2934-13478/com.google.android.googlequicksearchbox:search E/PlaceStateUpdater: Received no places
2020-06-14 18:44:33.116 2934-13478/com.google.android.googlequicksearchbox:search I/chatty: uid=10030(u0_a30) NonUserFacing17 identical 1 line
2020-06-14 18:44:33.117 2934-13478/com.google.android.googlequicksearchbox:search E/PlaceStateUpdater: Received no places
2020-06-14 18:44:33.348 13112-13159/com.google.android.apps.nexuslauncher W/OpenGLRenderer: Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
2020-06-14 18:44:34.451 13318-13318/com.ensperity.projectcoronas D/TSBackgroundFetch: - Background Fetch event received
2020-06-14 18:44:34.453 13318-13318/com.ensperity.projectcoronas D/TSBackgroundFetch: 💀 [HeadlessTask com.transistorsoft.customtask]
2020-06-14 18:44:34.467 13318-13318/com.ensperity.projectcoronas D/EGL_emulation: eglCreateContext: 0xa2a8efe0: maj 3 min 1 rcv 4
2020-06-14 18:44:34.499 13318-13968/com.ensperity.projectcoronas D/EGL_emulation: eglMakeCurrent: 0xa2a8efe0: ver 3 1 (tinfo 0xa2d83d60)
2020-06-14 18:44:34.504 13318-13968/com.ensperity.projectcoronas E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
2020-06-14 18:44:34.504 13318-13968/com.ensperity.projectcoronas E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
2020-06-14 18:44:34.573 13318-13318/com.ensperity.projectcoronas D/BeaconParser: Parsing beacon layout: m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24
2020-06-14 18:44:34.577 13318-13318/com.ensperity.projectcoronas W/FlutterEnginePluginRegistry: Attempted to register plugin (io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry$ShimRegistrarAggregate@fb16e92) but it was already registered with this FlutterEngine (io.flutter.embedding.engine.FlutterEngine@528c063).
2020-06-14 18:44:34.577 13318-13318/com.ensperity.projectcoronas E/MethodChannel#: Parameter messenger must not be null.
2020-06-14 18:44:34.577 13318-13318/com.ensperity.projectcoronas E/MethodChannel#: Parameter messenger must not be null.
2020-06-14 18:44:34.577 13318-13318/com.ensperity.projectcoronas D/AndroidRuntime: Shutting down VM
2020-06-14 18:44:34.578 13318-13318/com.ensperity.projectcoronas E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.ensperity.projectcoronas, PID: 13318
    java.lang.NullPointerException: Attempt to invoke interface method 'void io.flutter.plugin.common.BinaryMessenger.setMessageHandler(java.lang.String, io.flutter.plugin.common.BinaryMessenger$BinaryMessageHandler)' on a null object reference
        at io.flutter.plugin.common.MethodChannel.setMethodCallHandler(MethodChannel.java:116)
        at io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.onAttachedToEngine(FirebaseMessagingPlugin.java:62)
        at io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(FirebaseMessagingPlugin.java:52)
        at com.ensperity.projectcoronas.FirebaseCloudMessagingPluginRegistrant$Companion.registerWith(FirebaseCloudMessagingPluginRegistrant.kt:12)
        at com.ensperity.projectcoronas.Application.registerWith(Application.kt:20)
        at com.transistorsoft.flutter.backgroundfetch.HeadlessTask.startBackgroundIsolate(HeadlessTask.java:150)
        at com.transistorsoft.flutter.backgroundfetch.HeadlessTask.dispatch(HeadlessTask.java:101)
        at com.transistorsoft.flutter.backgroundfetch.HeadlessTask.run(HeadlessTask.java:95)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
2020-06-14 18:44:34.580 13318-13318/com.ensperity.projectcoronas E/TSLocationManager: [c.t.l.a.BackgroundGeolocation$e uncaughtException] 
      ‼️  Uncaught Exception: Attempt to invoke interface method 'void io.flutter.plugin.common.BinaryMessenger.setMessageHandler(java.lang.String, io.flutter.plugin.common.BinaryMessenger$BinaryMessageHandler)' on a null object reference
    {"activityRecognitionInterval":10000,"allowIdenticalLocations":false,"authorization":{},"autoSync":true,"autoSyncThreshold":0,"batchSync":false,"configUrl":"","debug":false,"deferTime":0,"desiredAccuracy":-1,"desiredOdometerAccuracy":100,"disableAutoSyncOnCellular":false,"disableElasticity":false,"disableLocationAuthorizationAlert":false,"disableMotionActivityUpdates":false,"disableStopDetection":false,"distanceFilter":10,"elasticityMultiplier":1,"enableHeadless":true,"enableTimestampMeta":false,"encrypt":false,"extras":{},"fastestLocationUpdateInterval":-1,"forceReloadOnBoot":false,"forceReloadOnGeofence":false,"forceReloadOnHeartbeat":false,"forceReloadOnLocationChange":false,"forceReloadOnMotionChange":false,"forceReloadOnSchedule":false,"foregroundService":true,"geofenceInitialTriggerEntry":true,"geofenceModeHighAccuracy":false,"geofenceProximityRadius":1000,"geofenceTemplate":"","headers":{},"headlessJobService":"com.transistorsoft.flutter.backgroundgeolocation.HeadlessTask","heartbeatInterval":60,"httpRootProperty":"location","httpTimeout":60000,"isMoving":false,"locationAuthorizationRequest":"Always","locationTemplate":"","locationTimeout":60,"locationUpdateInterval":1000,"locationsOrderDirection":"ASC","logLevel":5,"logMaxDays":3,"maxBatchSize":-1,"maxDaysToPersist":1,"maxRecordsToPersist":-1,"method":"POST","minimumActivityRecognitionConfidence":75,"notification":{"layout":"","title":"","text":"Location Service activated","color":"","channelName":"TSLocationManager","smallIcon":"","largeIcon":"","priority":0,"strings":{},"actions":[]},"params":{},"persist":true,"persistMode":2,"schedule":[],"scheduleUseAlarmManager":false,"speedJumpFilter":300,"startOnBoot":true,"stationaryRadius":25,"stopAfterElapsedMinutes":0,"stopOnStationary":false,"stopOnTerminate":false,"stopTimeout":1,"triggerActivities":"on_foot, walking, running, in_vehicle, on_bicycle","url":"","useSignificantChangesOnly":false,"enabled":true,"schedulerEnabled":false,"trackingMode":1,"odometer":0,"isFirstBoot":false,"didLaunchInBackground":false}
    java.lang.NullPointerException: Attempt to invoke interface method 'void io.flutter.plugin.common.BinaryMessenger.setMessageHandler(java.lang.String, io.flutter.plugin.common.BinaryMessenger$BinaryMessageHandler)' on a null object reference
        at io.flutter.plugin.common.MethodChannel.setMethodCallHandler(MethodChannel.java:116)
        at io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.onAttachedToEngine(FirebaseMessagingPlugin.java:62)
        at io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(FirebaseMessagingPlugin.java:52)
        at com.ensperity.projectcoronas.FirebaseCloudMessagingPluginRegistrant$Companion.registerWith(FirebaseCloudMessagingPluginRegistrant.kt:12)
        at com.ensperity.projectcoronas.Application.registerWith(Application.kt:20)
        at com.transistorsoft.flutter.backgroundfetch.HeadlessTask.startBackgroundIsolate(HeadlessTask.java:150)
        at com.transistorsoft.flutter.backgroundfetch.HeadlessTask.dispatch(HeadlessTask.java:101)
        at com.transistorsoft.flutter.backgroundfetch.HeadlessTask.run(HeadlessTask.java:95)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

My Config

allowIdenticalLocations: false, triggerActivities: 'on_foot, walking, running, in_vehicle, on_bicycle', desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH, reset: true, debug: false, logLevel: bg.Config.LOG_LEVEL_VERBOSE, distanceFilter: 50.0, //aman-50 stopTimeout: 1, autoSync: true, stopOnTerminate: false, foregroundService: true, startOnBoot: true, disableMotionActivityUpdates: true, enableHeadless: true,

My Headless in foreground everything is ok but when i kill the app the headless run the code faster x10 this is my headless method:

void backgroundGeolocationHeadlessTask(bg.HeadlessEvent headlessEvent) async {
print("LOCATION PLUG-IN in BACKGROUND...");

PreferenceUtils.init();
kill();
bleStatus();
checkInternet();
gps();
// checkInterNetLive();
BLE().scan();
DatabaseHelper helper = new DatabaseHelper();
helper.initializeDatabase();
getUserLocation(helper);
}

Debug logs W/FlutterEnginePluginRegistry(11730): Attempted to register plugin (io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry$ShimRegistrarAggregate@90a06e1) but it was already registered with this FlutterEngine (io.flutter.embedding.engine.FlutterEngine@a63ac06).

Additional context this happened after i set the switch event on my headless, then everything works fine and good but every time i killed the app the app crashed and stopped working , Many thanks

christocracy commented 4 years ago

Your issue comes from io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.onAttachedToEngine(FirebaseMessagingPlugin.java:62)

christocracy commented 4 years ago

Provide the following files:

is10vmust commented 4 years ago

My Application.kt

package com.ensperity.projectcoronas

import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
import com.transistorsoft.flutter.backgroundgeolocation.FLTBackgroundGeolocationPlugin;
import com.transistorsoft.flutter.backgroundfetch.BackgroundFetchPlugin;

public class Application: FlutterApplication(), PluginRegistrantCallback {
  override fun onCreate() {
    super.onCreate()
    BackgroundFetchPlugin.setPluginRegistrant(this)
    FlutterFirebaseMessagingService.setPluginRegistrant(this)

  }

  override fun registerWith(registry: PluginRegistry) {
    FLTBackgroundGeolocationPlugin.setPluginRegistrant(this)
    FirebaseCloudMessagingPluginRegistrant.registerWith(registry)

  }
}
christocracy commented 4 years ago

Please learn to use Github syntax highlighting.

christocracy commented 4 years ago

I asked for 2 files, including AndroidManifest.xml

is10vmust commented 4 years ago
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.ensperity.projectcoronas">
    <!--
    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.
    -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
    <application tools:replace="android:label" android:name=".Application" android:label="Myapp" android:usesCleartextTraffic="true" android:icon="@mipmap/ic_launcher">
        <activity android:name=".MainActivity" 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">
            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <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>
        <meta-data android:name="com.transistorsoft.locationmanager.license" android:value="Redacted" />
        <meta-data android:name="com.transistorsoft.locationmanager.ENCRYPTION_PASSWORD" android:value="" />
        <meta-data android:name="flutterEmbedding" android:value="2" />
    </application>
</manifest>
christocracy commented 4 years ago

This line shows your app has been upgraded to flutter sdk >= 1.12. You no longer need a custom Application.kt.

<meta-data android:name="flutterEmbedding" android:value="2" />

See the Android Setup

Modify your AndroidManifest.xml

<application
+        android:name="io.flutter.app.FlutterApplication"
is10vmust commented 4 years ago

This line shows your app has been upgraded to flutter sdk >= 1.12. You no longer need a custom Application.kt.

<meta-data android:name="flutterEmbedding" android:value="2" />

See the Android Setup

Modify your AndroidManifest.xml

<application
+        android:name="io.flutter.app.FlutterApplication"

i applied this changes and after that the background not worked at all

christocracy commented 4 years ago

Then you must figure out that problem.

Do NOT use a custom Application.kt with Flutter sdk >= 1.12

dimple3695 commented 4 years ago

This line shows your app has been upgraded to flutter sdk >= 1.12. You no longer need a custom Application.kt.

<meta-data android:name="flutterEmbedding" android:value="2" />

See the Android Setup Modify your AndroidManifest.xml

<application
+        android:name="io.flutter.app.FlutterApplication"

i applied this changes and after that the background not worked at all

I also same issue? If your problem resolved Please Can you suggest me how to solve it?

uzirthapa commented 4 years ago

I Ran the example application for iOS and when I kill the application, and try to open it again, the app crashes on startup. Any fixes for this?

Also, please let me know if you need more details.

My version is iOS 14.0 and using on IPhone XR

christocracy commented 4 years ago

If the app crashes, provided the stacktrace here.

uzirthapa commented 4 years ago

When launching through XCode it is okay, this only happens once you kill the app and then try to reopen it.

Here are the logs from the device for the example app

Incident Identifier: 61E75D87-D8DE-4A34-B2D6-86465315A518 CrashReporter Key: bd243a2ec0e9193d3e47b9dcc99ec8e558b91db9 Hardware Model: iPhone11,8 Process: Runner [18851] Path: /private/var/containers/Bundle/Application/BC0F6237-72AD-4FE9-97F1-BAF5A66EEDF4/Runner.app/Runner Identifier: com.transistorsoft.flutter.backgroundfetch.backgroundFetchExample Version: 1 (1.0.0) Code Type: ARM-64 (Native) Role: Foreground Parent Process: launchd [1] Coalition: com.transistorsoft.flutter.backgroundfetch.backgroundFetchExample [2048]

Date/Time: 2020-07-09 07:38:48.2077 -0500 Launch Time: 2020-07-09 07:38:47.9566 -0500 OS Version: iPhone OS 14.0 (18A5301v) Release Type: Beta Baseband Version: 2.50.07 Report Version: 104

Exception Type: EXC_BAD_ACCESS (SIGKILL - CODESIGNING) Exception Subtype: UNKNOWN_0x32 at 0x000000010ae81d60 VM Region Info: 0x10ae81d60 is in 0x10ae80000-0x10af00000; bytes after start: 7520 bytes before end: 516767 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL VM_ALLOCATE 10ae00000-10ae80000 [ 512K] r--/rwx SM=PRV
---> VM_ALLOCATE 10ae80000-10af00000 [ 512K] r-x/rwx SM=COW
MALLOC_LARGE 10af00000-10af10000 [ 64K] rw-/rwx SM=PRV

Termination Reason: Namespace CODESIGNING, Code 0x2 Triggered by Thread: 7

christocracy commented 4 years ago
Termination Reason: Namespace CODESIGNING

Open your app in XCode and configure your code-signing as required.

christocracy commented 4 years ago

Also see this that I found while googling "Termination Reason: Namespace CODESIGNING".

uzirthapa commented 4 years ago

I do have XCode Automatically Signing for me as well. I am trying the release build to see if that works.

Screen Shot 2020-07-09 at 7 58 35 AM

uzirthapa commented 4 years ago

The release build works! But its interesting that if I close the app in debug mode, it crashes on restart. Will see if we can find a better solution for that. Otherwise I will work with the release build for now.

Thank you!

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.

stale[bot] commented 3 years ago

Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.