Last active
November 4, 2021 12:20
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@levantAJ What do you do with the improve-pre-main-time-loading.rb script? I've added the post_install to my podfile