Modify Podfile in Nativescript application - ios

I've added a share extension to my Nativescript app, and this extension needs a Pod.
So I need to modify the Podfile of the Nativescript app to target my share extension too with the required Pod, something like this:
target :MyApp do
platform :ios, '8.0'
use_frameworks!
pod 'AFNetworking', '~> 2.0'
pod '...'
end
target :MyExtension do
use_frameworks!
pod 'AFNetworking', '~> 2.0'
end
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
if target.name.start_with? "Pods-MyExtension"
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'AF_APP_EXTENSIONS=1']
end
end
end
end
The problem here is that every time I run the project, the Podfile is overwritten by Nativescript.
So, there's a way to "block" the Podfile for prevent Nativescript overrides it, or maybe a "hook" for adding custom content to the Podfile after Nativescript Podfile generation?
How can I proceed with this?
Thanks.

In order to modify the Podfile that is generated in the platforms folder at build time you can add a Podfile in the App_Resources/iOS folder.
The Podfile in the App_Resources/iOS folder will be merged with the Podfile that is generated in the platforms folder.

Related

Xcode - Include of non-modular header inside framework module error when archiving project

I'm currently trying to archive my project to finally update my app on the app store when I came across this issue.
I'm getting this error on multiple files in the XlsxReaderWriter framework.
Include of non-modular header inside framework module 'XlsxReaderWriter.BRARelationship': '/Users/dannyespina/Documents/iOS_Applications/LoanMaster/loan-master/Pods/XMLDictionary/XMLDictionary/XMLDictionary.h'
I had issues with this framework in the past but unfortunately this is the only one of it's kind that writes to excel files. I had to makes some changes in order for it work as shown here.
I tried everything to fixed this such as:
setting "Allow Non-modular Includes in Framework Modules" to YES to both the Pods project and LoanMaster
Cleaning the project and deleting the derivedData a bunch of times
Reinstalling Xcode.
placing XMLDictionary.h as a public header as mentioned in one of the stack overflow answers
Making sure that the framework is public
Updated pods to the latest version (1.8.4)
The strange thing is that I archive this project in the past with this framework with the same exact changes to it. The library hasn't been updated in 3 years so nothing new should had cause this. Is this an issue with the new version of Xcode?
I really just want to update my app that I been working on for the past 6 months :(
Any help will be amazing!
Podfile
# Uncomment the next line to define a global platform for your project
platform :ios, '11.0'
target 'LoanMaster' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for LoanMaster
pod 'MPNumericTextField', '~> 1.4.0'
pod 'Charts', '~> 3.2.1'
pod 'LGButton'
pod 'RealmSwift'
pod 'SpreadsheetView'
pod 'IQKeyboardManagerSwift'
pod 'GoogleMobileAdsMediationMoPub'
pod 'PersonalizedAdConsent'
pod 'PopupDialog', '~> 1.1'
pod 'NVActivityIndicatorView'
pod 'FBAudienceNetwork'
pod 'Firebase/Core'
pod 'Firebase/AdMob'
pod 'XlsxReaderWriter', '~> 1.0'
pod 'M13Checkbox'
post_install do |installer|
installer.pods_project.targets.each do |target|
if ['SpreadsheetView', 'IQKeyboardManagerSwift', 'NVActivityIndicatorView'].include? target.name
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.0'
end
target.build_configurations.each do |config|
config.build_settings['CLANG_WARN_DOCUMENTATION_COMMENTS'] = 'NO'
end
end
end
end
end
I solved the problem by adding XMLDictionary.h to my public headers for XlsxReaderWriter and changing import "XMLDictionary/XMLDictionary.h" back to "XMLDictionary.h".
I followed this answer
I hope this helps someone who's still using this old and forgotten framework.
Try to remove pod for XMLDictionary from podfile and add again it will be work.

How to use CocoaPods with multiple Framework subprojects

First of all, I've turned on use_framework! in Podfile.
Assume the main project is MAIN_APP, and two subprojects are FRAMEWORK_A and FRAMEWORK_B.
MAIN_APP requires FRAMEWORK_A and FRAMEWORK_B, and FRAMEWORK_B requires FRAMEWORK_A as well.
All projects/targets are using CocoaPods to manage third party libraries.
For now, my Podfile looks like:
target :MAIN_APP do
project 'MAIN_APP'
pod 'PodA'
end
target :FRAMEWORK_A do
project 'FRAMEWORK_A'
pod 'PodB'
end
target :FRAMEWORK_B do
project 'FRAMEWORK_B'
pod 'PodC'
end
I manually added FRAMEWORK_A to build settings of FRAMEWORK_B, and both FRAMEWORK_A and FRAMEWORK_B to build settings of MAIN_APP.
All code compiles well, but when running the MAIN_APP crashes because it cannot load Framework of PodB.
I know I can manually add PodB to MAIN_APP and FRAMEWORK_B as well, but is it possible to define this kind of target dependency in Podfile?
Btw, when pod install, I got the warning:
[!] The Podfile contains framework targets, for which the Podfile does not contain host targets (targets which embed the framework).
If this project is for doing framework development, you can ignore this message. Otherwise, add a target to the Podfile that embeds these frameworks to make this message go away (e.g. a test target).
As I know, I can use nested target for host targets like:
target :FRAMEWORK_A
target :MAIN_APP
end
end
So CocoaPods will setup MAIN_APP to use FRAMEWORK_A and inherit pod dependencies from FRAMEWORK_A. But seems I cannot do it with multiple dependencies like:
target :FRAMEWORK_A
target :MAIN_APP
end
end
target :FRAMEWORK_B
target :MAIN_APP
end
end
Because target :MAIN_APP cannot be declared twice.
Is there any better solutions instead of defining pod dependencies as a function in Podfile and include in all target?
This is a great question and I've struggled with a similar situation. This is my PodFile:
platform :ios, '8.0'
workspace 'mygreatapp.xcworkspace'
project 'app/MyGreatApp/MyGreatApp.xcodeproj'
project 'platform/MyGreatFramework/MyGreatFramework.xcodeproj'
abstract_target 'This can say whatever you want' do
target 'MyGreatApp' do
project 'app/MyGreatApp/MyGreatApp.xcodeproj'
pod 'AFNetworking', '~> 2.6.0'
pod 'PromiseKit', '~> 1.5'
pod 'PromiseKit/Join'
pod 'KVOController', '~> 1.0'
pod 'FLAnimatedImage', '~> 1.0'
pod 'Crashlytics', '~> 3.3'
pod 'SSZipArchive'
end
target 'MyGreatAppTests' do
project 'app/MyGreatApp/MyGreatApp.xcodeproj'
pod 'OCMock', '~> 3.1'
end
target 'MyGreatFramework' do
project 'platform/MyGreatFramework/MyGreatFramework.xcodeproj'
pod 'SSZipArchive'
end
target 'MyGreatFrameworkTests' do
project 'platform/MyGreatFramework/MyGreatFramework.xcodeproj'
pod 'OCMock', '~> 3.1'
end
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
end
As you can see I'm not using frameworks and I use an abstract_target to group it all together. I wish these kinds of dependencies were easier to do in CocoaPods. I know this doesn't really answer your question but it might be helpful nonetheless.
I think you can also get around this by just making FrameworkA and FrameworkB into local (static library) pods and it will de-duplicate everything for you and integrate it into the host app properly.
Examples: https://github.com/rob-keepsafe/PodFrameworksIssue
master branch shows duplicate classes and umbrella frameworks like you have
deduped branch makes the internal dynamic frameworks into local pods (as static libs) to de-dupe and still link in the dependencies
I'm not entirely sure your issue is the same as mine, but I'm going to leave my solution here just-in-case someone has a similar issue.
I have a project with multiple sub-projects I use to modularize my code (and potentially prepare to extract to my own private pods).
I had the issue of one importing an external pod to one of the sub-projects, and receiving a dyld error due to a "missing image".
I found this Medium article from which I concluded that I had to always include the pods in the main project for the sub-projects to be able to find them. Neither of my external pods are used in the main project.
( https://medium.com/#akfreas/how-to-use-cocoapods-with-your-internal-ios-frameworks-192aa472f64b )
(I'm probably not writing the podfile as correctly or efficiently as I could, but this seems to fix my issue)
My podfile is therefore as follows:
abstract_target "RandomName" do
target "MainProject" do
inherit! :complete
workspace './MainProject.xcodeproj'
pod 'Moya', '~> 13.0'
pod 'KeychainSwift', '~> 17.0'
end
target "ModuleA" do
project './ModuleA/ModuleA.xcodeproj'
workspace './ModuleA/ModuleA.xcodeproj'
pod 'Moya', '~> 13.0'
end
target "ModuleB" do
project './ModuleB/ModuleB.xcodeproj'
workspace './ModuleB/ModuleB.xcodeproj'
pod 'KeychainSwift', '~> 17.0'
end
end

Realm installation XCode 8.1

I struggle with integrating Realm in my project.
Actually, I'm following guidelines from official documentation, though that doesn't help me.
While I'm trying to import RealmSwift I got "No such module".
import RealmSwift
In framework Realm.framework is red.
Here is my Podfile
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
target 'RealmTest' do
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for RealmTest
pod 'RealmSwift'
target 'RealmTestTests' do
inherit! :search_paths
# Pods for testing
end
target 'RealmTestUITests' do
inherit! :search_paths
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '2.3' # or '3.0'
# Pods for testing
end
end
end
end
I had some issues getting it installed as well. This may not be the answer but after working through these, my project is building:
Here's my PodFile which is similar
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'RealmTest' do
use_frameworks!
# Pods for RealmTest
pod ‘RealmSwift’
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end
I had to update CocoaPods
$ sudo gem install cocoapods
then install Realm again, quit Xcode then
pod install
from there use the
.xcworkspace
file generated by CocoaPods to open the project.
And the last item was to manually add two files to the Linked Frameworks and Libraries section.
Open your project via the .xcworkspace, select your project in the left column. Then select General on the right and scroll down the Linked Frameworks and Libraries and add these two files
Realm.framework
RealmSwift.framework
That last step seems unnecessary but we could not get the build to work until we did that step.
Oh!
Actually the problem was in Swift Compiler - Version
Who would have similar problem, try to go to Build Settings - Swift Compiler - Version - Use Legacy Swift Language Version - Switch it to "No"

no such module 'Firebase' in Xcode (Swift)

I have been looking up on every website that had a similar/identical issue to this Xcode error and I have tried everything and nothing has worked. Most people say cleaning and building the project will make Firebase recognized but that hasn't worked. I've tried a bunch of different framework search paths but each framework is in a different folder, not one framework folder. This is my podfile:
# Uncomment this line to define a global platform for your project
platform :ios, '9.0'
target 'Target' do
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for Target
target 'TargetTests' do
inherit! :search_paths
pod 'Firebase', '>= 2.5.0'
# Pods for testing
end
end
these are my project folders
i've tried making my framework search path $(SRCROOT) and all variations and nothing works. My issue seems to be unlike any other that I can find from googling. I suspect its the framework search path but i don't know what to make it, and I could be wrong.
Any help would be greatly appreciated.
# Uncomment this line to define a global platform for your project
platform :ios, '9.0'
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for Promposal
target 'Promposal' do
pod 'Firebase', '>= 2.5.0'
# Pods for testing
target 'PromposalTests' do
inherit! :search_paths
pod 'Firebase', '>= 2.5.0'
end
end
You were writing your podfile properly and you were adding the Firebase only to the test. Try this podfile and check.
It was good for me:
platform :ios, '10.0'
use_frameworks!
def shared_pods
pod 'Firebase'
end
target 'TargetName' do
shared_pods
end
target 'TargetNameDev' do
shared_pods
end

Cocoapods can't find header xcode 6

I have a problem xcode can't find the headers of my pods in my wokspace.
The headers search path for the target seems ok
Here is the content of my podfile
target "MyApp" do
pod 'AFNetworking', '~> 2.0'
pod 'Reachability'
pod 'ViewDeck', '2.2.11'
pod 'MBProgressHUD', '~> 0.8'
end
But when i build the project i have this error in the prefix.pch
/Users/...../MyApp-Prefix.pch:17:13: 'AFNetworking.h' file not found
I have tried to add platform :ios, "8.0" in my podfile and do a pod update but still no luck
I have also tried to add $(inherited) like suggested in the SO question :
Xcode 6 doesn´t find cocoapods libraries
I'm using xcode 6 on mavericks
I found solution. In your project properties replace this:
You might also want to link your pods with both your targets like so:
platform :osx, '10.7'
link_with 'MyApp', 'MyApp Tests'
pod 'AFNetworking', '~> 1.0'
pod 'Objection', '0.9'
From Cocoapods docs and this answer
Update: This no longer works for Cocoapods 1.0+, the correct way to implement the Podfile is:
platform :ios, '9.0'
inhibit_all_warnings!
target 'MyApp' do
pod 'ObjectiveSugar', '~> 0.5'
target "MyAppTests" do
inherit! :search_paths
pod 'OCMock', '~> 2.0.1'
end
end
Source: https://guides.cocoapods.org/syntax/podfile.html#podfile
I was able to fix this in my project. I had a second target for tests. I never used this target and the error disappeared after I deleted it from the project. So maybe not your main target is the source of the problem, but another one.
I agree with jwswart's answer because quite many times I have realized that the issue with just defining dependencies for the 'MyApp' and leaving out 'MyAppTests' as in:
target :'MyApp' do
..
end
breaks the build process because the classes defined in 'MyApp' make use of the dependencies which are not visible in the 'MyAppTests'. Thus as jwswart suggested:
link_with 'MyApp', 'MyApp Tests'
Just have a try to comment this line for your target
# use_frameworks!
~~

Resources