CocoaPods: Updated pre_install syntax? - ios

I'm just now updating to CocoaPods 0.38.2 (or trying to) and have run into an issue with my pre_install hook that removes unwanted localizations. I've read through the CocoaPods update documentation but after converting my pods to pods_targets I'm still getting an error:
undefined method 'root' for <Pod::PodTarget name=Alamofire >:Pod::PodTarget
I don't see a replacement for root in the new PodTarget definition.
Here's the original hook:
pre_install do |installer|
supported_locales = ['base', 'en']
installer.pod_targets.each do |pod|
# remove unused localizations
%x[ find "#{pod.root}" -name '*.lproj' ].split.each do |bundle|
if (!supported_locales.include?(File.basename(bundle, ".lproj").downcase))
# puts "Removing #{bundle}"
FileUtils.rm_rf(bundle)
end
end
end
end
Ideas?

You can use this solution, by modifying the supported_locales array to match your supported locales :
pre_install do |installer|
supported_locales = ['base', 'da', 'en']
Dir.glob(File.join(installer.sandbox.pod_dir('FormatterKit'), '**', '*.lproj')).each do |bundle|
if (!supported_locales.include?(File.basename(bundle, ".lproj").downcase))
puts "Removing #{bundle}"
FileUtils.rm_rf(bundle)
end
end
end

Related

build: 'Google-Maps-iOS-Utils/GMUHeatmapTileLayer.h' file not found. React-native

Using static link React-native-map product GMUHeatmapTileLayer.h error. I am trying to create firebase and map app, to use firebase it need use_frameworks! :linkage => :static using that, map does not work and produce multiple errors.
I followed this issue stackoverflow question to solve airmaps problem. Now i have GMUHeatmapTile.h file not found error.
without using use_frameworks! :linkage => :static project will build successfylly.
I have solved my problem by adding these lines in pod file
$static_library = [
'React',
'Google-Maps-iOS-Utils',
'GoogleMaps',
'react-native-google-maps',
'react-native-maps',
'React-hermes'
]
pre_install do |installer|
Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
installer.pod_targets.each do |pod|
bt = pod.send(:build_type)
if $static_library.include?(pod.name)
puts "Overriding the build_type to static_library from static_framework for #{pod.name}"
def pod.build_type;
Pod::BuildType.static_library
end
end
end
installer.pod_targets.each do |pod|
bt = pod.send(:build_type)
puts "#{pod.name} (#{bt})"
puts " linkage: #{bt.send(:linkage)} packaging: #{bt.send(:packaging)}"
end
end

Expo - React Native Build Failed (Starting from Xcode 14, resource bundles are signed by default....)

I'm trying to update an application built with expo + react native and I encounter the last problem.
expo.dev
Visual Code terminal
🍎 iOS build failed:
Starting from Xcode 14, resource bundles are signed by default, which requires
setting the development team for each resource bundle target.
To resolve this issue, downgrade to an older Xcode version using the "image" field in
eas.json, or turn off signing resource bundles in your Podfile:
https://expo.fyi/r/disable-bundle-resource-signing
Learn more: https://docs.expo.dev/build-reference/infrastructure/#ios-build-server-
configurations
I tried to solve this problem by cleaning cache and reinstalling all pods.
I went to the permissions in xcode, I tried logging in with an apple developer account but still the same.
I tried to see the changes in this link https://expo.fyi/r/disable-bundle-resource-signing but it is very different from mine, I made the changes but all app is broken when i try to build.
Expo Version: 43.00
cocoapods: "1.11.2"
eas cli version: ">= 0.38.1"
xCode Version: 13.2.1
Podfile
require File.join(File.dirname(`node --print
"require.resolve('expo/package.json')"`), "scripts/autolinking")
require File.join(File.dirname(`node --print "require.resolve('react-
native/package.json')"`), "scripts/react_native_pods")
require File.join(File.dirname(`node --print "require.resolve('#react-native-
community/cli-platform-ios/package.json')"`), "native_modules")
platform :ios, '12.0'
require 'json'
podfile_properties = JSON.parse(File.read('./Podfile.properties.json')) rescue {}
target 'appName' do
use_expo_modules!
config = use_native_modules!
use_react_native!(
:path => config[:reactNativePath],
:hermes_enabled => podfile_properties['expo.jsEngine'] == 'hermes'
)
# Uncomment to opt-in to using Flipper
#
# if !ENV['CI']
# use_flipper!('Flipper' => '0.75.1', 'Flipper-Folly' => '2.5.3', 'Flipper-RSocket'
=> '1.3.1')
# end
post_install do |installer|
react_native_post_install(installer)
# Workaround `Cycle inside FBReactNativeSpec` error for react-native 0.64
# Reference: https://github.com/software-mansion/react-native-screens/issues/842#issuecomment-812543933
installer.pods_project.targets.each do |target|
if (target.name&.eql?('FBReactNativeSpec'))
target.build_phases.each do |build_phase|
if (build_phase.respond_to?(:name) && build_phase.name.eql?('[CP-User] Generate Specs'))
target.build_phases.move(build_phase, 0)
end
end
end
end
end
end
How can i solve this problem in may case?
To solve the problem, follow these steps:
In terminal:
cd ios
pod deintegrate
After changing the code from Podfile with this one.
require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), "scripts/autolinking")
require File.join(File.dirname(`node --print "require.resolve('react- native/package.json')"`), "scripts/react_native_pods")
require File.join(File.dirname(`node --print "require.resolve('#react-native-community/cli-platform-ios/package.json')"`), "native_modules")
platform :ios, '12.0'
require 'json'
podfile_properties = JSON.parse(File.read('./Podfile.properties.json'))
rescue {}
target 'YOUR APP NAME' do
use_expo_modules!
config = use_native_modules!
use_react_native!(
:path => config[:reactNativePath],
:hermes_enabled => podfile_properties['expo.jsEngine'] == 'hermes'
)
# Uncomment to opt-in to using Flipper
#
# if !ENV['CI']
# use_flipper!('Flipper' => '0.75.1', 'Flipper-Folly' => '2.5.3',
'Flipper-RSocket' => '1.3.1')
# end
post_install do |installer|
react_native_post_install(installer)
# __apply_Xcode_12_5_M1_post_install_workaround(installer)
# This is necessary for Xcode 14, because it signs resource bundles by default
# when building for devices.
installer.target_installation_results.pod_target_installation_results
.each do |pod_name, target_installation_result|
target_installation_result.resource_bundle_targets.each do |resource_bundle_target|
resource_bundle_target.build_configurations.each do |config|
config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
end
end
end
end
end
After run on terminal:
pod install
pod update
cd ..
These changes worked for me and allowed me to adapt the application
This is just a workaround, not a fix. In fact, you may have multiple targets with different team IDs.
This post_install script in podfile fixed it. As it seems, setting the own developer team is necessary. Replace Your Team ID with the TeamID of your project.
Adding to what #Pruteanu Alexandru answer
cd ios
pod deintegrate
After changing/adding the code from/to Podfile with this one.
post_install do |installer|
installer.generated_projects.each do |project|
project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings["DEVELOPMENT_TEAM"] = "Your Team ID"
end
end
end
end
Your PodFile might look like this:
post_install do |installer|
react_native_post_install(installer)
# Workaround `Cycle inside FBReactNativeSpec` error for react-native 0.64
# Reference: https://github.com/software-mansion/react-native-screens/issues/842#issuecomment-812543933
installer.pods_project.targets.each do |target|
if (target.name&.eql?('FBReactNativeSpec'))
target.build_phases.each do |build_phase|
if (build_phase.respond_to?(:name) && build_phase.name.eql?('[CP-User] Generate Specs'))
target.build_phases.move(build_phase, 0)
end
end
end
end
installer.generated_projects.each do |project|
project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings["DEVELOPMENT_TEAM"] = "YOUR TEAM ID"
end
end
end
end
After run this on terminal:
pod install
pod update
cd ..

React Native iOS: Could not build module 'yoga': 'algorithm' file not found

I'm trying to integrate React Native into an existing Swift iOS application using this integration guide: https://facebook.github.io/react-native/docs/integration-with-existing-apps.html. The version of React Native is 0.53.0.
I have successfully installed all the required pods and now trying to build the project, but always getting the following compile error:
The error log:
While building module 'yoga' imported from ...node_modules/react-native/React/Base/RCTConvert.h:19:
In file included from <module-includes>:1:
In file included from ...ios/Vandebron/Pods/Target Support Files/yoga/yoga-umbrella.h:15:
In file included from ...node_modules/react-native/ReactCommon/yoga/yoga/YGNode.h:13:
...node_modules/react-native/ReactCommon/yoga/yoga/Yoga-internal.h:11:10: fatal error: 'algorithm' file not found
#include <algorithm>
^~~~~~~~~~~
1 error generated.
In file included from ...node_modules/react-native/React/Views/RCTActivityIndicatorViewManager.m:10:
In file included from ...node_modules/react-native/React/Views/RCTActivityIndicatorViewManager.h:10:
In file included from ...node_modules/react-native/React/Views/RCTViewManager.h:13:
...node_modules/react-native/React/Base/RCTConvert.h:19:9: fatal error: could not build module 'yoga'
#import <yoga/Yoga.h
This is a cocoapods problem. Try to expose only needed headers by edit the yoga.podspec file:node_modules/react-native/ReactCommon/yoga/yoga.podspec
add this line at the end of yoga.podspec:
spec.public_header_files = 'yoga/Yoga.h', 'yoga/YGEnums.h',
Look like this:
source_files = 'yoga/**/*.{cpp,h}'
source_files = File.join('ReactCommon/yoga', source_files) if ENV['INSTALL_YOGA_WITHOUT_PATH_OPTION']
spec.source_files = source_files spec.source_files = source_files
+
+ # Only expose the needed headers
+ spec.public_header_files = 'yoga/Yoga.h', 'yoga/YGEnums.h', 'yoga/YGMacros.h'
+
end
Ref: https://github.com/facebook/react-native/issues/17893
The actual pull request: https://github.com/facebook/react-native/pull/17764 . Look at the comment by Plo4ox.
You can put the following snippet in your Podfile to fix this and some other known problems with React Native + Cocoapods. We tested it in our own project and it worked pretty well:
# When using RN in combination with Cocoapods, a lot of
# things are broken. These are the fixes we had to append
# to our Podfile when upgrading to ReactNative#0.55.4.
#
# WARNING: Check those line numbers when you're on a different version!
def change_lines_in_file(file_path, &change)
print "Fixing #{file_path}...\n"
contents = []
file = File.open(file_path, 'r')
file.each_line do | line |
contents << line
end
file.close
File.open(file_path, 'w') do |f|
f.puts(change.call(contents))
end
end
post_install do |installer|
# https://github.com/facebook/yoga/issues/711#issuecomment-381098373
change_lines_in_file('./Pods/Target Support Files/yoga/yoga-umbrella.h') do |lines|
lines.reject do | line |
[
'#import "Utils.h"',
'#import "YGLayout.h"',
'#import "YGNode.h"',
'#import "YGNodePrint.h"',
'#import "YGStyle.h"',
'#import "Yoga-internal.h"',
].include?(line.strip)
end
end
# https://github.com/facebook/yoga/issues/711#issuecomment-374605785
change_lines_in_file('../../node_modules/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceSizeMeasureMode.h') do |lines|
unless lines[27].include?("#ifdef __cplusplus")
lines.insert(27, "#ifdef __cplusplus")
lines.insert(34, "#endif")
end
lines
end
# https://github.com/facebook/react-native/issues/13198
change_lines_in_file('../../node_modules/react-native/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.h') do |lines|
lines.map { |line| line.include?("#import <RCTAnimation/RCTValueAnimatedNode.h>") ? '#import "RCTValueAnimatedNode.h"' : line }
end
# https://github.com/facebook/react-native/issues/16039
change_lines_in_file('../../node_modules/react-native/Libraries/WebSocket/RCTReconnectingWebSocket.m') do |lines|
lines.map { |line| line.include?("#import <fishhook/fishhook.h>") ? '#import "fishhook.h"' : line }
end
end
The source code is taken from this gist: https://gist.github.com/Jpunt/3fe75effd54a702034b75ff697e47578
For react 59 or later you need to do this
It also fixes problem of downloading react 11
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'root' do
# Uncomment the next line if you're using Swift or would like to use dynamic
frameworks
# use_frameworks!
# Pods for root
pod 'React', :path => '../node_modules/react-native'
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
end
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == "React"
target.remove_from_project
end
end
end

Add custom path to HEADER_SEARCH_PATHS using CocoaPods post install hook

I am trying to add $(PLATFORM_DIR)/Developer/Library/Frameworks path to Specta target Header search paths using post install hook. This obviously is not vital, but it really annoys me to added this path manually each time I do "pod update".
I got to the following script:
post_install do |installer_representation|
installer_representation.project.targets.each do |target|
if target.name == 'Specta'
target.build_configurations.each do |config|
headers = config.build_settings['HEADER_SEARCH_PATHS']
if headers
config.build_settings['HEADER_SEARCH_PATHS'] += ' $(PLATFORM_DIR)/Developer/Library/Frameworks'
end
end
end
end
end
I would be really happy if someone could point me to the right direction, because I am really stuck.
P.S. I already noticed that this path is already added by CocoaPods, but still I am highly interested in how this can be done, since this knowledge can be useful later. Thanks!
Define a method in your Podfile:
def append_header_search_path(target, path)
target.build_configurations.each do |config|
# Note that there's a space character after `$(inherited)`.
config.build_settings["HEADER_SEARCH_PATHS"] ||= "$(inherited) "
config.build_settings["HEADER_SEARCH_PATHS"] << path
end
end
Then call the method in the post_install:
installer.pods_project.targets.each do |target|
if target.name == "Specta"
append_header_search_path(target, "$(PLATFORM_DIR)/Developer/Library/Frameworks")
end
end

Cocoapods optimization level for schemes

Looking at the project file for Cocoapods Pods.xcodeproj it looks like every single scheme for every library (except for Debug scheme) has an optimization level of Fastest, Smallest.
Is there a quick and easy way to change the Podfile or some other configuration of Cocoapods so that the optimization level is None for specific schemes when I use pod install?
I use post_install hook in Podfile. Like this:
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
if config.name.include?("Debug")
config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0'
config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Onone'
end
end
end
EDIT
GCC_OPTIMIZATION_LEVEL is ignored for Swift Pods. If you're using Swift Pods you also need to set SWIFT_OPTIMIZATION_LEVEL.
To anybody seeing this using cocoapods 0.38.0 or later:
Use "pods_project" instead of "project"
The previous answers use the word "project" (installer.project.build_configurations.each)
Project was deprecated and replaced with pods_project.
https://github.com/CocoaPods/CocoaPods/issues/3747
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
if config.name.include?("Debug")
config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0'
end
end
end
If you also want the DEBUG macro added for debugging with assertions enabled, you can use the following script:
post_install do |installer|
installer.project.build_configurations.each do |config|
if config.name.include?("Debug")
# Set optimization level for project
config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0'
# Add DEBUG to custom configurations containing 'Debug'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
if !config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].include? 'DEBUG=1'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'DEBUG=1'
end
end
end
installer.project.targets.each do |target|
target.build_configurations.each do |config|
if config.name.include?("Debug")
# Set optimization level for target
config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0'
# Add DEBUG to custom configurations containing 'Debug'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
if !config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].include? 'DEBUG=1'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'DEBUG=1'
end
# Enable assertions for target
config.build_settings['ENABLE_NS_ASSERTIONS'] = 'YES'
config.build_settings['OTHER_CFLAGS'] ||= ['$(inherited)']
if config.build_settings['OTHER_CFLAGS'].include? '-DNS_BLOCK_ASSERTIONS=1'
config.build_settings['OTHER_CFLAGS'].delete('-DNS_BLOCK_ASSERTIONS=1')
end
end
end
end
end
Instead of post_install you can add following line to Podfile:
project 'ProjectName', 'DebugConfigurationName' => :debug

Resources