What should be the Podspec file for using local .xcframework in React Native library?
Asked Answered
C

2

5

I created a React Native library that is a wrapper for using the native iOS framework in the React Native Projects. Earlier I was using .framework & it was working fine. Now I am facing an issue in using this library with .xcframework instead of .framework.

I added this library as a dependency to the project & then on running pod install getting the below error:

[!] [Xcodeproj] Generated duplicate UUIDs:

When I opened the project & try to build it, it builds successfully for the device but fails on the simulator.

Below is the Podspec file that I am using in the library project:

Pod::Spec.new do |s|
  s.name         = "react-native-myLibrary"
  s.version      = "1.0.0"
  s.summary      = "react-native-myLibrary"
  s.description  = <<-DESC
                    react-native-myLibrary
                   DESC
  
  s.homepage     = "https://github.com/geektimecoil/react-native-onesignal"
  s.license      = "MIT"
  s.author       = { "author" => "[email protected]" }
  s.platform     = :ios, "10.0"
  s.source       = { :http => 'file:' + __dir__ + '/' }

  s.source_files = "**/*.{h,m,swift}"
  s.requires_arc = true
  s.vendored_frameworks = 'MyLibrary.xcframework'

  s.dependency "React"
end

On searching for the solution I found that this error is caused by s.source_files = "**/*.{h,m,swift}". So, I commented this line & run pod install again. The error was gone but no dependency is being added to the Project target. Can anyone provide me the Podspec file to use for local .xcframework in React Native Library. Thanks in advance!

Cameroncameroon answered 21/3, 2021 at 8:23 Comment(2)
I'm also facing similar issue.Platinous
Hey Ankur, how do you generate xcframework file using react-native?Vidar
C
7

I was able to fix this issue using:

s.source_files = "ios/*.{h,m,swift}"
s.vendored_frameworks = 'ios/Frameworks/MyLibrary.xcframework'

& also by updating the Framework Search Paths from the Build Settings to $(inherited).

Cameroncameroon answered 8/5, 2021 at 7:13 Comment(2)
[!] Unable to install vendored xcframework MyLibrary for Pod demo-sdk-react-native, because it contains both static and dynamic frameworks. Any idea about this error ??Convex
@MehulAkoliya I am facing the same error. Were you able to fix this error?Unbeliever
I
0

Try this:

s.preserve_paths =  'MyFraemwork.xcframework/*'
s.source_files = 'MyFraemwork.xcframework/ios-arm64_armv7/PicUPSDKv3.framework/Headers/*.{h,m,swift}'

Innovation answered 21/3, 2021 at 14:14 Comment(3)
I tried this but it didn't work. No dependency is added to the Target.Cameroncameroon
Go to the Pods project, click Pods-MyTarget then go to Build Phases and look at the Dependencies. Do you see your XCFramework there? (your target links with Pods-MyTarget)Innovation
I don't see MyLibrary.xcframework there. But it has the react-native-myLibrary(Pods) added in the Dependencies.Cameroncameroon

© 2022 - 2024 — McMap. All rights reserved.