I am writing my components in React Native using react-native cli and am damn frustrated and confused about configuring it to be consumed as a library. Here's how the react native folder structure looks like:
src
ios
build
projectName.xcodeproj
projectName.xcodeworkspace
PodFile
PodFile.lock
...
android
index.js
...
when I open the xcode and build the project everything works fine as expected, now here's the thing. My React Native code sits into a git repository (Repo-A) which is different from an ios-repository (Repo-B) which contains collection of lot of independent pods.
All I want is to configure my project (Repo-A) MyApp to be consumed by Repo-B. I want to understand two syntax:
How do I add podSpec file in my Repo-A so that it points to ios directory so that it could be picked up by other repositories (in this case Repo-B).
In order to include the podfile in a specific repo (Repo-B in this case), all I need to do is the below snippet or something else? [Also how does podFile get access to these private repositories?]
Here's how I would like to consume it:
pod 'MyApp', :git => 'https://github.com/<username>/my-app', :branch => 'main'
Someone please help me understanding how can I achieve this? (Connecting the podFiles).
Additionally, one more thing I would like to know is how the versioning works? Like lets say I make some updates to my codebase, if I push it all to main and rebuild the Repo-B would that be sufficient to update changes in app or should I be using tags and create podSpec for each changes?
I can answer at least part of your question:
In Repo-A, create a podspec file with the same name as your library: my-library-name.podspec. Add this code:
require "json"
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
folly_version = '2021.06.28.00-v2'
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
Pod::Spec.new do |s|
s.name = "my-library-name"
s.version = package["version"]
s.summary = package["description"]
s.homepage = package["homepage"]
s.license = package["license"]
s.authors = package["author"]
s.platforms = { :ios => "10.0" }
s.source = { :git => "https://github.com/<username>/my-app", :tag => "#{s.version}" }
s.source_files = ['ios/']
s.dependency "React-Core"
# Don't install the dependencies when we run `pod install` in the old architecture.
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}
s.dependency "React-Codegen"
s.dependency "RCT-Folly", folly_version
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
end
end
The s.source_files points to the ios directory so that it can be referenced by other repositories.
Documentation on sourcing other repos in podspec: https://guides.cocoapods.org/syntax/podspec.html#source
Related
I'm trying to add below as dependencies together for my CocoaPod (installing either one works but cannot install both)
s.dependency 'TensorFlowLiteSwift'
s.dependency 'LibTorch-Lite'
'LibTorch-Lite' requires below spec
s.static_framework = true
s.pod_target_xcconfig = {
'HEADER_SEARCH_PATHS' => '$(inherited) ${PODS_ROOT}/LibTorch-Lite/install/include’,
'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64'
}
s.user_target_xcconfig = {
'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64'
}
because I get below error.
libtorch.a(empty.cpp.o), building for iOS Simulator, but linking in object file built for iOS, file '/var/folders/3x/x73_p70n2tg0gnwq9lct7rmr0000gn/T/CocoaPods-Lint-20221219-7300-1w8h64c-PyTorchTensorFlowCocoaPod/Pods/LibTorch-Lite/install/lib/libtorch.a' for architecture arm64
However spec 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' causes below error when installing TensorFlowLiteSwift.
main.swift:1:8: error: could not find module 'PyTorchTensorFlowCocoaPod' for target 'arm64-apple-ios-simulator'; found: x86_64-apple-ios-simulator, at: /Users/steve.ham/Library/Developer/Xcode/DerivedData/App-dnxlikhybfsytahdpnmquhblzyly/Build/Products/Release-iphonesimulator/PyTorchTensorFlowCocoaPod/PyTorchTensorFlowCocoaPod.framework/Modules/PyTorchTensorFlowCocoaPod.swiftmodule
Does anyone know how to install both CocoaPods as dependency? Thanks.
eg.
I have 'react-native-awesome' module, and ios file path is below
ios/RNAwesome/RNAwesome.h
ios/RNAwesome/RNAwesome.m
ios/RNAwesome.xcodeproj
I wrote podspec like below
require 'json'
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
Pod::Spec.new do |s|
...some specification
s.source_files = "ios/*.{h,m}" //correct path is "ios/**/*.{h,m}"
...
end
It occur error when I use auto linking? (at RN > 0.60.x)
I specified frameworks ad weak_frameworks for my private pod but after installing it via pod install, I am not seeing AdSupport or WebKit appearing anywhere in the project settings.
Should it appear under Build Phases -> Link Binary with Libraries or Build Settings -> Linker Flags? What's the difference between the two?
Pod::Spec.new do |s|
s.name = 'Analytics'
s.version = '1.0.0'
s.summary = 'Analytics SDK'
s.description = <<-DESC
Analytics SDK
DESC
s.homepage = 'https://github.com/author/analytics-ios'
s.license = ''
s.author = { 'Author' => 'Email' }
s.source = { :git => 'https://github.com/author/analytics-ios.git', :tag => s.version.to_s }
s.vendored_frameworks = 'Pods/Assets/Analytics.framework'
s.ios.deployment_target = '9.0'
s.frameworks = 'AdSupport'
s.weak_frameworks = 'WebKit'
end
You can find the reference to those frameworks on your respective .xcconfig file associated to your target. In the Pods folder within your main Xcode project structure.
I have an Objective-C Library and I am trying to update the podspec to cocoapods. When I do the "pod spec lint" command I get the following error:
[!] The spec did not pass validation, due to 1 error.
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
`echo "2.3" > .swift-version`.
Here is my podspec file:
Pod::Spec.new do |s|
s.name = "OSwitch"
s.version = "0.2.0"
s.license = { :type => "MIT", :file => "LICENSE" }
s.summary = "OSwitch is a customisable switch control writen in Objective C."
s.homepage = 'https://github.com/OyaSaid/OSwitch'
s.source = { :git => 'https://github.com/OyaSaid/OSwitch.git', :tag => s.version.to_s }
s.platform = :ios, "7.0"
s.ios.frameworks = ['UIKit', 'Foundation']
s.source_files = 'OSwitch/Classes/**/*.{h,m}'
s.requires_arc = true
end
Why does this show when I have an objective C library. And how do I fix this?
Thanks
It shows that because you're able to use both swift and Objc languages in your pod.
Just run the following command in the terminal:
`echo "2.3" > .swift-version`
Replace "2.3" with your current Swift version in XCode, if you're on 3.1 for example replace it with "3.1". It will create a swift version file in your pod-project folder. And then you can run the lint command to validate your podspec.
I'm trying to deploy a private CocoaPod, and I'm running into a perplexing issue with my framework's dependency graph. I cannot get my code to find a necessary class from one of its dependencies - RestKit, to be specific.
I first ran pod lib create to create the framework, then added RestKit as a dependency of the private CocoaPod in its .podpsec file. Everything seemed to be working fine until I referenced one particular class in RestKit, which it cannot seem to find unless I use an #import statement.
I've tried all of the following include's, and none of them work:
#import <RestKit/RestKit.h>
#import <RestKit/ObjectMapping.h>
#import <RestKit.h>
#import <ObjectMapping.h>
#import "RestKit.h"
#import "ObjectMapping.h"
The only one that does work is #import RestKit.ObjectMapping. However, using this import/include statement causes pod lib lint to fail as it can't find RestKit. I'm a bit stuck as to what else to try here. I've remade the podspec project already, and I've tried all the includes. Has anyone else ran into this issue?
Edit:
Below is my podspec.
Pod::Spec.new do |s|
s.name = "MyAPI"
s.version = "0.1.4"
s.summary = "My summary here."
s.description = <<-DESC
My description here.
DESC
s.homepage = "http://example.com"
s.license = 'None'
s.author = { "Sean Olszewski" => "sean#somewebsite.com" }
s.source = { :git => "ssh://username#myprivateserver/path/to/private/pod/repo", :tag => s.version.to_s }
s.platform = :ios, '7.0'
s.requires_arc = true
s.source_files = 'Pod/Classes/**/*'
s.resource_bundles = {
'MyAPI' => ['Pod/Assets/*.png']
}
s.public_header_files = 'Pod/Classes/**/*.h'
s.dependency 'RestKit', '~> 0.25.0'
s.dependency 'RKValueTransformers'
end
You should specify a version and a development target for your Pod.
s.ios.deployment_target = '7.0'
s.platform = :ios, '7.0'
Also you will have to change the import statement in your code, as it will be interpreted as a module (use_frameworks! in the pod file ), that's why you can't use #import anymore.
If you run into the 'non modular include' you will the to set the property in your Podspec:
s.xcconfig = { 'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES'}