CocoaPods/cocoapods-packager

local path for s.source in podspec

sunil-chayagol opened this issue Β· 26 comments

instead of giving git path i have given the below path for s.source in my podspec
{:path=>"~/Users/sunil/workspace/MyFramework"}
validation does not pass and gives message as unsupported download strategy. is there a way to give local path instead of git path.

Apparently :path is not officially supported in CocoaPods 1.6.0:
https://guides.cocoapods.org/syntax/podspec.html#source

I am not sure why it was removed. πŸ˜•

Katsz commented

Can we get any response? This was so convenient

Katsz commented

I do, in fact, have a workaround. But it is questionable, I'd say.

How

Assuming Podfile, local .podspec and .zip are placed in the same directory

In Podfile specify local .podspec like so:

pod 'MyFramework', :podspec => "./MyFramework.podspec"

Then, edit your .podspec as following

s.source            = { :http => 'file:' + __dir__ + '/MyFramework.zip' }

Why

__dir__ is a ruby analog for pwd in bash, so the full path will look lie file:/Users/dev/projects/MyProject/MyFramework.zip. Under the hood ruby uses curl -f -L -o %tempdir% %s.source% for http requests, and curl can be used to fetch local files

Β―\_(ツ)_/Β―

Was really missing this feature today, workaround above works, but is so cumbersome to implement due to need of manually zipping a package. Will CocoaPods consider bringing back :path as a valid option for source. If I am correct it used to be a valid option at some point, what was the reason for removing it?

Katsz commented

@iljadaderko I was talking about binary .framework. If it's your case, you can add post-build step to your xcode project to zip your artifact.

If you're developing an open source pod, you can use :git => on local git repo. According to docs git supports file:/ URL format

These workarounds are pretty surprising. Is there no way to include a framework (podspec) that's in development locally to be used within another cocoapods project? It has to be uploaded somewhere?

Katsz commented

@mikegb

Β―\_(ツ)_/Β―

As I've said, someone in cocoapods team decided to remove this feature a long time ago.
Yet there is not a single reason to do so.

I solved this by executing the zip command with the @Katsz solution.

Example

zipfile = "#{__dir__}/../../artifacts/JasonComponent.zip"

Pod::Spec.new do |s|
    s.name         = "JasonComponent"
    s.version      = "1.0.0"
    s.summary      = "Jason Component"
    s.description  = "Enables of Jason Components"

    s.homepage     = "https://github.com/jasonelle/jasonette-ios"
    s.screenshots  = ""

    s.license      = { :type => "MIT", :file => "LICENSE" }
    s.authors      = { 
        "Ethan Gliechtenstein" => "https://github.com/gliechtenstein" ,
        "Camilo Castro" => "https://github.com/clsource"
    }

    system("rm -rf #{zipfile} && zip -r #{zipfile} #{__dir__} > /dev/null")

    s.source = { :http => "file://#{zipfile}"}

    s.source_files  = "src", "src/**/*.{h,m,swift}"
    s.requires_arc  = true

    s.ios.deployment_target = '8.0'
end

Then just use pod install to fetch the zip and install it πŸ‘

It works for me with empty path s.source = { :git => '' }, in your projects Podfile you just point to your package and everything works out of the box.

any news for this issue?
also asked in SO

xT-Tx commented

This works for me:
s.source = { :git => 'file:///Users/MyName/path' } # be noted the triple-slash
My pod version is 1.7.4

doesn't work for me. I'm getting : does not appear to be a git repository fatal: Could not read from remote repository

@slootzky @sunil-chayagol @xT-Tx's answer working for me, Hope you are giving git repo folder path, Not the podfile folder path.

Ex:
Give file:///Users/guest/Desktop/iOS/sample-pod-example
Not file:///Users/guest/Desktop/iOS/sample-pod-example/SamplePod

Thanks @xT-Tx

Thanks, I'll give that a try

Any news on that?

Support for local :path sources would be very useful. Especially for React Native modules which are distributed as npm packages and already contain all sources as well as a .podspec file referencing to those.

PS: Since v0.60.0 react-native provides CocoaPods integration by default (https://github.com/facebook/react-native/releases/tag/v0.60.0).

@eddyfrank you can just use empty git path in react native i.e. following works for me

require 'json'

package = JSON.parse(File.read(File.join(__dir__, '../..', 'package.json')))
name = 'ModuleName'

Pod::Spec.new do |s|
  s.name           = name
  s.version        = package['version']
  s.summary        = package['description']
  s.license        = package['license']
  s.author         = package['author']
  s.homepage       = package['homepage']
  s.platform       = :ios, '11.4'
  s.source         = { :git => '' }
  s.source_files   = '**/*.{h,m}'
  s.preserve_paths = '**/*.{h,m}'

  s.dependency    'React'
end

@iljadaderko Thanks. Sounds like a workaround. However, it does not work here :(

Error on pod install or pod update:

[!] Error installing MyReactNativeModule
[!] /usr/bin/git clone  /var/folders/mq/wfwmj51j2hb5bqdv30zq2s100000gn/T/d20190827-99417-1mtb6ja --template= --single-branch --depth 1
fatal: repository '' does not exist

$ pod --version
1.7.5
$ git --version
git version 2.20.1 (Apple Git-117)

I do, in fact, have a workaround. But it is questionable, I'd say.

How

Assuming Podfile, local .podspec and .zip are placed in the same directory

What .zip file are you referring to?

I do, in fact, have a workaround. But it is questionable, I'd say.

How

Assuming Podfile, local .podspec and .zip are placed in the same directory

In Podfile specify local .podspec like so:

pod 'MyFramework', :podspec => "./MyFramework.podspec"

Then, edit your .podspec as following

s.source            = { :http => 'file:' + __dir__ + '/MyFramework.zip' }

Why

__dir__ is a ruby analog for pwd in bash, so the full path will look lie file:/Users/dev/projects/MyProject/MyFramework.zip. Under the hood ruby uses curl -f -L -o %tempdir% %s.source% for http requests, and curl can be used to fetch local files

Β―\_(ツ)_/Β―

This will cause the podfile.lock file to update on every developer local environment 😒

I do, in fact, have a workaround. But it is questionable, I'd say.

How

Assuming Podfile, local .podspec and .zip are placed in the same directory
In Podfile specify local .podspec like so:

pod 'MyFramework', :podspec => "./MyFramework.podspec"

Then, edit your .podspec as following

s.source            = { :http => 'file:' + __dir__ + '/MyFramework.zip' }

Why

__dir__ is a ruby analog for pwd in bash, so the full path will look lie file:/Users/dev/projects/MyProject/MyFramework.zip. Under the hood ruby uses curl -f -L -o %tempdir% %s.source% for http requests, and curl can be used to fetch local files
Β―\_(ツ)_/Β―

This will cause the podfile.lock file to update on every developer local environment 😒

Hi, do you have any workarround on this problem?

@fahmisdk6 not yet.. Our problematic dependency is RNQualtricsDigital from react-native-qualtrics

Every time a developer installs dependencies the podfile.lock changes.

Here is their podspec:


Pod::Spec.new do |s|
  s.name         = "RNQualtricsDigital"
  s.version      = "0.0.1"
  s.summary      = "RNQualtricsDigital"
  s.description  = <<-DESC
                  RNQualtricsDigital
                   DESC
  s.homepage     = "https://api.qualtrics.com"
  s.platform     = :ios, "9.0"
  s.source_files  = "*.{h,m}"
  s.requires_arc = true
  s.dependency "Qualtrics"
  s.source       = { :http => 'file:' + __dir__ + '/RNQualtricsDigital.zip' }
  s.author       = "Qualtrics"
  s.dependency "React"
end

This is the node_module:

image

@wilau2 We're also having this issue with Qualtrics, found any workaround yet?

alloy commented

I’m unsure what people refer to when they say that this used to work, perhaps it did but was a fluke as the :path option is solely meant to be used by a user in their Podfile, not in a podspec.

In the case of React Native and pods being shipped inside npm packages, β€œauto-linking” uses the Podfile :path option under the hood. If you are not using β€œauto-linking”, then you can specify the :path option in your Podfile explicitly.

In short, the source property of a podspec will actually never be used, so I would just point it to a helpful URL, e.g. the repo.

alloy commented

I missed context about what repo this was on, I incorrectly assumed it was the main repo, so I better understand your point now. I can’t speak for the current maintainers, only why historically this has been as it was. I would suggest you open a issue on the main repo to clearly discuss your needs and how they deviate from normal CP users.

@wilau2 We're also having this issue with Qualtrics, found any workaround yet?

@henninghall, no.. we have some discussions with Qualtrics support and it's not the best experience.
The SDK is not open source... so we can't really fix it ourselves, I suggest you write to them as well so that they feel more pressure coming from a wider group.

Hi There,

What happens if the pod is private?

Best Regards