12

I've a framework project on IOS and I would like to change it to a cocoapod project , however as much as I read from making cocoapod documentation its commonly used for the project which source codes are open. However our SDK is commercial and our customers are paying money for that, so I would like to include my existing framework into cocoapod library(private or public) but I dont want my source codes to be seen. Is something like that possible?

I' ve seen the google analytics made something like that ( https://developers.google.com/analytics/devguides/collection/ios/v3/)

Does anybody know how can I do something like that?

[EDIT]

According to answers, I've modified our podspec file as in the below url: https://github.com/Kandy-IO/test-cp/blob/1.6.7/CPaaSSDK.podspec

However when I try to push it to cocoapods , it gave the below error

Validating podspec
 -> CPaaSSDK (1.6.7)
    - ERROR | [iOS] public_header_files: The pattern includes header files that are not listed in source_files (/private/var/folders/kl/zfs4qq_d119cvqq26x9rt3zc0000gp/T/CocoaPods-Lint-20190513-14320-1opt8kx-CPaaSSDK/Pods/CPaaSSDK/CPaaSSDK.framework/Headers/CPaaSSDK-Swift.h, /private/var/folders/kl/zfs4qq_d119cvqq26x9rt3zc0000gp/T/CocoaPods-Lint-20190513-14320-1opt8kx-CPaaSSDK/Pods/CPaaSSDK/CPaaSSDK.framework/Headers/CPaaSSDK.h).
    - ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.
    - NOTE  | [CPaaSSDK/CPUtilities, CPaaSSDK/RestManager, CPaaSSDK/CPWebRTC, and more...] xcodebuild:  note: Using new build system
    - NOTE  | [CPaaSSDK/CPUtilities, CPaaSSDK/RestManager, CPaaSSDK/CPWebRTC, and more...] xcodebuild:  note: Planning build
    - NOTE  | [CPaaSSDK/CPUtilities, CPaaSSDK/RestManager, CPaaSSDK/CPWebRTC, and more...] xcodebuild:  note: Constructing build description
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked library 'swiftCoreGraphics'
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked library 'swiftFoundation'
    - NOTE  | xcodebuild:  ld: warning: 
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked library 'swiftMetal'
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked library 'swiftDarwin'
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked library 'swiftUIKit'
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked library 'swiftCoreFoundation'
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked library 'swiftObjectiveC'
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked library 'swiftDispatch'
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked library 'swiftCoreMedia'
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked library 'swiftQuartzCore'
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked library 'swiftCore'
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked library 'swiftCoreImage'
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked library 'swiftCoreAudio'
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked framework 'CPAddressBookService'
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked framework 'CPWebRTC'
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked framework 'CPAuthenticationService'
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked framework 'NotificationEngine'
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked framework 'CPMessagingService'
    - NOTE  | xcodebuild:  ld: warning: Could not find auto-linked framework 'CPUtilities'
    - NOTE  | xcodebuild:  RestManager.CPRestDownloadRequest.completion(_: __C.NSObject?, error: Swift.Error?) -> () in CPaaSSDK(CPRestDownloadRequest.o)
    - NOTE  | xcodebuild:  function signature specialization <Arg[1] = Exploded> of CPAddressBookService.CPAddressBookService.(logResult in _FFF4592E3450CC7F075A904CF3818DC2)(error: __C.CPError?, functionName: Swift.String) -> () in CPaaSSDK(CPAddressBookService.o)
    - NOTE  | [iOS] xcodebuild:  clang: error: 
    - NOTE  | [iOS] xcodebuild:  ld: warning: Could not find auto-linked library 'swiftsimd'
    - NOTE  | [iOS] xcodebuild:  ld: warning: Could not find auto-linked library 'swiftAVFoundation'
    - NOTE  | [iOS] xcodebuild:  ld: warning: Could not find auto-linked framework 'RestManager'
    - NOTE  | [iOS] xcodebuild:  ld: warning: Could not find auto-linked framework 'CPPresenceService'
    - NOTE  | [iOS] xcodebuild:  ld: warning: Could not find auto-linked framework 'CPCallService'
    - NOTE  | [iOS] xcodebuild:  ld: warning: Could not find auto-linked framework 'CPPushService'
    - ERROR | [CPaaSSDK/CPUtilities, CPaaSSDK/RestManager, CPaaSSDK/CPWebRTC, and more...] file patterns: The `vendored_frameworks` pattern did not match any file.
    - WARN  | [CPaaSSDK/CPUtilities, CPaaSSDK/RestManager, CPaaSSDK/CPWebRTC, and more...] file patterns: The `public_header_files` pattern did not match any file.

[!] The spec did not pass validation, due to 3 errors and 1 warning.

Thanks

tolgatanriverdi
  • 561
  • 9
  • 31

2 Answers2

2

CocoaPods's podspec allows shipping closed source pods.

You can use the following podspec settings:

You can even combine both, for what it's worth.

When properly set up, your prepared library files will be shipped instead of source files that have to be built by devs.

To differentiate the platforms, you can write:

spec.ios.vendored_frameworks = "..."
spec.osx.vendored_frameworks = "..."

Similarly, vendored_libraries is available for the platform parameters as well.

Static lib

As @Sven Herzberg mentioned, the Flurry SDK uses static library plus headers like this:

s.subspec 'FlurrySDK' do |ss|
  ss.source_files = [
    'Flurry/Flurry.h',
    'Flurry/FlurrySessionBuilder.h',
    'Flurry/FlurryConsent.h',
    'Flurry/FlurryEmpty.m'
  ]

  ss.platform   = :ios, '8.0'
  ss.frameworks = 'Foundation', 'SystemConfiguration', 'UIKit', 'Security'
  ss.vendored_libraries = "Flurry/libFlurry_9.2.1.a"
end

Framework bundle

On the other hand, the Google Ads SDK v7.35 uses frameworks and additionally a static library without headers (of which I'm not sure how you'd use that):

"source": {
  "http": "https://dl.google.com/dl/cpdc/bda58e433afe6cb0/Google-Mobile-Ads-SDK-7.35.0.tar.gz"
},
"vendored_frameworks": [
  "Frameworks/frameworks/GoogleMobileAds.framework"
],
"vendored_libraries": [
  "Libraries/libGoogleMobileAds.a"
],

Heads up: the source parameter points to the downloadable package that contains both the framework and the static library, not to headers like source_files does. I overlooked this when first scanning the specification.

ctietze
  • 2,805
  • 25
  • 46
  • but the sub libraries which I needed is also frameworks Structure is similar to this Umbrella.framework -Subframework folder - sub1.framework - sub2.framework ......... So I'll put our umbrella framework to vendored_frameworks part , but where should I put the sub frameworks – tolgatanriverdi May 09 '19 at 15:21
  • I don't understand the problem with sub-frameworks in your case. Can you explain? What if you start with the innermost framework and bundle it in the way I describe, then require this from the other frameworks that you also bundle up as closed source pods in this manner? In principle, the nature of "sub libraries" should not matter. – ctietze May 10 '19 at 12:32
  • I've made the changes according to your suggestions and edited my original post about it. But another problem started to show up now. As you've suggested I've started the inner frameworks as in order of innermost first. But couldnt understand why it gaves this error – tolgatanriverdi May 13 '19 at 11:43
  • @tolgatanriverdi With your recent edits, this sounds like a very different problem. Do the errors appear when you run `pod lib lint`? That'd be good, because then you can experiment. I'd suggest starting with a .podspec for 1 of the inner frameworks (as if you want to distribute them on their own) and see if the linting errors still appear, continue with all the others, then work your way to the wrapper. – ctietze May 14 '19 at 13:18
  • Also when you search for the linker errors you get, stuff like this pops up and could help: https://stackoverflow.com/questions/52536380/why-linker-link-static-libraries-with-errors-ios – ctietze May 14 '19 at 13:20
-2

Yes, this is possible. Just look at the Cocoapods for Flurry or Google Ads, they ship compiled code to the user.

herzi
  • 774
  • 6
  • 18