maps: [Bug]: Build failed cannot find symbol mEventEmitterCallback.invoke("onLocationUpdate", value);

Mapbox Implementation

Mapbox

Mapbox Version

default

React Native Version

0.72.10

Platform

Android

@rnmapbox/maps version

10.1.8

Standalone component to reproduce

import React from 'react';
import {
  MapView,
  ShapeSource,
  LineLayer,
  Camera,
} from '@rnmapbox/maps';

const aLine = {
  type: 'LineString',
  coordinates: [
    [-74.00597, 40.71427],
    [-74.00697, 40.71527],
  ],
};

class BugReportExample extends React.Component {
  render() {
    return (
      <MapView style={{flex: 1}}>
        <Camera centerCoordinate={[-74.00597, 40.71427]} zoomLevel={14} />
        <ShapeSource id="idStreetLayer" shape={aLine}>
          <LineLayer id="idStreetLayer" />
        </ShapeSource>
      </MapView>
    );
  }
}

Observed behavior and steps to reproduce

Build failed with this error:

> Task :rnmapbox_maps:compileDebugJavaWithJavac
C:\Users\mbaga\Lab\wisili-rider-app\node_modules\@rnmapbox\maps\android\src\main\old-arch\com\rnmapbox\rnmbx\NativeRNMBXLocationModuleSpec.java:38: error: cannot find symbol
    mEventEmitterCallback.invoke("onLocationUpdate", value);
    ^
  symbol:   variable mEventEmitterCallback
  location: class NativeRNMBXLocationModuleSpec
1 error

Expected behavior

No response

Notes / preliminary analysis

No response

Additional links and references

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 6
  • Comments: 18

Most upvoted comments

Here is the temporary Fix ✅

Manually Edit the Package Code

Edit the file:

node_modules/@rnmapbox/maps/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeRNMBXLocationModuleSpec.java

Add import

import com.facebook.react.bridge.Callback;

Add private Callback mEventEmitterCallback in class NativeRNMBXLocationModuleSpec

public abstract class NativeRNMBXLocationModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
    private Callback mEventEmitterCallback; // ✅ Correct placement inside class

Edit the emitOnLocationUpdate and add null check for mEventEmitterCallback

protected final void emitOnLocationUpdate(ReadableMap value) {
    if (mEventEmitterCallback != null) {
        mEventEmitterCallback.invoke("onLocationUpdate", value);
    }
  }

Now patch the package for Auto Package update each time you tigger npm i.

npm i patch-package

Run this in root of your project **npx patch-package @rnmapbox/maps**

Add this in your “scripts” in project package.json "postinstall": "patch-package"

It works with v10.1.36, which is only one version downgrade from the latest one.

Ok, after some research I’ve found the following:

  • rnmapbox v10.1.37 depends on react native 0.76.x
  • in RN 0.76.x new architecture is enabled by default
  • the field mEventEmitterCallback was added to RN 0.76.x in PR https://github.com/facebook/react-native/pull/44906 to support TurboModules
  • support for TurboModules was added to rnmapbox at PR https://github.com/rnmapbox/maps/pull/3789, using the new field mEventEmitterCallback present only in RN 0.76.x
  • the class using TurboModules is included in the rnmapbox android sources only when isNewArchitecture=false in gradle.properties

In short:

  • rnmapbox v10.1.37 supports only RN >= 0.76.x

using RN < 0.76.x with isNewArchitecture=true in gradle.properties is not an option due to how the changes were implemented at PR https://github.com/rnmapbox/maps/pull/3789 if you want to support older RN versions add the patch described by @Rahul-Ranjan-Singh at https://github.com/rnmapbox/maps/issues/3795#issuecomment-2697844403

Confirming we’ve also had this same issue in our development after upgrading to latest from 10.1.33 to 10.1.37 on both Android and iOS builds. Rolling back one patch version to 10.1.36 has resolved the problem for us too.

Having same issue.

“react-native”: “0.73.6”, “expo”: “^50.0.18”, “@rnmapbox/maps”: “^10.1.33”,

tried the following versions for rnmapbox and still facing the issue: ^10.1.33, ^10.1.36, ^10.1.37, ^10.1.38

I’m able to fix using the version 10.1.38 and by following this: https://github.com/rnmapbox/maps/issues/3795#issuecomment-2697844403

Having same issue.

“react-native”: “0.73.6”, “expo”: “^50.0.18”, “@rnmapbox/maps”: “^10.1.33”,

tried the following versions for rnmapbox and still facing the issue: ^10.1.33, ^10.1.36, ^10.1.37, ^10.1.38