Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xcode build failure #6

Closed
nitinsh99 opened this issue Feb 6, 2021 · 25 comments
Closed

Xcode build failure #6

nitinsh99 opened this issue Feb 6, 2021 · 25 comments
Labels

Comments

@nitinsh99
Copy link

nitinsh99 commented Feb 6, 2021

Hi all, I am getting following error during xcode build after installing this package

ld: warning: building for iOS, but linking in dylib file (/Users/nitinsharma/Library/Developer/Xcode/DerivedData/app-bpqejjqomhurrldtyubqevqtdqzc/Build/Products/Debug-iphoneos/MapboxAccounts.framework/MapboxAccounts) built for Mac Catalyst
Undefined symbols for architecture arm64:
  "_swift_getFunctionReplacement", referenced from:
      _swift_getFunctionReplacement50 in libswiftCompatibilityDynamicReplacements.a(DynamicReplaceable.cpp.o)
     (maybe you meant: _swift_getFunctionReplacement50)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I am using

react-native : v0.63.0
xcode : 12.4

mapbox related pods from my podfile.lock
  - Mapbox-iOS-SDK (6.3.0):
    - MapboxMobileEvents (~> 0.10.4)
  - MapboxAccounts (2.3.1)
  - MapboxCommon (9.2.0)
  - MapboxCoreNavigation (1.2.1):
    - MapboxAccounts (~> 2.3.0)
    - MapboxDirections (~> 1.2.0)
    - MapboxMobileEvents (~> 0.10.2)
    - MapboxNavigationNative (~> 30.0)
    - Turf (~> 1.0)
  - MapboxDirections (1.2.0):
    - Polyline (~> 5.0)
    - Turf (~> 1.0)
  - MapboxMobileEvents (0.10.7)
  - MapboxNavigation (1.2.1):
    - Mapbox-iOS-SDK (~> 6.0)
    - MapboxCoreNavigation (= 1.2.1)
    - MapboxMobileEvents (~> 0.10.2)
    - MapboxSpeech (~> 1.0)
    - Solar (~> 2.1)
  - MapboxNavigationNative (30.0.0):
    - MapboxCommon (= 9.2.0)
  - MapboxSpeech (1.0.0)
@rossmartin
Copy link
Contributor

You appear to have a mac that is using apple silicon. The underlying SDK needs to be updated to handle this but until that happens you can get around it by adding this to your Podfile (ios/Podfile) -

# define architecture at the top level of your Podfile
architecture = `uname -p` # arm64 or i386

target 'YourAppNameHere' do

  # ... you will have all your stuff in between here

    post_install do |installer|
        flipper_post_install(installer)
        ## add this here after the above
        installer.pods_project.targets.each do |target|
          target.build_configurations.each do |config|
            if architecture === 'arm64' # only enable this for apple silicon
              config.build_settings["ONLY_ACTIVE_ARCH"] = "YES"
            end
          end
        end
    end
end

@rossmartin rossmartin changed the title Xcode build failure Xcode build failure on Apple Silicon Feb 6, 2021
@rossmartin rossmartin added the ios label Feb 6, 2021
@nitinsh99
Copy link
Author

Thanks for looking into this. I have a 4 year old mac. arm64 could be attributed to me running this on an actual iphone device? But regardless let me try the podfile changes you suggested and report back.

@rossmartin
Copy link
Contributor

I'm curious did you create a bridging header for swift or already have one? There is a step in the readme on how to do this if you haven't created one yet - https://github.com/homeeondemand/react-native-mapbox-navigation#ios-specific-instructions

image

@rossmartin rossmartin changed the title Xcode build failure on Apple Silicon Xcode build failure Feb 6, 2021
@nitinsh99
Copy link
Author

Yeah. I had that configured. I was able to resolve this issue ONLY for emulator by removing $(toolchain dir)/usr/lib/swift-5.0/$(platform_name) from my library search path. After I did that I am able to run the app on emulator. However, I am not able to run the app on real device as I am getting some un-related errors.

Here is the stackoverlow I created: https://stackoverflow.com/questions/66079852/xcode-react-native-undefined-symbol-swift-getfunctionreplacement which has more details.

Feel free to close this issue but I do have one last question for you. I am seeing the lanugage as chinese in the navigation view? Any idea how I can make it default to english? I don't see any language related prop.Thx

@rossmartin
Copy link
Contributor

Hey glad you got it figured out for the simulator at least. I see that you received an answer in your stackoverflow post and hopefully that resolves it.

I have witnessed some odd behavior with language in the navigation UI as well. I believe it is related to this - mapbox/mapbox-navigation-ios#2605. I left a comment in that thread.

In the future I might add language prop and then set it on the native side. It should be using the language set by the device but I have witnessed some parts of the nav UI be different.

@mertozylmz
Copy link

Hi @rossmartin , I did what they said, but the error still continues.
I'm getting the same mistake with @nitinsh99. Can you help me?

@rossmartin
Copy link
Contributor

@nitinsh99 @mertozylmz What version of cocoapods are you using? I can't reproduce the issue with Xcode 12.4 and cocoapods 1.10.1

@mccooll Can you elaborate on the negativity?

@rossmartin
Copy link
Contributor

@nitinsh99 It appears that you marked that stackoverflow answer to your question as a solution. Does that solve your issue?

@nitinsh99
Copy link
Author

hey @rossmartin @mertozylmz yeah.. following steps solved the issue for me

  1. Go to project>build settings> library search path
  2. remove "$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)"
    at this point i was able to run the app on simulator but not on device
  3. after this I had to set Don't Dead-strip Inits and Terms to Yes for both Project and Target.
  4. and most importantly update the cocoapods to 1.10.1
    at this point i was also able to run the app on device

However, I am still seeing following issues which were not originally related to this issue

  1. seeing a random language issue on navigation view. I have tried following steps mentioned here : MapView localization won't display english mapbox/mapbox-navigation-ios#2605 (comment) but no luck
  2. once the navigation finishes in the , nothing happens if you click on End Navigation button.

These two should be easily reproducible..thx

@rossmartin
Copy link
Contributor

Thanks for the details. Has your RN Xcode project gone through RN version updates? I think this can explain the need for step 1 and 2 in your solution.

My next question was going to be around what version of cocoapods was being used. I should have asked that one first.

In regard to the issues that are still there - I can't solve that 1st issue yet unfortunately.

The 2nd issue you mention I should be able to implement that delegate method on the native side and provide a prop that accepts a callback function. Perhaps something like onNavigationFinish that takes a function. I'll need to implement that on android and iOS.

I'm going to close this issue for now and I'll follow up when I release a new version with the prop for handling the navigation ending.

@rossmartin
Copy link
Contributor

Hey @nitinsh99 I added an onArrive prop that gets called when you reach the destination. This is published in 0.2.2.

I could not find a delegate/callback in the SDK that gets called when you tap the "End Navigation" in the bottom banner. Now you will know when you have arrived at the destination though.

@devguy22
Copy link

We're also seeing nearly the same issue as nitinsh99. For us, it complains about the _swift_getFunctionReplacement50, but for x86_64. We have react-native : v0.63.4, cocoapods 1.10.1, and xcode : 12.0 (also tried 12.4).

Removing$(toolchain dir)/usr/lib/swift-5.0/$(platform_name) from the library search path allows us to compile, but then it crashes on startup on the simulator. Without removing that library search path, we've tried every combination of setting Don't Dead-strip Inits and Terms as well as dead code stripping. Any ideas?

@nitinsh99
Copy link
Author

@devguy22 this is a really nasty issue but I am pretty positive its not related to this react-native library as eventually things worked out for me without any change in this library.. The only I other think I could think of which you can try is flush out the derived data folder after you made library search path changes ~/Library/Developer/Xcode/DerivedData/*

@devguy22
Copy link

Thanks, we still see that error after trying to delete that DerivedData. Our error in XCode is this:
dyld: Library not loaded: @rpath/MapboxMobileEvents.framework/MapboxMobileEvents Referenced from: /Users/pcandel1/Library/Developer/CoreSimulator/Devices/AA14D9F7-C774-459E-A943-E0AF12E82A5B/data/Containers/Bundle/Application/040D8696-9838-4140-B85E-63586A84B7A1/shift.app/Frameworks/Mapbox.framework/Mapbox Reason: image not found

Any ideas? We tried manually adding that .a library to our project (in addition to the libPods .a), but it didn't help.

@zoolle
Copy link

zoolle commented Feb 10, 2021

@devguy22 I am having the same issue and tried everything I could but nothing helps. Updated the xcode, downgrading the react-native, creating a fresh project but nothing seem to work

@LowBudgetMan
Copy link

Something interesting to note, when we pulled all the library source code into the project, we found everything works if it's marked as dynamically linked. Seems to be something related to the library being statically linked?

Relevant lines from our Podfile:

  pod 'MapboxCoreNavigation', :build_type => :dynamic_framework
  pod 'MapboxNavigation', :build_type => :dynamic_framework

@devguy22
Copy link

devguy22 commented Feb 12, 2021

So, I have gotten this to work for me. In my case, I did need to have the Mapbox Libraries load dynamically. In order to achieve this, I needed to:

  1. add use_frameworks! to my podfile (this makes the libraries dynamic instead of static)
  2. modify the podspecs in any libraries that reference React as a dependency in their podspec to instead depend on React-Core. In my case, this included: @react-native-community/masked-view, amazon-cognito-identity-js, react-native-gesture-handler, and this library, @homee/react-native-mapbox-navigation
  3. I then brought in patch-package to create patch files that changes those for me as part of npm install

Note, our app uses the expo libraries (not build environment) which requires use_unimodules!, and this still works. I did not need to remove the swift-5.0 toolchain for this to work, or setting any code stripping things.

@rossmartin
Copy link
Contributor

Thanks for providing the details. I haven’t had time until now to catch up on emails. I closed on the purchase of a house yesterday and I’ve been busy with that and starting to move. I’ll be swamped in the coming weeks but I’ll try to help when I can.

@rossmartin
Copy link
Contributor

@LowBudgetMan @devguy22 I had some time to revisit this stuff tonight. I spent too much time going down this rabbit hole with the root cause of the library being statically linked.

One thing I did do is publish 1.0.1 that changes the dependency of React to React-Core in the podspec (https://github.com/homeeondemand/react-native-mapbox-navigation/releases/tag/1.0.1).

If I get some more time I'll try and find a solution. Until cocoapods can incorporate dynamic swift pods then I may have to go the route that @LowBudgetMan mentions.

@rossmartin
Copy link
Contributor

@LowBudgetMan @devguy22 I was able to find a "solution". I found out how https://github.com/react-native-mapbox-gl/maps is getting around this issue and they are using this hack - https://github.com/react-native-mapbox-gl/maps/pull/714

I added that to the .podspec for this library and it solves the main build issue - https://github.com/homeeondemand/react-native-mapbox-navigation/blob/master/react-native-mapbox-navigation.podspec#L22

I'll be updating the readme also to document setting the Don't Dead-strip Inits and Terms to YES and removing the "$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)" from library search paths. I'll release 1.0.2 later tonight.

@rossmartin
Copy link
Contributor

Just an update on this specific issue and related ones (hopefully the last update needed) -

It has been resolved as of release 1.0.2 and I have documented how to solve potential build issues in the readme - https://github.com/homeeondemand/react-native-mapbox-navigation#ios-specific-instructions

@adhendo
Copy link

adhendo commented Mar 4, 2021

@devguy22 @rossmartin Hey, I've been trying to implement this package in RN, got it working following @devguy22 advice with the use_frameworks! dynamic loading. But once i try to bring in some other packages (RNReanimated, react-native-screens, react-navigation) I get some non specific errors:
Screen Shot 2021-03-04 at 1 01 14 PM

Just wondering if anyone has experienced similar issues when trying to integrate this package into your app. THANK YOU!

@zoolle
Copy link

zoolle commented Mar 4, 2021

@adhendo try not using use_frameworks!

@adhendo
Copy link

adhendo commented Mar 4, 2021

@zoolle only problem is im on a macbook m1/silicon so the use_frameworks! tag solved the issues i was having with the arch incompatibilities

Edit: ok after searching around I think your solution is correct of specifying which pods should use dynamic frameworks instead of just using the use_frameworks! tag. @zoolle are you using cocoapods-user-defined-build-types to specify which pods to build dynamically?

@mccooll
Copy link

mccooll commented Mar 5, 2021

FYI if you're using the react native map library, the workaround may cause a problem: https://github.com/react-native-mapbox-gl/maps/issues/1097#issuecomment-781647269.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants