nitaliano / react-native-mapbox-gl

A Mapbox GL react native module for creating custom maps
Other
2.16k stars 697 forks source link

Runtime errors when building for Android after ejecting from Expo #1608

Closed aratcliffe closed 5 years ago

aratcliffe commented 5 years ago

Hi, I'm struggling to get my app running on Android. Unfortunately I come from a web background and have no experience with native app development. I created my app with Expo, ejected with ExpoKit and following the iOS installation instructions (using Cocoapods) I was able to get it running on the iOS simulator without any issues. For Android I ran "react-native link" and was able to a development build ok. However when running on the simulator I was unable to access the app as it required a permission to draw over apps which the UI would not allow me to accept (a known Expo issue). I tried doing a signed release build and deployed that to the simulator but got a runtime error. Looking at issues others have experienced I switched to using the master version of react-native-mapbox-gl but got a build error related to different versions being used for the compile and runtime classpath. I was able to resolve that issue by adding the following code to my root build.gradle:

subprojects { project.configurations.all { resolutionStrategy.eachDependency { details -> if (details.requested.group == 'com.android.support' && !details.requested.name.contains('multidex') ) { details.useVersion "28.0.0" } } } }

Now I can do a release build but get the following runtime error:

Uncaught Error: Native module com.mapbox.rctmgl.mdodules.RCTMGLModule tried to override com.mapbox.rctmgl.module.RCTMGLModule for module name RCTMGLModule. Check the getPackages() method in MainApplication.java, it might be that the module is being created twice.

I've run out of ideas of how to proceed so any help would be most welcome.

ferdicus commented 5 years ago

hey @aratcliffe, I'm no android crack myself, however the error message gives some hints to what might cause the issue: Check the getPackages() method in MainApplication.java, it might be that the module is being created twice.

Did you check MainApplication.java?

in it's getPackages() method it should look something like this:

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          // probably more packages
          new RCTMGLPackage() // mapbox package, should only be there once
      );
    }

Additionally you might want to check the installation guide and make sure, that the react-native link command actually did all the changes that are necessary: https://github.com/nitaliano/react-native-mapbox-gl/blob/master/android/install.md

Hope this helps

aratcliffe commented 5 years ago

hey @ferdicus thanks for pointing me in the right direction. It appears that the mapbox package was indeed being added twice - must have happened with running react-native link twice. I needed to also disable proguard to eliminate the next error "RCTMGLAndroidTextureMapView" was not found in the UIManager.

The app now runs but Expo reports there was an error but the error log is empty. As this appears to be more of an Expo issue now I'll try asking there.

Thanks for your help!