rnmapbox / maps

A Mapbox react native module for creating custom maps
MIT License
2.27k stars 848 forks source link

Build issue for ios in MGLModule.m Multiple Errors - MapLibre SDK #1472

Closed f1sh1918 closed 3 years ago

f1sh1918 commented 3 years ago

Describe the bug
The IOS Build Process fails with multiple errors in MGLModule.m after adding react-native-mapbox lib and installing pods

To Reproduce

Podfile:

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '10.0'

target 'MapTest' do
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => false
  )

  target 'MapTestTests' do
    inherit! :complete
    # Pods for testing
  end

  $RNMBGL_Use_SPM = true

    pre_install do |installer|
      $RNMBGL.pre_install(installer)
    end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  use_flipper!()

  post_install do |installer|
    react_native_post_install(installer)
     $RNMBGL.post_install(installer)
  end
end

Expected behavior
Build runs successfully

Actual behavior
Build fails with multiple errors in MGLModule.m

 // style urls
    NSMutableDictionary *styleURLS = [[NSMutableDictionary alloc] init];
    [styleURLS setObject:[MGLStyle.streetsStyleURL absoluteString] forKey:@"Street"];
    [styleURLS setObject:[MGLStyle.darkStyleURL absoluteString] forKey:@"Dark"];
    [styleURLS setObject:[MGLStyle.lightStyleURL absoluteString] forKey:@"Light"];
    [styleURLS setObject:[MGLStyle.outdoorsStyleURL absoluteString] forKey:@"Outdoors"];
    [styleURLS setObject:[MGLStyle.satelliteStyleURL absoluteString] forKey:@"Satellite"];
    [styleURLS setObject:[MGLStyle.satelliteStreetsStyleURL absoluteString] forKey:@"SatelliteStreet"];
....
RCT_EXPORT_METHOD(setAccessToken:(NSString *)accessToken)
{
    [MGLAccountManager setAccessToken:accessToken];
}

Errors:

Bildschirmfoto 2021-07-26 um 15 57 44

Versions (please complete the following information):

Additional context
Build run on XCode 12.5.1

ferdicus commented 3 years ago

Can you try with the default pack in Mapbox ios sdk please instead of MapLibre

f1sh1918 commented 3 years ago

Downloading dependencies Installing Mapbox-iOS-SDK (5.9.0) Installing MapboxMobileEvents (0.10.2) Installing react-native-mapbox-gl 8.2.1

Rebuild project leads to the same errors

ferdicus commented 3 years ago

could you also please change the order of these:

  post_install do |installer|
    $RNMBGL.post_install(installer)
    react_native_post_install(installer)
  end
f1sh1918 commented 3 years ago

could you also please change the order of these:

  post_install do |installer|
    $RNMBGL.post_install(installer)
    react_native_post_install(installer)
  end

did not solve the issue unfortunately. Even the prebuilding fails because MGLStyle object is missing the types

ferdicus commented 3 years ago

but a vanilla react-native app, without any dependencies does work?!

ferdicus commented 3 years ago

or, what does happen when you try building the /example app?

f1sh1918 commented 3 years ago

yes it builds and loads in the emulator without any issues. I'm not using expo but react native cli

jutaz commented 3 years ago

I'm also seeing this happen in an application where we've upgraded to latest @react-native-mapbox-gl/maps and switched to Maplibre - both 5.12.0 and 5.11.0 seem to be broken:

Screen Shot 2021-07-26 at 18 58 25
noway commented 3 years ago

Happens to me too. Podfile:

platform :ios, '10.0'
plugin 'cocoapods-patch'

begin
  require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
rescue LoadError
  puts "WARNING: ../node_modules/@react-native-community/cli-platform-ios/native_modules couldn't be loaded. Should be fine if you're in prepenv"
end

project 'myapp',
    'Debug' => :debug,
    'Release' => :release,
    'DevDebug' => :debug,
    'DevRelease' => :release

target 'myapp' do
  $RNMBGL_Use_SPM = {
    url: "https://github.com/maplibre/maplibre-gl-native-distribution",
    requirement: {
      kind: "upToNextMajorVersion",
      minimumVersion: "5.11.0"
    },
    product_name: "Mapbox"
  }
  $ReactNativeMapboxGLIOSVersion = "6.3.0"

  # Pods for myapp
  pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
  pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
  pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
  pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
  pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
  pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
  pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
  pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
  pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
  pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
  pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
  pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
  pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'

  pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
  pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
  pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
  pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
  pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
  pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
  pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

  permissions_path = '../node_modules/react-native-permissions/ios'

  pod 'Permission-BluetoothPeripheral', :path => "#{permissions_path}/BluetoothPeripheral.podspec"
  pod 'Permission-Reminders', :path => "#{permissions_path}/Reminders.podspec"
  pod 'Permission-SpeechRecognition', :path => "#{permissions_path}/SpeechRecognition.podspec"
  pod 'Permission-FaceID', :path => "#{permissions_path}/FaceID.podspec"
  pod 'Permission-Contacts', :path => "#{permissions_path}/Contacts.podspec"
  pod 'Permission-MediaLibrary', :path => "#{permissions_path}/MediaLibrary.podspec"
  pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications.podspec"
  pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary.podspec"
  pod 'Permission-Camera', :path => "#{permissions_path}/Camera.podspec"
  pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone.podspec"
  pod 'Permission-Siri', :path => "#{permissions_path}/Siri.podspec"
  pod 'Permission-StoreKit', :path => "#{permissions_path}/StoreKit.podspec"
  pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways.podspec"
  pod 'Permission-Motion', :path => "#{permissions_path}/Motion.podspec"
  pod 'Permission-Calendars', :path => "#{permissions_path}/Calendars.podspec"
  pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse.podspec"

  pod 'Permission-AppTrackingTransparency', :path => "#{permissions_path}/AppTrackingTransparency.podspec"

  target 'myappTests' do
    inherit! :search_paths
    # Pods for testing
  end

  use_native_modules!
end

pre_install do |installer|
  fix_mapbox_events(installer)
  $RNMBGL.pre_install(installer)
end

post_install do |installer|
  $RNMBGL.post_install(installer)
end

def fix_mapbox_events(installer)
  installer.pod_targets.each do |pod|
    if pod.name == 'MapboxMobileEvents'
      def pod.build_type;
        Pod::BuildType.dynamic_framework
      end
    end
  end
end

puts "Podfile has been eval'd"

package.json:

    ...
    "react-native": "0.61.5",
    "@react-native-mapbox-gl/maps": "8.2.1",
    ...

react-native info:

warn Your project is using deprecated "rnpm" config that will stop working from next release. Please use a "react-native.config.js" file to configure the React Native CLI. Migration guide: https://github.com/react-native-community/cli/blob/master/docs/configuration.md
warn The following packages use deprecated "rnpm" config that will stop working from next release:
  - react-native-comparison-slider: https://npmjs.com/package/react-native-comparison-slider
  - react-native-orientation: https://github.com/yamill/react-native-orientation#readme
  - react-native-video: https://npmjs.com/package/react-native-video
  - react-native-zip-archive: https://github.com/mockingbot/react-native-zip-archive
Please notify their maintainers about it. You can find more details at https://github.com/react-native-community/cli/blob/master/docs/configuration.md#migration-guide.
info Fetching system and libraries information...
System:
    OS: macOS 11.3.1
    CPU: (8) arm64 Apple M1
    Memory: 106.03 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.5.0 - /var/folders/85/2xpmzxms1tsgzr9nqnhszzfw0000gn/T/yarn--1627356302717-0.9925064687240368/node
    Yarn: 1.22.10 - /var/folders/85/2xpmzxms1tsgzr9nqnhszzfw0000gn/T/yarn--1627356302717-0.9925064687240368/yarn
    npm: 7.19.1 - /opt/homebrew/bin/npm
    Watchman: 4.9.0 - /opt/homebrew/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
    Android SDK:
      API Levels: 23, 25, 27, 28, 29, 30
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3
      System Images: android-29 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom, android-30 | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: 4.1 AI-201.8743.12.41.7199119
    Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0
    react-native: 0.61.5 => 0.61.5
✨  Done in 15.25s.
f1sh1918 commented 3 years ago

@jutaz which package versions and podfile did you use before upgrading that worked?

jutaz commented 3 years ago

@f1sh1918 I've had:

(from podfile.lock):

@react-native-mapbox-gl-mapbox-static (5.8.0)
react-native-mapbox-gl (8.0.0)
Mapbox-iOS-SDK (5.9.0)
MapboxMobileEvents (0.10.2)

And:

in package.json:

@react-native-mapbox-gl/maps@8.0.0

I've switched to Maplibre in this change.

f1sh1918 commented 3 years ago

@jutaz When i downgrade to 8.0.0 i'm facing pre_install errors. How was your podfile looking? Do you have the pre & post_install hooks like this:

$RNMBGL.pre_install(installer)
jutaz commented 3 years ago

I do have them like so:

   pre_install do |installer|
     $RNMBGL.pre_install(installer)
   end
   post_install do |installer|
     flipper_post_install(installer)
     $RNMBGL.post_install(installer)
   end

Previously (@8.0.0) neither hook was present for $RNMBGL.

jutaz commented 3 years ago

FWIW this works beautifully on Android w/ Maplibre and the same versions of packages. So it seems like something is off w/ iOS

f1sh1918 commented 3 years ago

FWIW this works beautifully on Android w/ Maplibre and the same versions of packages. So it seems like something is off w/ iOS

Is there a configuration with mapbox 5.x working on android and ios for you? I even get the same errors using mapbox instead of maplibre, even with @8.0.0

Update: I just had to remove swift package of MapLibre manually to get normal mapBox work ;)

ferdicus commented 3 years ago

Can everyone observing this issue let me know which version is actually downloaded and used in
XCode > PROJECT > Swift Packages??

My suspicion is, that it actually downloads version 5.12.0 of MapLibre, because these are the requirements that are used when nothing specific is defined (and you aren't on master):

    requirement: {
      kind: "upToNextMajorVersion",
      minimumVersion: "5.11.0"
    }

You can circumvent this by adding this to your Podfile:

  $RNMBGL_Use_SPM = {
    url: "https://github.com/maplibre/maplibre-gl-native-distribution",
    requirement: {
        kind: "exactVersion",
        version: "5.11.0"
    },
    product_name: "Mapbox"
  }

Make sure to previously remove the current swift package download in XCode, just to be sure. πŸ‘πŸΏ

@jutaz, reason why it probably works in Android is, that it doesn't use something like this upToNextMajorVersion. Could you try with android-v9.5.0 and report back please if you find the time? Thanks in advance πŸ™‡πŸΏ

jutaz commented 3 years ago

@ferdicus you are absolutely correct - it did download 5.12.0 of MapLibre. Applied your suggestion and now it builds. however it seem to crash when running the app with 5.11.0 (though probably not related to the original issue):

2021-07-30 14:24:59.955555+0300 app[64582:3617029] Failed to make complete framebuffer object 8cd6
2021-07-30 14:25:02.958816+0300 app[64582:3617029] Failed to bind EAGLDrawable: <CAEAGLLayer: 0x600000bb9ac0> to GL_RENDERBUFFER 1
libc++abi: terminating with uncaught exception of type std::domain_error
terminating with uncaught exception of type std::domain_error
CoreSimulator 757.5 - Device: iPhone 12 (C9643721-E984-49ED-9F0C-9A53CFF6E894) - Runtime: iOS 14.5 (18E182) - DeviceType: iPhone 12

After deeper digging it looks like it's fixed in 5.13.0 - I'll try building on x86 now (I was building on arm64 M1).

I'll also test on Android πŸ‘

jutaz commented 3 years ago

Hrm, look like I'm seeing exactly the same crash on x86 when trying to open up the map. Rest of the app seems to work just fine, however.

ferdicus commented 3 years ago

hmm, yeah - the complication with M1 chipsets certainly doesn't help πŸ˜…

I was building fine with 5.11.0 on pre M1 MacBook for ARM64 architecture.

My assumption why it doesn't build for anything post that, is probably this change: https://github.com/maplibre/maplibre-gl-native/pull/90 Which "replac[es] hardcoded configuration with configurable API and remov[ed] Mapbox assets and dependencies"

ferdicus commented 3 years ago

Also build under Release configuration onto a device (iPad mini 5. Gen) - worked fine with 5.11.0 also opened map and all πŸ‘πŸΏ

f1sh1918 commented 3 years ago

@ferdicus @jutaz

thx for the great support :)

I can confirm that maplibre 5.11 is working fine. Just had to remove manually version 5.12 swift package before installing v5.11.

ferdicus commented 3 years ago

@ferdicus @jutaz

thx for the great support :)

I can confirm that maplibre 5.11 is working fine. Just had to remove manually version 5.12 swift package before installing v5.11.

Great to hear πŸ‘πŸΏ

I'll close this ticket then

noway commented 3 years ago

yeah it worked for me too. thanks ferdicus!

mvanroon commented 3 years ago

Pinning Maplibre version 5.11 fixes the build, but this critical bug was fixed in Maplibre 5.12. Does anyone know of a way to make this library work with Maplibre >= 5.12.0 ?

ferdicus commented 3 years ago

Pinning Maplibre version 5.11 fixes the build, but this critical bug was fixed in Maplibre 5.12. Does anyone know of a way to make this library work with Maplibre >= 5.12.0 ?

Making MapLibre 5.12 work is a non-trivial undertaking, which atm no one is working on afaik

mvanroon commented 3 years ago

Pinning Maplibre version 5.11 fixes the build, but this critical bug was fixed in Maplibre 5.12. Does anyone know of a way to make this library work with Maplibre >= 5.12.0 ?

Making MapLibre 5.12 is a non-trivial undertaking, which atm no one is working on afaik

Users are seeing crashes happen on a regular base. We're seeing the same thing. Sounds trivial to me.

ferdicus commented 3 years ago

Pinning Maplibre version 5.11 fixes the build, but this critical bug was fixed in Maplibre 5.12. Does anyone know of a way to make this library work with Maplibre >= 5.12.0 ?

Making MapLibre 5.12 is a non-trivial undertaking, which atm no one is working on afaik

Users are seeing crashes happen on a regular base. We're seeing the same thing. Sounds trivial to me.

Sorry, my message was missing a word "work".
I'm not saying the issue at hand is trivial - making MapLibre work 5.12 is non-trivial. It will require some rework on the repo and could potentially hinder support for MapBox v10 SDKs moving forward...

mvanroon commented 3 years ago

Gotcha! Thanks!

tomgreco commented 3 years ago

@ferdicus any idea if/when MapLibre 5.12 will be supported?

I cannot run on iOS simulator with 5.11 because of issue similar to this: https://github.com/react-native-mapbox-gl/maps/issues/1355#issuecomment-928994988

And Apple review team will reject the app if it crashes on simulator.

ferdicus commented 3 years ago

@ferdicus any idea if/when MapLibre 5.12 will be supported?

I cannot run on iOS simulator with 5.11 because of issue similar to this: #1355 (comment)

And Apple review team will reject the app if it crashes on simulator.

Nope, nothing on the roadmap yet

mfazekas commented 3 years ago

I've added a fix for this: #1571

You can test this using react-native-mapbox-gl/maps#mfazekas/map-libre-support in your package.json

yurilawnguru commented 2 years ago

I'm still facing the error using the maplibre v5.12, have you guys find any solution?