Include static frameworks and libs on cocoapods - ios

After spending hours, I definitely need your help.
I want to create a pod including Spotify SDK (here, it's a .framework) and Deezer SDK (here, it's a *.a lib) in order to do some work with.
Both SDK are written in Objective-C, and I want to write my pod in Swift 2 (iOS 8). Also, projects that will include this pod are in Swift 2 (iOS 8).
After the creation of the pod project with pod create lib I started by trying to add Spotify.framework directly in the pod project, but can't compile...
So, I tried to include the Spotify.framework like a pod by writing a podspec, here is spotify.podspec.json :
{
"name": "FakeSpotify",
"version": "1.1",
"summary": "Spotify iOS SDK",
"homepage": "https://developer.spotify.com/technologies/spotify-ios-sdk/",
"license": "MIT",
"authors": {
"jjt": "jeanjaques#thierry.com"
},
"source": {
"git": "https://github.com/spotify/ios-sdk.git",
"tag": "beta-13"
},
"platforms": {
"ios": "8.0"
},
"requires_arc": true,
"preserve_paths": "Spotify.framework",
"public_header_files": "Spotify.framework/Versions/A/Headers/*.h",
"vendored_frameworks": "Spotify.framework",
"xcconfig": {
"OTHER_LDFLAGS": "-ObjC"
}
}
And I Also added a line on the Podfile :
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target 'SpoTest_Example', :exclusive => true do
pod 'SpoTest', :path => '../'
pod 'FakeSpotify', :podspec => './spotify.podspec.json'
end
target 'SpoTest_Tests', :exclusive => true do
pod 'SpoTest', :path => '../'
end
Now, after a pod install, a folder "FakeSpotify" is created with the the Spotify.framework in it. This part is ok, but it's not enough : I can't use it...
I can't import Spotify neither in the example project, nor in the development pods files (both in Swift).
I tried to add #import <Spotify/Spotify.framework in the umbrella file (SpoTest-umbrella.h), but there were an error : Include of non-modular header inside framework module 'SpoTest'.
After hitting myself and some search, I tried to edit my podfile by adding this post script :
post_install do |installer|
installer.pods_project.build_configuration_list.build_configurations.each do |configuration|
configuration.build_settings['CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'
end
end
Nothing better, same error. Ok ok, what can I do ? Hmmm, I tried to remove the previously added import in umbrella file and I edited my pod podspec (SpoTest.podspec). I cried "ohhh I'm really bad, we need to also tell that we have a dependency in this podspec, even for development test...".
So I added this beautiful line : s.dependency 'FakeSpotify'
I was so happy, ... and so sad : new error from pod install command now :
[!] The 'Pods-SpoTest_Example' target has transitive dependencies that include static binaries: (/Users/jjt/Documents/dev/ios/LIBS/SpoTest/Example/Pods/FakeSpotify/Spotify.framework)
Ouch, so close ! Ok, let's try something to deal with it. I edited my Podfile by adding a pre install script :
pre_install do |installer|
# workaround for https://github.com/CocoaPods/CocoaPods/issues/3289
def installer.verify_no_static_framework_transitive_dependencies; end
end
With this, the command line is ok, and the installation is done. But I still can't use it. And there is still an error if I import the framework in umbrella.
Do you have any more ideas ? I currently don't have more :)
Or maybe there is a better way without cocoapods ? My goal is to create a something with these two SDK, and to include it easily on others reals projects.
Thanks.

Related

CocoaPods could not find compatible versions for pod "React/Core"?

Following the steps in the link doesn't help in integrating react native in existing project.
Link:
https://reactnative.dev/docs/integration-with-existing-apps
Configuration
Mac OS X - 10.15.6 (19G2021)
XCode - 12.1 (12A7403)
React Native Cli - 2.0.1
React Native - 0.63.4
package.json
{
"name": "MyReactNativeApp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "yarn react-native start"
}
"dependencies": {
"react-native": "^0.63.4"
}
}
Podfile
source 'https://github.com/CocoaPods/Specs.git'
# Required for Swift apps
platform :ios, '11.0'
use_frameworks!
# The target name is most likely the name of your project.
target 'MyReactNativeApp' do
# Your 'node_modules' directory is probably in the root of your project,
# but if not, adjust the `:path` accordingly
pod 'React', :path => '../MyReactNativeApp/node_modules/react-native', :subspecs => [
'Core',
'CxxBridge', # Include this for RN >= 0.47
'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
'RCTText',
'RCTNetwork',
'RCTWebSocket', # needed for debugging
# Add any other subspecs you want to use in your project
]
# Explicitly include Yoga if you are using RN >= 0.42.0
pod "Yoga", :path => "../MyReactNativeApp/node_modules/react-native/ReactCommon/yoga"
# Third party deps podspec link
pod 'DoubleConversion', :podspec => '../MyReactNativeApp/node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../MyReactNativeApp/node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../MyReactNativeApp/node_modules/react-native/third-party-podspecs/Folly.podspec'
end
When I run pod install. I get an error
[!] CocoaPods could not find compatible versions for pod "React/Core":
Screenshot:
I checked existing threads. Nothing works fine. I also did pod 'React' by removing everything else, result is
It's deprecated
It's not detected as Module. Module not found - I
will separate Question for that.
Follow these steps. It might help.
Open your project in XCode.
Expand Pods file.
There should be Development Pods, expand it also.
Find React folder. There should be 2 folders: Pods and Support Files. Go to Pods folder.
This directory should contain React.podspec file, open it, find where is s.dependency "React/Core", and change to s.dependency "React-Core",.

How to add a thirdparty SDK (multiple .framework files) to react native library module?

I have built a react native library module (with RN 0.63). This module depends on some thirdparty SDKs. When integrated with Android (using .aar files) it works just fine. In case of iOS, I have been able to get the library module working without the SDK (using swift hence with the bridging header). On adding the SDK, I am getting errors such as .h is not avaialble.
This is my directory My directory structure:
react-native-lib
--android
--ios
----MyCls.swift
----MyCls.m
----react-native-lib-Bridging-Header.h
----SDKS
------DEBUG
--------A.framework
--------B.framework
--------A-Debug.podspec
--------B-Debug.podspec
------THIRDPARTY
--------JSONModel.framework
--------CocoaLumberjack.framework
--------... other frameworks
--react-native-lib.podspec
--Example
--index.js
--Logger.swift
--package.json
I have a sample application in Swift which uses the SDKS folder, but I cannot seem to get RN to recognize the framework files/headers.
The last few lines of the Podspec file of react-native-lib is as follows:
...
s.dependency "React"
s.dependency 'JSONModel', '~> 1.8.0'
s.dependency 'CocoaLumberjack', '~> 3.6.1'
My example application Podfile:
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/#react-native-community/cli-platform-ios/native_modules'
platform :ios, '11.0'
use_frameworks!
project 'example', {
'Debug' => :debug,
'Release' => :release,
}
#
def applibs
pod 'A-Debug', :configuration => ['Debug'], :path => '../node_modules/react-native-lib/ios/SDKS/DEBUG/A-Debug.podspec'
# ... A-Release, B-Debug, B-Release
# The release folders not shown in structure above.
end
target 'example' do
config = use_native_modules!
use_react_native!(:path => config["reactNativePath"])
applibs
# Disabled Flipper because of use_frameworks!
end
I am not sure what I am doing wrong and how I can overcome this issue. There seems to be not quite a lot of articles on how such 3rd party sdk can be integrated in a library module. I have explored similar questions like this one which is still unsolved and has insufficient information.
after days of research and experimenting, I have been able to resolve the problem. It's simple enough, made difficult with lack of resources on the topic.
Primarily, I used the podspec file in my react native lib (ios folder) to add dependency on the 3rd party frameworks as follows.
react-native-lib.podspec
s.dependency 'A-Debug', '~> 1.2.3', :configurations => :debug
s.dependency 'B-Debug', '~> 2.3.4', :configurations => :debug
s.dependency 'A-Release', '~> 1.2.3', :configurations => :release
s.dependency 'B-Release', '~> 2.3.4', :configurations => :release
In my example application, the podfile works as shown above (by adding the pods in applibs). However, I encountered the 'enable bitcode' error where the compiler asked me to recompile the 3rd party libraries with bitcode enabled. I worked around it with the following post install script in the application (not library) podfile (obtained from here).
Example/ios/Podfile
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
Do a cache clean, and as an extra measure, clear node modules.
Then simply run the following in your application directory:
yarn install && cd ios && pod install && cd .. && yarn react-native start
Open your project in Xcode and import your SDK as per its documentation. Hope this saves you hours of research, experiment and debugging.

Error ITMS-90206 Invalid bundle contains disallowed file 'Frameworks'

I have a problem uploading my application into the Store via Xcode, this one in particular.
I saw a lot of post about this error, but all are talking about Extension App, that I do not use.
I'm using a Custom framework and Cocoapods.
You can see here my tree :
XXX is my project app name
SharedXXX is my custom framework
Pods is the project created by cocoa pods
Here is my cocoa podFile :
use_frameworks!
link_with 'XXX', 'SharedXXX'
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.1'
workspace 'XXX'
xcodeproj 'XXX/XXX.xcodeproj'
xcodeproj 'Shared/SharedXXX.xcodeproj'
def default_pods
pod 'Reveal-iOS-SDK', :configurations => ['Debug']
pod "SnapKit", '~> 0.17.0'
pod "DKChainableAnimationKit", '~> 1.6.0'
pod "AsyncSwift"
end
def shared_pods
pod "Alamofire", '~> 3.0'
pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git'
pod 'ReachabilitySwift', :git => 'https://github.com/ashleymills/Reachability.swift'
end
target :XXX do
xcodeproj 'XXX/XXX.xcodeproj'
default_pods
shared_pods
end
target :XXXDev do
xcodeproj 'XXX/XXX.xcodeproj'
default_pods
shared_pods
end
target :SharedXXX do
xcodeproj 'Shared/SharedXXXX.xcodeproj'
shared_pods
end
Build settings for custom framework (SharedXXX) :
I set the Embedded property to Yes
General Settings for custom framework (SharedXXX) :
The framework provided by Cocoapods is linked.
And to finish,
The General Settings to the main project (App Project : called XXX on the tree)
:
Any idea ?
I solved the problem
Firstly, set into Build Settings
For main project (here XXX) : Embedded Content Contains Swift Code to
YES
Custom Framework (SharedXXX) : Embedded Content Contains Swift Code to NO
Custom Framework (SharedXXX) : Runpath Search Path = #executable_path/../../Frameworks
This helped me solving that issue
I faced the same problem while trying to upload from Xcode 9.3
This happened because I added 'use_frameworks' in my OneSignal
NotificationServiceExtension
The value Always Embed Swift Standard Libraries found in Build Settings should be set to Yes only for you main Projects and not for your custom frameworks or extensions.

'RestKit/RKSerialization.h' file not found via Cocapods

I've been trying for hours but couldn't find any solution that helped me to solve the issue.
my Podfile looks like:
source 'https://github.com/CocoaPods/Specs.git'
inhibit_all_warnings!
xcodeproj 'MyProject.xcodeproj'
# Uncomment this line to define a global platform for your project
# platform :ios, '6.0'
target 'MyProject' do
pod 'ZBarSDK', '~> 1.3.1'
pod 'RestKit'
end
I have tried different options but none of them are working.
Header Search Paths and Library Search Paths & Framework Search Paths have: $(inherited) as value.
#import <RestKit/RestKit.h> // works fine
#import <RestKit/RKSerialization.h> // I get 'RestKit/RKSerialization.h' file not found
#import <RestKit/RKJSONParserJSONKit.h> // 'RestKit/RKJSONParserJSONKit.h' file not found
UPDATE:
cocapods version - 0.38.0
XCode version - Version 7.0 (7A220)
I've managed to solve it by using the following Podfile and recreated the project from scratch. I think the problem was that the XCode was created with older version and might interfere something.
source 'https://github.com/CocoaPods/Specs.git'
inhibit_all_warnings!
xcodeproj 'MyProject.xcodeproj'
# Uncomment this line to define a global platform for your project
# platform :ios, '6.0'
target 'MyProject' do
pod 'ZBarSDK', '~> 1.3.1'
pod 'RestKit', '0.10.3' //This is the lastest version that has RKJSONParserJSONKit file, next version is not backward compatibility with previous version, you need to update the code
pod 'FileMD5Hash', :podspec => 'FileMD5Hash.podspec.json'
end
and FileMD5Hash.podspec.json content. You will need to create that file on root folder of the Podfile, thanks & +1 to #ryanmaxwell
{
"name": "FileMD5Hash",
"version": "0.0.1",
"license": "Apache",
"summary": "Library for computing MD5 hashes of files with small memory usage.",
"homepage": "http://www.joel.lopes-da-silva.com/2010/09/07/compute-md5-or-sha-hash-of-large-file-efficiently-on-ios-and-mac-os-x/",
"authors": {
"Joel Lopes Da Silva": "joel#lopes-da-silva.com"
},
"source": {
"git": "https://github.com/JoeKun/FileMD5Hash.git",
"commit": "6864c180c010ab4b0514ba5c025091e12ab01199"
},
"prefix_header_file": "Common/FileMD5Hash_Prefix.pch",
"source_files": "Common/*.{h,c}",
"requires_arc": false
}

Using dependency in swift module (framework)

I am trying to create a swift module (Cocoa Touch Framework) with reusable code inside the environment set up by cocoa pods which includes third party libraries written in Objective-C (namely here Restkit).
Unfortunately I am not able to use Restkit in the module I create.
Here's what I did to create the module:
File -> New target: Cocoa Touch Framework, Language: Swift, Project: MyProject, Embed in Application: MyProject
In the "Info" tab of the project settings in the "Configurations" section I define the Pods.debug and Pods.release xcconfig file for my newly created target.
In the header file, which Xcode automatically created for me, networkModule.h, I add the following line:
#import <RestKit/RestKit.h>
Result: When trying to compile I get the error "include of non-modular header inside framework module 'networkModule'"
I have set the flag for "Allow Non-modular Includes in Framework Modules" to YES in the build settings for the Project Target and the Module/Framework target.
I went to the Cocoa pod project and have tried setting the visibility of the RestKit.h Header file to "Public" in the target membership (which of course is not a good solution to mess with the cocoa pods environment)
I am not able to compile. I still get the same error.
Is it possible in the first place to create a Cocoa Touch Framework with dependencies to a cocoa pod managed framework?
Btw. My first idea of creating a private cocoa pod didn't work out as well, as it doesn't seem to be supported, although I am using the prerelease of cocoa pods 0.36 with support for swift.
You should be able to make your won private Pod. You just need to make a podspec for it. Here is an example of one.
Pod::Spec.new do |s|
s.name = "Commons"
s.version = "1.0.0"
s.summary = "Common code for my iOS projects."
s.license = {:type => 'Commercial', :text => "Copyright (c) Dan Leonard(Or Your Name?). All rights reserved." }
s.source = { :git => "https://github.com/PATHTOPOD", :tag =>
s.version.to_s }
s.homepage = "https://github.com/PATHTOPOD"
s.requires_arc = true
s.ios.deployment_target = '9.0'
s.subspec 'Core' do |ss|
ss.source_files = '*.swift'
end
s.subspec 'Menu' do |ss|
ss.source_files = 'Menu/*.swift'
ss.resources = ['Menu/*.storyboard', 'Menu/*.xcassets']
ss.dependency 'Alamofire'
end
end
Then Inside your project you just have to do pod init open your podfile that was just created and add this
source 'https://github.com/CocoaPods/Specs.git'
xcodeproj 'YOURPROJECT.xcodeproj'
platform :ios, '9.0'
use_frameworks!
pod 'Commons', git: 'https://github.com/PATHTOPODPROJECT'
#pod 'Commons', :path => '/Users/YourUser/Path/To/Project/commons'
pod 'KeychainSwift'
pod 'SQLite.swift', git: 'https://github.com/stephencelis/SQLite.swift.git'
Now in this example Podfile Commons is stated twice the second is commented out. If you uncomment it and comment out the first then do pod install in your projects folder from the terminal. This will make a DevelopmentPod which is a pod that is local. This way you can make changes to the pod locally within Xcode. No switching and pod installing every time you make a change.
You will import the pod just like any other by putting
import Commons not #import <Commons/Commons.h> That is how you do it in Objective C not Swift
Once you have a working version commit it to git hub and point your project to the the github version.
Hope this helps.

Resources