mapbox / mapbox-navigation-ios

Turn-by-turn navigation logic and UI in Swift on iOS
https://docs.mapbox.com/ios/navigation/
Other
860 stars 310 forks source link

[Bug]: Missing XCFrameworks in v3.2.0 #4703

Closed emilianoalvarez91 closed 1 week ago

emilianoalvarez91 commented 1 month ago

Mapbox Navigation SDK version

v3.2.0

Steps to reproduce

Fetch the mapbox-navigation-ios package pointing to version 3.2.0.

From version 3.1.1 the navigation SDK could be added as xcframeworks, however since 3.2.0 MapboxNavigationCore and MapboxNavigationUIKit and their dependencies are not exposed as binaries.

My Project uses frameworks for modularization and if I add mapbox-navigation-ios as a swift package inside my framework and then add it to my app target the app fails to compile due to duplicated symbols. Therefore, I would require the dependencies as xcframeworks to manually add them.

Expected behavior

All artificts should be retrieved: _MapboxNavigationUXPrivate.xcframework; MapboxCoreMaps.xcframework; MapboxDirections.xcframework; MapboxMaps.xcframework; MapboxNavigationCore.xcframework; MapboxNavigationUIKit.xcframework; Turf.xcframework; MapboxNavigationNative.xcframework; MapboxCommon.xcframework.

Actual behavior

Only these are retrieved as XCFrameworks: MapboxCoreMaps.xcframework; MapboxNavigationNative.xcframework; MapboxCommon.xcframework.

Is this a one-time issue or a repeatable issue?

repeatable

kried commented 1 month ago

Hi @emilianoalvarez91

Thank you for the report.

The Nav SDK iOS is intended to be distributed as open source. We intentionally switched to the source code distribution for the Swift SDKs, as we did for the v2 SDK.

You can create local frameworks for the distributed libraries using the standard xcodebuild -create-xcframework command or by using some third party tools, like Scipio.

emilianoalvarez91 commented 1 month ago

Hi @kried, have you tried building the XCFrameworks on 3.2.0?

When using Scipio I'm getting the following error: Screenshot 2024-08-02 at 01 09 23

Which is exactly the same issue that I get when I'm trying to embed the framework when using SMP

image image image image

fbeccaceci commented 1 month ago

Hi @kried, have you tried building the XCFrameworks on 3.2.0?

When using Scipio I'm getting the following error: Screenshot 2024-08-02 at 01 09 23

Which is exactly the same issue that I get when I'm trying to embed the framework when using SMP

image image image image

I'm having the same problem, did you find a solution?

emilianoalvarez91 commented 1 month ago

Not yet, I'm still waiting for a solution on this

emilianoalvarez91 commented 3 weeks ago

Hi, @kried @chizhavko @volkdmitri the new framework distribution is not allowing to upgrade to the newest framework. I've tried the solution proposed by @kried but that's not working as there is something wrong in how MapboxNavigationCore is created.

Not being able to migrate to v3.2.0 is a serious issue as v3.1.1 doesn't allow you to use dynamic access tokens and forcing the only option to expose the access token in the info.plist.

I'm trying to upgrade since July 1st and still I'm unable to do so. What are the options to migrate to the newest versions of the framework?

kried commented 3 weeks ago

Hi @emilianoalvarez91

The Nav SDK iOS is distributed as source code, in both v3 and v2. It is the designated way for our library to distribute the release. We will support a second option to distribute the release as a framework, but at the moment I cannot guarantee the timeline.


As a temporary workaround, you can build local xcframework. Please note that in this case, you need to provide all dependencies as frameworks.

You can test the flow in a branch kried/framework-build. Execute sh scripts/build_frameworks.sh in the root directory and open the Examples/Examples.xcodeproj project.


I've tried the solution proposed by @kried but that's not working as there is something wrong in how MapboxNavigationCore is created.

On the screenshot, it is visible that the dependency MapboxNavigationNative was not added. You need to add all the compiled frameworks to the project to resolve missing symbol errors.

  1. You can update Package.swift: remove test targets and specify explicitly dependency on MapboxNavigationNative binary target. I attached the example Package.swift for v3.3.0. Package.swift.zip

  2. build the frameworks with Scipio by executing the following lines in the mapbox-navigation-ios directory:

    
    if [ ! -d "scipts/Scipio" ]; then
    git clone https://github.com/giginet/Scipio.git scipts/Scipio
    fi
    cd scipts/Scipio
    git checkout "0.21.0"
    swift build -c release

swift run -c release scipio create ../.. -f \ --platforms iOS \ --only-use-versions-from-resolved-file \ --enable-library-evolution \ --support-simulators \ --embed-debug-symbols \ --verbose


3. Update Framework Search Path in Xcode project to contain the build results from `$PROJECT_DIR/../XCFrameworks`
4. Embed the xcframeworks into the project. Please note that you need to embed all of the frameworks on the screenshots and not add the dependencies through SPM.
<img width="815" alt="Screenshot 2024-08-19 at 22 18 12" src="https://github.com/user-attachments/assets/18b96990-6db1-40c7-8475-d2621c997ae6">
emilianoalvarez91 commented 3 weeks ago

@kried thank you very much for the thorough response, I will check this tomorrow.

fbeccaceci commented 3 weeks ago

Hi @emilianoalvarez91

The Nav SDK iOS is distributed as source code, in both v3 and v2. It is the designated way for our library to distribute the release. We will support a second option to distribute the release as a framework, but at the moment I cannot guarantee the timeline.

As a temporary workaround, you can build local xcframework. Please note that in this case, you need to provide all dependencies as frameworks.

You can test the flow in a branch kried/framework-build. Execute sh scripts/build_frameworks.sh in the root directory and open the Examples/Examples.xcodeproj project.

I've tried the solution proposed by @kried but that's not working as there is something wrong in how MapboxNavigationCore is created.

On the screenshot, it is visible that the dependency MapboxNavigationNative was not added. You need to add all the compiled frameworks to the project to resolve missing symbol errors.

  1. You can update Package.swift: remove test targets and specify explicitly dependency on MapboxNavigationNative binary target. I attached the example Package.swift for v3.3.0. Package.swift.zip
  2. build the frameworks with Scipio by executing the following lines in the mapbox-navigation-ios directory:
if [ ! -d "scipts/Scipio" ]; then
    git clone https://github.com/giginet/Scipio.git scipts/Scipio
fi
cd scipts/Scipio
git checkout "0.21.0"
swift build -c release

swift run -c release scipio create ../.. -f \
    --platforms iOS  \
    --only-use-versions-from-resolved-file \
    --enable-library-evolution \
    --support-simulators \
    --embed-debug-symbols \
    --verbose
  1. Update Framework Search Path in Xcode project to contain the build results from $PROJECT_DIR/../XCFrameworks
  2. Embed the xcframeworks into the project. Please note that you need to embed all of the frameworks on the screenshots and not add the dependencies through SPM.
Screenshot 2024-08-19 at 22 18 12

Thanks @kried now i can build the frameworks correctly and they works included as you show, anyway i'm trying to include them as vedored_frameworks in a pod but i get some errors with duplicated declarations

Screenshot 2024-08-20 alle 10 01 28
kried commented 3 weeks ago

Thanks @kried now i can build the frameworks correctly and they works included as you show, anyway i'm trying to include them as vedored_frameworks in a pod but i get some errors with duplicated declarations

@fbeccaceci The problem is that if you add MapboxNavigation as frameworks, you should also use all its dependencies as frameworks. So you cannot use the public open source release of MapboxMaps, because it leads to the symbols duplications for the Maps SDK and its dependencies, like MapboxCommon.

On your screenshots, it looks like there are duplicate symbols for MapboxCommon. Please ensure that you don't use dependencies on the podsMapboxMaps in your podspec, but explicitly add them as frameworks.

fbeccaceci commented 3 weeks ago

This is my podspec

Pod::Spec.new do |s|
  s.name           = 'ExpoMapboxNavigation'
  s.version        = '1.0.0'
  s.summary        = 'A sample project summary'
  s.description    = 'A sample project description'
  s.author         = ''
  s.homepage       = 'https://docs.expo.dev/modules/'
  s.platforms      = { :ios => '15.0', :tvos => '15.0' }
  s.source         = { git: '' }
  s.static_framework = true

  s.dependency 'ExpoModulesCore'
  s.dependency 'SnapKit', '~> 5.7.0'

  s.vendored_frameworks = [
    "Frameworks/_MapboxNavigationHelpers.xcframework",
    "Frameworks/MapboxCommon.xcframework",
    "Frameworks/MapboxCoreMaps.xcframework",
    "Frameworks/MapboxDirections.xcframework",
    "Frameworks/MapboxMaps.xcframework",
    "Frameworks/MapboxNavigationCore.xcframework",
    "Frameworks/MapboxNavigationNative.xcframework",
    "Frameworks/MapboxNavigationUIKit.xcframework",
    "Frameworks/Turf.xcframework"
  ]

  # Swift/Objective-C compatibility
  s.pod_target_xcconfig = {
    'DEFINES_MODULE' => 'YES',
    'SWIFT_COMPILATION_MODE' => 'wholemodule'
  }

  s.source_files = "**/*.{h,m,mm,swift,hpp,cpp}"
end

I fixed the last 2 errors ("No such module 'MapboxMaps'") fixing a typo on the podspec but the redefinition errors remained, i don't have any dependency on any mapbox library in the pospec and i added all the frameworks

fbeccaceci commented 3 weeks ago

@kried I actually managed to fix the errors adding

s.exclude_files = "Frameworks/*.xcframework/**/*.h"

to the podspec

Now i got a question, can the frameworks be compiled as static frameworks? Cause i tried with scipio and the compile but then at runtime i get this exception

Screenshot 2024-08-20 alle 10 41 16
fbeccaceci commented 3 weeks ago

I got it working using use_frameworks! :linkage => :static don't really know why, i'm not that an expert about ios frameworks stuff

emilianoalvarez91 commented 3 weeks ago

@kried I checked your branch and it works, also I could check the dynamic access token and that works too, thank you very much with the help here.

Can this solution be integrated into future versions of Package.swift? I don't mind generating the xcframeworks, but I prefer not to modify the original file. Otherwise, it would be difficult to track the URL for downloading MapboxNavigationNative.xcframework.zip or other framework dependencies.