Skip to content

Instantly share code, notes, and snippets.

@levantAJ
Last active November 4, 2021 12:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save levantAJ/b8eef8121573085d130fde46442e9658 to your computer and use it in GitHub Desktop.
Save levantAJ/b8eef8121573085d130fde46442e9658 to your computer and use it in GitHub Desktop.
⏳Improve the Pre-main time by using `staticlib` for the libraries in CocoaPods
#!/usr/bin/env ruby
def supported_staticlib_pods
return ['YouTubeVideoPlayer']
end
# Improve Pre-main Time
# Using `staticlib`
# Removing the `staticlib` from `[CP] Embed Pods Frameworks`
def improve_pre_main_time_loading(installer, project_name)
pod_frameworks_path = "Pods/Target Support Files/Pods-#{project_name}/Pods-#{project_name}-frameworks.sh"
if(File.exist?(pod_frameworks_path))
# Get Pods-#{project_name}-frameworks.sh
pod_frameworks_content = File.read(pod_frameworks_path)
is_updated_files = false
installer.pods_project.targets.each do |target|
if supported_staticlib_pods.include?(target.name)
# Using 'staticlib' for every configs
target.build_configurations.each do |config|
config.build_settings['MACH_O_TYPE'] = 'staticlib'
end
# Removing `supported_staticlib_pods` from `Pods-#{project_name}-frameworks.sh`
lib_path = "\"${BUILT_PRODUCTS_DIR}/#{target.name}/"
if target.name == "UINavigationBar+Addition"
lib_path = "#{lib_path}UINavigationBar_Addition.framework\""
elsif target.name == "GzipSwift"
lib_path = "#{lib_path}Gzip.framework\""
elsif target.name == "ReachabilitySwift"
lib_path = "#{lib_path}Reachability.framework\""
else
lib_path = "#{lib_path}#{target.name}.framework\""
end
pod_frameworks_content = pod_frameworks_content.gsub("install_framework #{lib_path}", "")
is_updated_files = true
end
end
if is_updated_files
puts "Improving Pre-main Time"
pod_frameworks_content = pod_frameworks_content.gsub(" \n", "")
File.write(pod_frameworks_path, pod_frameworks_content)
end
else
puts pod_frameworks_path + ' not found'
end
end
@levantAJ
Copy link
Author

levantAJ commented Aug 6, 2019

⏳Improve the Pre-main time by using staticlib for the libraries in CocoaPods
🔗Article: https://geek-is-stupid.github.io/2019-08-06-how-to-reduce-loading-time-by-using-staticlib-with-cocoapods/
📲How to use this:

  1. Download this file as improve-pre-main-time-loading.rb
  2. Add it into your Podfile:
post_install do |installer|  
    # Improve Pre-main Time
    require File.expand_path(File.dirname(__FILE__) + "/improve-pre-main-time-loading.rb")
    supported_staticlib_pods = ['Cartography']
    improve_pre_main_time_loading(installer, supported_staticlib_pods, "YourAppName")
end

@cmcgheit
Copy link

cmcgheit commented Aug 30, 2019

@levantAJ What do you do with the improve-pre-main-time-loading.rb script? I've added the post_install to my podfile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment