2

i'm trying to use mapbox in reactnative and as documented i follow everything but my app broking. please find the below exception for your reference null is not an object (evaluating 'MapboxGL.StyleURL'). Please help me

David Leuliette
  • 1,595
  • 18
  • 26

1 Answers1

0

I just have this issue and maybe this will help you.

I have followed the official documentation to integrate @react-native-mapbox-gl/maps, but it keeps telling me

null is not an object(evaluating 'MapboxGL.StyleURL')

for version 7.0.8~7.2.0 and

Native part of Mapbox React Native libraries were not registered properly, double check our native installation guides.

after version 8.0.0.

I have added the RCTMGLPackage in the MainApplication:

public class MainApplication extends Application implements ReactApplication {

    private final ReactNativeHost mReactNativeHost =
            new ReactNativeHost(this) {
                @Override
                public boolean getUseDeveloperSupport() {
                    return BuildConfig.DEBUG;
                }

                @Override
                protected List<ReactPackage> getPackages() {
                    @SuppressWarnings("UnnecessaryLocalVariable")
                    List<ReactPackage> packages = new PackageList(this).getPackages();
                    packages.add(new MainReactPackage());
                    packages.add(new RCTMGLPackage());
                    return packages;
                }

                @Override
                protected String getJSMainModuleName() {
                    return "index";
                }
            };

    @Override
    public ReactNativeHost getReactNativeHost() {
        return mReactNativeHost;
    }
}

But still not work every time.

After checking the existing code, it has other places to add Native Module package in Activity.

in MainActivity :

mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(this.getApplication())
                .setBundleAssetName("index.android.bundle")
                .setJSMainModulePath("index")
                .addPackage(new MainReactPackage())
                .addPackage(new RCTMGLPackage())
                .setCurrentActivity(this)
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();

Not sure if you have the same case, may this will help you.

Phillip
  • 801
  • 10
  • 13