rekabhq / background_locator

A Flutter plugin for updating location in background.
MIT License
290 stars 339 forks source link

[ANDROID] App crash on start backgroud locator service [NullPointerException: Attempt to read from field 'java.lang.String io.flutter.view.FlutterCallbackInformation.callbackLibraryPath' on a null object reference] #267

Open joandervieira opened 3 years ago

joandervieira commented 3 years ago

The background locator do not start on Android:

Log error:

D/BackgroundLocatorPlugin( 4983): start locator with Google client
D/EGL_emulation( 4983): eglCreateContext: 0x7b11e1b600: maj 3 min 0 rcv 3
D/EGL_emulation( 4983): eglCreateContext: 0x7b11e2df00: maj 3 min 0 rcv 3
D/HostConnection( 4983): HostConnection::get() New Host Connection established 0x7b21da1d10, tid 5225
D/HostConnection( 4983): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_3_0 
D/EGL_emulation( 4983): eglMakeCurrent: 0x7b11e2df00: ver 3 0 (tinfo 0x7ab1e75de0) (first time)
D/AndroidRuntime( 4983): Shutting down VM
E/AndroidRuntime( 4983): FATAL EXCEPTION: main
E/AndroidRuntime( 4983): Process: com.battletag.battletag_field, PID: 4983
E/AndroidRuntime( 4983): java.lang.RuntimeException: Unable to create service rekab.app.background_locator.IsolateHolderService: java.lang.NullPointerException: Attempt to read from field 'java.lang.String io.flutter.view.FlutterCallbackInformation.callbackLibraryPath' on a null object reference
E/AndroidRuntime( 4983):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:4204)
E/AndroidRuntime( 4983):    at android.app.ActivityThread.access$1500(ActivityThread.java:237)
E/AndroidRuntime( 4983):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
E/AndroidRuntime( 4983):    at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 4983):    at android.os.Looper.loop(Looper.java:223)
E/AndroidRuntime( 4983):    at android.app.ActivityThread.main(ActivityThread.java:7656)
E/AndroidRuntime( 4983):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 4983):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/AndroidRuntime( 4983):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/AndroidRuntime( 4983): Caused by: java.lang.NullPointerException: Attempt to read from field 'java.lang.String io.flutter.view.FlutterCallbackInformation.callbackLibraryPath' on a null object reference
E/AndroidRuntime( 4983):    at io.flutter.embedding.engine.dart.DartExecutor$DartCallback.toString(DartExecutor.java:357)
E/AndroidRuntime( 4983):    at java.lang.String.valueOf(String.java:2924)
E/AndroidRuntime( 4983):    at java.lang.StringBuilder.append(StringBuilder.java:132)
E/AndroidRuntime( 4983):    at io.flutter.embedding.engine.dart.DartExecutor.executeDartCallback(DartExecutor.java:150)
E/AndroidRuntime( 4983):    at rekab.app.background_locator.IsolateHolderExtensionKt.startLocatorService(IsolateHolderExtension.kt:37)
E/AndroidRuntime( 4983):    at rekab.app.background_locator.IsolateHolderService.onCreate(IsolateHolderService.kt:64)
E/AndroidRuntime( 4983):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:4192)
E/AndroidRuntime( 4983):    ... 8 more

The AndroidManifest.xml file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.battletag.battletag_field">
    <!-- 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.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <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.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.VIBRATE" />

    <application android:name="io.flutter.app.FlutterApplication" android:label="COMANDO" android:icon="@mipmap/launcher_icon">
        <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">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme" />
            <!-- Displays an Android View that continues showing the launch screen
                 Drawable until Flutter paints its first frame, then this splash
                 screen fades out. A splash screen is useful to avoid any visual
                 gap between the end of Android's launch screen and the painting of
                 Flutter's first frame. -->
            <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>

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <!-- Accepts URIs that begin with YOUR_SCHEME://YOUR_HOST -->
                <data android:scheme="app" android:host="comando.app" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <!-- Accepts URIs that begin with YOUR_SCHEME://YOUR_HOST -->
                <data android:scheme="https" android:host="comando.app" />
            </intent-filter>

        </activity>

        <service android:name="rekab.app.background_locator.IsolateHolderService" android:permission="android.permission.FOREGROUND_SERVICE" android:exported="true"
            android:foregroundServiceType = "location"/>

        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data android:name="flutterEmbedding" android:value="2" />
    </application>
</manifest>

My android package:

print_android

The MainActivity.kt:

package com.battletag.battletag_field

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}

The 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);
    flutterEngine.getPlugins().add(new rekab.app.background_locator.BackgroundLocatorPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.firebase.firestore.FlutterFirebaseFirestorePlugin());
      io.flutter.plugins.firebase.functions.FlutterFirebaseFunctionsPlugin.registerWith(shimPluginRegistry.registrarFor("io.flutter.plugins.firebase.functions.FlutterFirebaseFunctionsPlugin"));
    flutterEngine.getPlugins().add(new io.flutter.plugins.connectivity.ConnectivityPlugin());
    flutterEngine.getPlugins().add(new com.mr.flutter.plugin.filepicker.FilePickerPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.firebase.auth.FlutterFirebaseAuthPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin());
    flutterEngine.getPlugins().add(new com.sidlatau.flutteremailsender.FlutterEmailSenderPlugin());
    flutterEngine.getPlugins().add(new app.meedu.flutter_facebook_auth.FlutterFacebookAuthPlugin());
    flutterEngine.getPlugins().add(new com.jrai.flutter_keyboard_visibility.FlutterKeyboardVisibilityPlugin());
    flutterEngine.getPlugins().add(new com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin());
    flutterEngine.getPlugins().add(new com.whelksoft.flutter_native_timezone.FlutterNativeTimezonePlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.flutter_plugin_android_lifecycle.FlutterAndroidLifecyclePlugin());
    flutterEngine.getPlugins().add(new com.baseflow.geolocator.GeolocatorPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.googlesignin.GoogleSignInPlugin());
    flutterEngine.getPlugins().add(new vn.hunghd.flutter.plugins.imagecropper.ImageCropperPlugin());
      com.codeheadlabs.libphonenumber.LibphonenumberPlugin.registerWith(shimPluginRegistry.registrarFor("com.codeheadlabs.libphonenumber.LibphonenumberPlugin"));
    flutterEngine.getPlugins().add(new com.example.libphonenumber_plugin.LibphonenumberPlugin());
    flutterEngine.getPlugins().add(new com.lyokone.location.LocationPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.packageinfo.PackageInfoPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.pathprovider.PathProviderPlugin());
    flutterEngine.getPlugins().add(new com.baseflow.permissionhandler.PermissionHandlerPlugin());
    flutterEngine.getPlugins().add(new li.jod.search_choices.SearchChoicesPlugin());
    flutterEngine.getPlugins().add(new com.zt.shareextend.ShareExtendPlugin());
    flutterEngine.getPlugins().add(new com.aboutyou.dart_packages.sign_in_with_apple.SignInWithApplePlugin());
    flutterEngine.getPlugins().add(new com.tekartik.sqflite.SqflitePlugin());
    flutterEngine.getPlugins().add(new name.avioli.unilinks.UniLinksPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.urllauncher.UrlLauncherPlugin());
  }
}

The flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.3, on macOS 11.5.1 20G80 darwin-arm, locale en-BR)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Android Studio (version 4.2)
[✓] VS Code (version 1.59.0)
[✓] Connected device (1 available)

• No issues found!
BartoszStasiurka commented 3 years ago

I have similar problem, I think. It's occurs after few minutes afer service starts.

2021-08-16 11:59:28.087 1296-1918/? E/ClipboardService: Denying clipboard access to com.example.test2, application is not in focus neither is a system service for user 0
2021-08-16 12:22:56.538 15490-15490/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.test2, PID: 15490
    java.lang.RuntimeException: Unable to create service rekab.app.background_locator.IsolateHolderService: java.lang.NullPointerException: Attempt to read from field 'java.lang.String io.flutter.view.FlutterCallbackInformation.callbackLibraryPath' on a null object reference
        at android.app.ActivityThread.handleCreateService(ActivityThread.java:4050)
        at android.app.ActivityThread.access$1700(ActivityThread.java:230)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1927)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:7551)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)
     Caused by: java.lang.NullPointerException: Attempt to read from field 'java.lang.String io.flutter.view.FlutterCallbackInformation.callbackLibraryPath' on a null object reference
        at io.flutter.embedding.engine.e.a$b.toString(Unknown Source:22)
        at java.lang.String.valueOf(String.java:2924)
        at java.lang.StringBuilder.append(StringBuilder.java:132)
        at io.flutter.embedding.engine.e.a.a(Unknown Source:22)
        at rekab.app.background_locator.b.a(Unknown Source:105)
        at rekab.app.background_locator.IsolateHolderService.onCreate(Unknown Source:3)
        at android.app.ActivityThread.handleCreateService(ActivityThread.java:4038)
        at android.app.ActivityThread.access$1700(ActivityThread.java:230)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1927)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:7551)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)
2021-08-16 12:23:00.723 15544-15544/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.test2, PID: 15544
    java.lang.UnsatisfiedLinkError: No implementation found for io.flutter.view.FlutterCallbackInformation io.flutter.embedding.engine.FlutterJNI.nativeLookupCallbackInformation(long) (tried Java_io_flutter_embedding_engine_FlutterJNI_nativeLookupCallbackInformation and Java_io_flutter_embedding_engine_FlutterJNI_nativeLookupCallbackInformation__J)
        at io.flutter.embedding.engine.FlutterJNI.nativeLookupCallbackInformation(Native Method)
        at io.flutter.view.FlutterCallbackInformation.lookupCallbackInformation(Unknown Source:0)
        at rekab.app.background_locator.b.a(Unknown Source:56)
        at rekab.app.background_locator.IsolateHolderService.onCreate(Unknown Source:3)
        at android.app.ActivityThread.handleCreateService(ActivityThread.java:4038)
        at android.app.ActivityThread.access$1700(ActivityThread.java:230)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1927)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:7551)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)
2021-08-16 12:53:24.563 17739-17739/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.test2, PID: 17739
    java.lang.UnsatisfiedLinkError: No implementation found for io.flutter.view.FlutterCallbackInformation io.flutter.embedding.engine.FlutterJNI.nativeLookupCallbackInformation(long) (tried Java_io_flutter_embedding_engine_FlutterJNI_nativeLookupCallbackInformation and Java_io_flutter_embedding_engine_FlutterJNI_nativeLookupCallbackInformation__J)
        at io.flutter.embedding.engine.FlutterJNI.nativeLookupCallbackInformation(Native Method)
        at io.flutter.view.FlutterCallbackInformation.lookupCallbackInformation(Unknown Source:0)
        at rekab.app.background_locator.b.a(Unknown Source:56)
        at rekab.app.background_locator.IsolateHolderService.onCreate(Unknown Source:3)
        at android.app.ActivityThread.handleCreateService(ActivityThread.java:4038)
        at android.app.ActivityThread.access$1700(ActivityThread.java:230)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1927)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:7551)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995) 
saravananmnm commented 3 years ago

@joandervieira have you override the below method from mainactivity?

@Override public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { GeneratedPluginRegistrant.registerWith(flutterEngine); }

mehdok commented 3 years ago

Hi @joandervieira Thank you for opening an issue;

This is the only place that I look into FlutterCallbackInformation.

https://github.com/rekab-app/background_locator/blob/b2fcb125001796f186189cbca970782da244c8f6/android/src/main/kotlin/rekab/app/background_locator/IsolateHolderExtension.kt#L26

please make sure you have a global callback function. You can also add some breakpoints around here and check if you can find more info;

memarv commented 3 years ago

Hi @mehdok

When system tries to restart foreground service (example after power manager app kills process) I get similar errors and service doesn't start:

java.lang.UnsatisfiedLinkError: No implementation found for io.flutter.view.FlutterCallbackInformation io.flutter.embedding.engine.FlutterJNI.nativeLookupCallbackInformation(long) (tried Java_io_flutter_embedding_engine_FlutterJNI_nativeLookupCallbackInformation and Java_io_flutter_embedding_engine_FlutterJNI_nativeLookupCallbackInformation__J)

You can simulate it via adb usingi the example app in this project:

adb shell am start-foreground-service rekab.app.background_locator_example/rekab.app.background_locator.IsolateHolderService

Before execute this command make sure you kill app rekab.app.background_locator_example

MoacirSchmidt commented 2 years ago

This error occurs when BackgroundLocator.initialize is not called

Habil24 commented 2 years ago

Experiencing same issue

hieudz commented 2 years ago

Anyone know how to fix? I'm experiencing the same issue