Skip to content

Android/Example: offline region manager broken #543

@felix-ht

Description

@felix-ht

For me none of the global function for managing offline regions work. The same issue also happens in the with the example app from the current master branch.

They fail with:

/MethodChannel#plugins.flutter.io/mapbox_gl( 9206): Failed to handle method call
E/MethodChannel#plugins.flutter.io/mapbox_gl( 9206): java.lang.NullPointerException: Attempt to invoke interface method 'android.content.Context io.flutter.plugin.common.PluginRegistry$Registrar.context()' on a null object reference
E/MethodChannel#plugins.flutter.io/mapbox_gl( 9206): 	at com.mapbox.mapboxgl.GlobalMethodHandler.onMethodCall(GlobalMethodHandler.java:61)
E/MethodChannel#plugins.flutter.io/mapbox_gl( 9206): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/MethodChannel#plugins.flutter.io/mapbox_gl( 9206): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#plugins.flutter.io/mapbox_gl( 9206): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:693)
E/MethodChannel#plugins.flutter.io/mapbox_gl( 9206): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/mapbox_gl( 9206): 	at android.os.MessageQueue.next(MessageQueue.java:335)
E/MethodChannel#plugins.flutter.io/mapbox_gl( 9206): 	at android.os.Looper.loop(Looper.java:183)
E/MethodChannel#plugins.flutter.io/mapbox_gl( 9206): 	at android.app.ActivityThread.main(ActivityThread.java:7656)
E/MethodChannel#plugins.flutter.io/mapbox_gl( 9206): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/mapbox_gl( 9206): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/MethodChannel#plugins.flutter.io/mapbox_gl( 9206): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

I added some debug code to onMethodCall in the GlobalMethodHandler

  @Override
    public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
        Log.d("offlineTEST", "onMethodCall -> " + methodCall.method);
        Log.d("offlineTEST", "onMethodCall registrar -> " + registrar);
        Log.d("offlineTEST", "onMethodCall flutterAssets -> " + flutterAssets);
        Log.d("offlineTEST", "onMethodCall context -> " + context);

this leads to the following output:

D/offlineTEST( 9206): onMethodCall -> getListOfRegions
D/offlineTEST( 9206): onMethodCall registrar -> null
D/offlineTEST( 9206): onMethodCall flutterAssets -> io.flutter.embedding.engine.FlutterEngineConnectionRegistry$DefaultFlutterAssets@9c135c7
D/offlineTEST( 9206): onMethodCall context -> androidx.multidex.MultiDexApplication@f70fc9

This might be related to #488 as the new plugin api does not provide a regsistar to the method handler:

new

    methodChannel.setMethodCallHandler(
      new GlobalMethodHandler(
        binding.getApplicationContext(),
        binding.getFlutterAssets()
      )
    );

old

    methodChannel.setMethodCallHandler(new GlobalMethodHandler(registrar));

Trying to get the context from the registrar that is null, is the cause for the error in final Context context = registrar.context();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions