Showing posts with label cocoapods. Show all posts
Showing posts with label cocoapods. Show all posts

Tuesday, June 5, 2018

Add preprocessor macro for another pod

Leave a Comment

I'm creating a CocoaPod framework (Pod B) that has a dependency on another CocoaPod framework (Pod A). Some of the behavior and file locations used by Pod A are controlled by preprocessor macros. Is there a way I can supply some of these macros from Pod B so that users of Pod B do not have to be aware of or deal with the settings required by Pod A?

I've tried setting some of these in XCode, but it seems that building Pod A does not take any of these settings from XCode. It would be preferable not to have to modify Pod A's .xcconfig unless that could be automated as part of either the build process or Pod B's install.

Update The CocoaPods team seems to have talked about solving this issue, but I can't see if any work has been done on this. Wondering if anyone has tried to solve this in other ways.

I would really prefer to avoid the standard mechanism of having a post_install in the Podfile, since that would require Pod B's users to make that change and hence be aware of these settings.

1 Answers

Answers 1

Would defining/re-defining the macros in Pod B's headers be acceptable to you? For example, if Pod A defined foo, & you wanted it to be defined to something different, you could add something like the following to Pod_B.h:

#ifdef foo #undef foo #endif #define foo bar 

Of course, you'd replace Pod_B.h with Pod B's header, & foo and bar with the macros & whatever you want to define them to.

Read More

Wednesday, January 31, 2018

Projects dependencies for custom configuration

Leave a Comment

We are using cocoapods to link different projects together. We have a main project with a target (project1) that has 3 configurations release, debug and a custom duplicate of release, qa.

We have 3 external libraries that project1 depends on that are not cocoapod compatible, let's call those external1, external2 and external3. Those external projects only have 2 configurations, the default release and debug.

Our Podfile looks like this:

platform :ios, '8.0' workspace 'project1.xcworkspace'  pod ... pod ...  target 'project1' target 'project1-cal'  target 'external1' do   project '[...]/external1.xcodeproj', 'qa' => :release end  target 'external2' do   project '[...]/external2.xcodeproj', 'qa' => :release end  target 'external3' do   project '[...]/external3.xcodeproj', 'qa' => :release end 

this setup fails when I try to build for Qa with the following error: Showing All Messages error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -lPods-external1

The only way I can fix this is by manually adding qa configurations to external1, external2 and external3.

Can someone please help with this, by explaining what I am doing wrong? I lack some depth knowledge of how exactly cocoapod work.

N.B: Pods-external*.qa.xcconfig are being properly created by pod install in Target Support Files/Pods-external1 albeit they aren't appearing in xcode and also no qa configuration are being added.

0 Answers

Read More

Wednesday, November 22, 2017

How to use CocoaPods with LibGDX?

Leave a Comment

I have a LibGDX project which I can run on all platforms that are supported by LibGDX. Recently I started integrating the Google Nearby Messages API. I got it working on Android through platform-specific code, pretty much like the description on Google says it should be done. Now I want to integrate it in the iOS project, which uses RoboVM, but according to their documentation (https://developers.google.com/nearby/messages/ios/get-started) I should use CocoaPods, which doesn't seem so straightforward for integration, especially in a LibGDX project. I hope someone with some experience in doing this can help me out, or point me to a project in which that's already done. Thanks!

0 Answers

Read More

Monday, November 20, 2017

Issue Google maps API on iOS 11 with Xcode 9

Leave a Comment

I'm trying to set a map in a view in my app and I got this problem:

CoreData: annotation: Failed to load optimized model at path '/var/containers/Bundle/Application/35C61A40-48B9-40E0-A6F9-AB7492A15009/simply-convertor.app/GoogleMaps.bundle/GMSCacheStorage.momd/Storage.omo' CoreData: annotation: Failed to load optimized model at path '/var/containers/Bundle/Application/35C61A40-48B9-40E0-A6F9-AB7492A15009/simply-convertor.app/GoogleMaps.bundle/GMSCacheStorage.momd/Storage.omo' CoreData: annotation: Failed to load optimized model at path '/var/containers/Bundle/Application/35C61A40-48B9-40E0-A6F9-AB7492A15009/simply-convertor.app/GoogleMaps.bundle/GMSCacheStorage.momd/Storage.omo'

I add an empty view to my ViewContoroller and change it's type to GMSMapView. And in viewDidLoad method I create a new map from location and init my main mapView:

override func viewDidLoad() {         super.viewDidLoad()         placesClient = GMSPlacesClient.shared()         locationManager.delegate = self         locationManager.desiredAccuracy = kCLLocationAccuracyBest         locationManager.requestWhenInUseAuthorization()         locationManager.startMonitoringSignificantLocationChanges()          locationAuthStatus()         print(location.coordinate.latitude, location.coordinate.longitude)         let camera = GMSCameraPosition.camera(withLatitude: 31.9650070083707, longitude: 34.7899029677496, zoom: 6.0)         let map = GMSMapView.map(withFrame: CGRect.zero, camera: camera)         self.mapView = map          // Creates a marker in the center of the map.         let marker = GMSMarker()         marker.position = CLLocationCoordinate2D(latitude: 31.9650070083707, longitude: 34.7899029677496)         marker.title = "Home"         marker.snippet = "Home"         marker.map = mapView     } 

what is the problem?

1 Answers

Answers 1

I find my problem.. it appears I misunderstood the initialliztion of a GMSMapView and not initialize it correct..

From other post the CoreData error that I mention is a problem of Google's API and it doesn't affect the app.

Read More

Monday, July 31, 2017

Swift error when running pod lib lint

Leave a Comment

Swift is very new for me so please excuse me if this is a very basic question. I have a swift project that builds fine in xcode and all the unit tests pass.

However when I run pod lib lint i get a no such module MyModule error.

Testing with xcodebuild.  -> my-swift-project (0.4.2) - WARN  | source: Git SSH URLs will NOT work for people behind firewalls configured to only allow HTTP, therefore HTTPS is preferred. - ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. - ERROR | [iOS] xcodebuild:  my-swift-project/Echo/Delegates/MyModule/MyModule.swift:7:8: error: no such module 'MyModule' 

The file in question has an import module declaration at the top of the file

import MyModule 

Would anyone know why this would be happening and why the project builds in xcode fine but not when i get to this stage?

Any help appreciated

Thanks

1 Answers

Answers 1

build settings > Framework Search Paths Set framework search path to $(SRCROOT) and recursive.

Read More

Wednesday, April 5, 2017

How to download Podspec dependencies for local development

Leave a Comment

This seems like something that should be done very easily. I don't know why I just can't seem to find a simple answer to that.

I am creating a pod library that has a pod dependency.

So in my .podspec, I have a s.dependency 'SomePod', '~> 1.0'. Since I am writing my library using SomePod, I want the source files from it in order to import it and use it. Sure one way to do it is to have a PodFile in the repo and then pod install the SomePod.

But is there some other way to download the somePod dependency so that I can use it in my library? What is the best practice around that to have a clean structure?

FYI, I am using the Cookie Cutter library in order to generate all my project structure. What's left for me to do is download those podspec dependencies and avoid using Podfile and pod install since I already have a .xcworkspace generated from Cookie Cutter, so pod install won't like that and will go crazy.

1 Answers

Answers 1

Well you could handle the dependency management with other Tools (Carthage etc.) or simply on your own (git clone + project integration), but as you are already providing a podspec for your lib, why not just stick to cocoapods for third party lib integration?

This would be the typical approach for your setup, as you just need to write a simple Podfile, assure that SomePod is fetched with the same version as defined in podspec and call pod install.

Advantages:

  • you can still watch third party sources
  • you can debug into third party lib
  • you can compile, test & debug against the exact same version of SomePod that will be fetched from a client project of your lib (no need to keep versions manually in sync)
Read More

Sunday, March 26, 2017

How to port swift based cocoapods to Xamarin

Leave a Comment

I am trying to port cocoapods to xamarin.

Objective C based cocoapods can be ported by converting it into a static library(.a) and subsequently converting that as binding library in xamarin studio or visual studio

But Swift based cocoapods can not be converted into a static library and so it can't be ported to xamarin.

but swift can be converted into a dynamic framework but I couldn't find any way to port that to xamarin

Is there any other way to port swift based cocoapods or ios project into xamarin ?

1 Answers

Answers 1

Binding a Swift Library in Xamarin.iOS follows the same process for Objective-C as shown in xamarin documentation

but with some caveats.

  • A swift class must inherit from NSObject to be binded.

  • Swift compiler will translate class and protocol names into something else, so you must specify the final name in the ApiDefinition.

  • In runtime your APP must include some swift core libraries alongside your binded framework in a folder called Frameworks;

  • When the App is pushed to AppStore it must include a SwiftSupport folder alongside your Payload folder. Those are inside the IPA file.

Here you can find a simple sample binding: https://github.com/Flash3001/Xamarin.BindingSwiftLibrarySample

And a full binding sample: https://github.com/Flash3001/iOSCharts.Xamarin

Please find the full documentation of how to do this here

Read More

Friday, March 10, 2017

using 'vendored_frameworks' and 'source_files' for cocoapod using 'use_frameworks!'

Leave a Comment

I'm building a cocoapod that basically contains a framework (private sources) and a view (open source) that rely on this framework, all made in Objective-C.

In the podspec I have the following lines :

  • spec.vendored_frameworks = 'MyPod/Framework/MyFramework.framework'
  • spec.source_files = ['MyPod/UI/Views/MyView.{h,m}']

When using the use_frameworks! syntax, I can't #import MyFramework

I just don't understand what's happening.

Moreover, when I remove the spec.source_files line, I can #import MyFramework and it works perfectly, but of course I cannot use MyView.

What am I doing wrong ?

2 Answers

Answers 1

If you use use_frameworks! your pod itself will become a framework. Therefore you should #import MyPod instead of #import MyFramework and then use MyView.

Review also public_header_files in case you need it.

Answers 2

Since the project's pods are now a framework, you could try importing it as a module using @importMyFramework.

However, if that doesn't work, then try backing up your project and then running pod deintegrate && pod install. Also, this question is very similar, and some of its comments and answers may be helpful.

Read More

Friday, June 10, 2016

Cocoapods testing linker error

Leave a Comment

Whenever I build my testing target (the standard target that Xcode generates), the build fails with an cryptic error:

framework not found Pods_AppName_AppNameTests 

which I take to mean the pod generated target for my tests can't be found. My podfile is pretty simple:

use_frameworks!  target 'AppName' do    pod 'ReactiveCocoa'   pod 'RealmSwift'   pod 'ObjectMapper'   pod 'Moya'   pod 'Moya/ReactiveCocoa'   pod 'pop'   pod 'Heimdallr'   pod 'Heimdallr/ReactiveCocoa'   pod 'Alamofire'   pod 'AlamofireImage'   pod 'SwiftDate'   pod 'DropdownAlert'   pod 'NibDesignable'     target 'AppNameTests' do     pod 'Quick'     pod 'Nimble'   end end 

I'm using Cocoapods 1.0.1.

EDIT:

It is NOT the format of my podfile. This is the default setup given to me by running pod init. There may very well be a bug in cocoapods but the format is correct.

EDIT 2:

If I include:

inherit! search_paths 

in my test target, the tests fail saying:

The bundle “MyApp_Tests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle. 

Without that line, the tests also fail to build but this time with a linker error:

Ld /Users/travis/Library/Developer/Xcode/DerivedData/Reactify-fqgxzcgedmqljrangqdkxpwdfxne/Build/Intermediates/Reactify.build/Debug-iphonesimulator/Reactify_Tests.build/Objects-normal/i386/Reactify_Tests normal i386

That particular error is from Travis but I get the same one in Xcode locally.

2 Answers

Answers 1

I've been battling with this the last week as well -- the "solution" I eventually found to work reliably was to add inherit! search_paths, pod install, then remove it, and pod install again, from the test target, like this:

source 'https://github.com/CocoaPods/Specs.git'  project 'CityWeather/CityWeather.xcodeproj' install! 'cocoapods',          :deterministic_uuids => false  use_frameworks!  platform :ios, '9.3'  abstract_target 'CityWeather_Base' do    <... pod list here, contents don't seem to matter ...>    target 'CityWeather' do   end    target 'CityWeatherTests' do   # NB. If it starts refusing to link the test frameworks,   # adding and then removing inherit! :search_paths here appears to help.   #inherit! :search_paths   end  end 

That's less hassle at least than creating a new target every time it happens to you, which judging by my last week I predict to happen to you shortly. Very annoying. Spent as much time as I could spare to try to deduce from the commit logs where the problem occurs, but it's not straightforwardly obvious. I'll update here if I manage to find the time to figure out the problem enough to open a useful issue. But in the meantime, hopefully my "solution" will improve your productivity somewhat.

Answers 2

It's the strangest thing and I absolutely tried this before, but I just deleted the test target, created a new one, and lo and behold, it works. The sole difference, as far I can tell, between the two targets is one was called MyApp_Tests and the other MyApp_ExampleTests. I'd be surprised if that was the cause but at this point it's hard to tell.

I will say though as a side note, the project I was referring to is not the only project I've seen this happen with. The last four of my projects have encountered this error, all created since Cocoapods 1.0.0. That leads me to believe that there's some hidden bug in the Cocoapods test setup which I'll have to investigate more.

Additionally, deleting the test target and making a new one only seemed to work in this particular case. In other projects, the error persists. And I can tell it's more than just my local setup because my travis builds would also fail consistently.

Read More

Sunday, April 10, 2016

Embed a framework without module in a Pod

Leave a Comment

I'm using a 3rd party library provided as a framework : Library.framework. Apparently, it can only be used in my Swift project via the Bridging Header by doing #import <Library/Library.h>. Which is fine in most cases.

However, I'm currently developing a Pod in which I want to use Library.framework. This means that I cannot rely on the Bridging Header.

I tried to link the Library.framework in my Pod target (see General > Linked Frameworks and Libraries) but then, once the Pod is installed in my app, Xcode says the Pod cannot compile because some files in Library are not found.

What would be the best strategy to adopt here ?

2 Answers

Answers 1

I think I made it.

The trick was to add the .h files in both source_files and public_header_files in the Pod.podspec.

Like this :

s.source_files = 'Library.framework/Headers/*.h' s.public_header_files = 'Library.framework/Headers/*.h' 

This way, all the header files appear in the Pod-umbrella.h and can now be used in my app.

Answers 2

In your pod project I assume you have a file named [PodName].h, it will look similar to the file below. You could try to add the header in this file.

// //  PodName.h //  PodName // //  Created by John Doe on 06.04.2016. //  Copyright © 2016 John Doe Inc. All rights reserved. //  #import <UIKit/UIKit.h>  //! Project version number for PodName. FOUNDATION_EXPORT double PodNameVersionNumber;  //! Project version string for PodName. FOUNDATION_EXPORT const unsigned char PodNameVersionString[];  // In this header, you should import all the public headers of your framework using statements like #import <PodName/PublicHeader.h>  #import <Library/Library.h> // Add framework header here. 
Read More

Saturday, April 9, 2016

Always get build error : No such module 'Alamofire'

Leave a Comment

I followed the instruction of Alamofire in github,

I created an xcode project named cocoapods-test & I closed it.

I go to the project folder run pod init command which generates a Podfile. Then I added the following code to the Podfile:

source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' use_frameworks!  pod 'Alamofire', '~> 3.0' 

Then, I run command pod install and this is the result in terminal:

Updating local specs repositories  CocoaPods 1.0.0.beta.6 is available. To update use: `gem install cocoapods --pre` [!] This is a test version we'd love you to try.  For more information see http://blog.cocoapods.org and the CHANGELOG for this version http://git.io/BaH8pQ.  Analyzing dependencies Downloading dependencies Installing Alamofire (3.3.0) Generating Pods project Integrating client project  [!] Please close any current Xcode sessions and use `cocoapods-test.xcworkspace` for this project from now on. Sending stats Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed. 

Then, in my project folder there is a new file called cocoapods-test.xcworkspace . I double clicked it which opens my xcode again, and I can see the Alamofire module.

Then, I opened my project's ViewController class, and import Alamofire . But no matter how many times I clean & build, I always get error No such module 'Alamofire' . Here is the screenshot:

enter image description here

Why I get this problem though I followed the instruction step by step?

(I am using XCode 7.2.1, Swift 2.1.1 & Alamofire 3.3.0)

======= UPDATE ========

I tried @LK Yeung 's answer, uncomment import Alamofire, then clean & build again, I got a bunch of compiler errors from Alarmofire:

enter image description here

4 Answers

Answers 1

I was having this exact same problem. Please make sure that you are on Xcode 7.3 and using Swift 2.2.

You can check your Swift version using xcrun swift -version. Updating Xcode to 7.3 should also automatically update Swift.

Updating Xcode resolved this issue for me.

Answers 2

You need to add the lib to 'the Link Binary With Libraries' section also

Answers 3

You need to build the project successfully once before using the library

comment import Alamofire -> build -> uncomment import Alamofire

Answers 4

You can try put pod 'Alamofire', '~> 3.0' like below. And run pod install again.

target 'yourtarget' do      pod 'Alamofire', '~> 3.0' end 
Read More

Thursday, March 24, 2016

cocoa pods Dependency management

Leave a Comment

[!] Unable to satisfy the following requirements:

  • SDWebImage (= 3.7) required by DZNPhotoPickerController/Core (1.6.0)
  • AFNetworking (~> 3.0) required by Podfile
  • AFNetworking (~> 1.3.3) required by DZNPhotoPickerController (1.0.2)

PodFile

pod 'DZNPhotoPickerController' pod 'ZXingObjC', '~> 3.0' pod 'vfrReader','~>2.8.6' pod 'Mantle' pod 'PPSSignatureView' pod 'AFNetworking','~>3.0' pod 'JNKeychain' pod 'SVProgressHUD' pod 'ZipArchive' 

I want to update AFNetworking.

Help me to solve this

3 Answers

Answers 1

To fix this you might need to

Fork the DZNPhotoPickerController repo and modify the dependency in the Pod spec and then use your forked repo's git location in the pod file. Not a great solution for the long term but works.

For instance, The Pod spec here should have the line#33 which is

ss.dependency 'AFNetworking' 

should be changed to

ss.dependency 'AFNetworking', '~> 3.0'  

in your forked repo.

Then use in your Pod file as below

pod 'DZNPhotoPickerController', :git => 'https://github.com/yourUsername/DZNPhotoPickerController.git' 

Your forked repo is not guaranteed to work out of the box if the project relies on legacy dependency code, if any. In this particular case, if it uses any methods of AFNetworking that is removed in 3.0 it will not work.

Answers 2

To update a single AFNetworking pod,

pod update AFNetworking 

with above code, cocoapods will find a latest updated pod version and update your pod.

To update your all pods you can use

pod update 

this will update your all the pods.

Answers 3

The issue looks like 'DZNPhotoPickerController' has dependancy of ss.dependency 'AFNetworking', '~> 2.6.0' so when you are trying to update AFNetworking to version 3.0 it shows the wrong version error.

If you didn't check it recently the 'DZNPhotoPickerController' has also updated it's podspec to make AFNetworking to 3.0 so you should try pod update now it may fix your issue as both dependancy needs the same version

If the above and the fork 'DZNPhotoPickerController' in to newer one didn't work

  • Please remove the 'DZNPhotoPickerController' from the cocoapods
  • update the cocoapods by pod update
  • if it's successful add the 'DZNPhotoPickerController' dependancy again in the cocoapods and install that again it may solve your problem
Read More

Sunday, March 20, 2016

Setting up a project that includes Pods and will be released on CocoaPods

Leave a Comment

I'm in this situation... I'm starting a new SDK that I want to release through CocoaPods, the SDK itself needs some Pods (AFNetworking) I wonder which is the best way to setup the project, given that I need to try the SDK in an example project while writing it.

My first attempt started with the pod lib create command. I followed all the instruction and I ended up with a complete workspace, wonderful! now how can I include AFNetworking? I have to add it as dependency in the mySDK.podspec file using: s.dependency 'AFNetworking', '~> 3.0' so that users of my SDK can also have it included into the library, great. But how can I have it included in my current project to use it during development?

I see that under the "Example" folder created by cocoapods I have a Podfile but it contains only the example and test target... I've tried to include the SDK target here but it doesn't seem to work that way.

source 'https://github.com/CocoaPods/Specs.git' use_frameworks!  target 'MYSDK_Example', :exclusive => true do   pod 'MYSDK', :path => '../' end  target 'MYSDK_Tests', :exclusive => true do   pod 'MYSDK', :path => '../'    pod 'Specta'   pod 'Expecta' end 

I've tried to include the next configuration and launch again pod install...

target 'MYSDK', :exclusive => true do     pod 'AFNetworking', '~> 3.0' end 

I get a generic terrible error and anyway it doesn't sound really good as solution.

This is the structure created by the lib create command, where I'm supposed to add a new Podfile to include the library that I need to develop the library?

 MyLib   ├── _Pods.xcproject   ├── Example   │   ├── MyLib   │   ├── MyLib.xcodeproj   │   ├── MyLib.xcworkspace   │   ├── Podfile    <----- the Podfile previously described   │   ├── Podfile.lock   │   ├── Pods   │   └── Tests   ├── MyLib.podspec   ├── Pod   │   ├── Assets   │   └── Classes   │     └── TheFilesForMyLib.[swift/m] <---- My Lib code 

2 Answers

Answers 1

How I did it was to have a Podfile for my library as well. In this Podfile I have all the dependency.

Here my libraries Podfile:

source 'https://github.com/CocoaPods/Specs.git'  platform :ios, '7.0'  workspace 'SAFoundation.xcworkspace'  xcodeproj 'SAFoundation.xcodeproj'  pod 'AFNetworking' 

Answers 2

I made a project using pods, and my Podfile looked like this.

# Uncomment this line to define a global platform for your project # platform :ios, '8.0' # Uncomment this line if you're using Swift use_frameworks!  target 'golden-boy-iOS' do end  target 'golden-boy-iOSTests' do end  target 'golden-boy-iOSUITests' do end  pod 'AFNetworking', '~> 2.6' pod 'SVProgressHUD' pod 'FBSDKCoreKit' pod 'FBSDKLoginKit' pod 'FBSDKShareKit' pod 'Fabric' pod 'Crashlytics' pod 'REFrostedViewController', '~> 2.4' pod 'IBActionSheet' pod 'ICViewPager' pod 'TwitterKit' pod 'SDWebImage', '~>3.7' 

after edit your Podfile you have to run pod install in your terminal. Also after install pods you have to open your project through myProjec.xcworkspace instead of myProject.xcodeproject.

For more info check out this doc. guides.cocoapods.org

hope it works.

Read More