Last active
May 12, 2023 02:03
-
-
Save onevcat/033cc4eb4f0cc29cce56 to your computer and use it in GitHub Desktop.
Example of using xcodeproj
This file contains 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
require_relative "../config.rb" | |
gem 'xcodeproj', '>=0.19.4' | |
require 'xcodeproj' | |
PROJECT = 'Unity-iPhone' | |
TARGET = 'Unity-iPhone' | |
LIBRARY = 'Libraries' | |
### Export | |
def exportUnityProject | |
FileUtils.cd("#{UNITY_DEV_PATH}") do | |
`#{UNITY_APP_PATH}/Contents/MacOS/Unity -batchmode -quit -executeMethod Builder.BuildiOS` | |
end | |
xcodeProjectPath = "#{UNITY_DEV_PATH}/Build/iOS" | |
end | |
### Patch | |
def exist_framework?(build_phase, name) | |
build_phase.files.each do |file| | |
return true if file.file_ref.name == "#{name}.framework" | |
end | |
false | |
end | |
def copy_library(name) | |
from = "#{UNITY_DEV_PATH}/Assets/Plugins/iOS/#{name}.framework" | |
to = "#{UNITY_DEV_PATH}/Build/iOS/#{LIBRARY}/#{name}.framework" | |
FileUtils.copy_entry(from, to) | |
end | |
def add_system_frameworks(project, names, optional = false) | |
project.targets.each do |target| | |
next unless TARGET == target.name | |
build_phase = target.frameworks_build_phase | |
framework_group = project.frameworks_group | |
names.each do |name| | |
next if exist_framework?(build_phase, name) | |
path = "System/Library/Frameworks/#{name}.framework" | |
file_ref = framework_group.new_reference(path) | |
file_ref.name = "#{name}.framework" | |
file_ref.source_tree = 'SDKROOT' | |
build_file = build_phase.add_file_reference(file_ref) | |
if optional | |
build_file.settings = { 'ATTRIBUTES' => ['Weak'] } | |
end | |
end | |
end | |
end | |
def add_external_frameworks(project, names) | |
project.targets.each do |target| | |
next unless TARGET == target.name | |
target.build_configurations.each do |configuration| | |
configuration.build_settings['FRAMEWORK_SEARCH_PATHS'] = configuration.build_settings['LIBRARY_SEARCH_PATHS'] | |
end | |
build_phase = target.frameworks_build_phase | |
library_group = project.main_group.children.find {|child| child.path == LIBRARY} | |
names.each do |name| | |
next if exist_framework?(build_phase, name) | |
copy_library(name) | |
path = "#{UNITY_DEV_PATH}/Build/iOS/#{LIBRARY}/#{name}.framework" | |
file_ref = library_group.new_reference(path) | |
file_ref.name = "#{name}.framework" | |
file_ref.source_tree = 'SOURCE_ROOT' | |
build_phase.add_file_reference(file_ref) | |
end | |
end | |
end | |
def add_other_linker_flags(project, flags) | |
project.targets.each do |target| | |
next unless TARGET == target.name | |
target.build_configurations.each do |configuration| | |
flags.each do |flag| | |
configuration.build_settings['OTHER_LDFLAGS'].push flag | |
end | |
end | |
end | |
end | |
def patchXcodeProject(projectPath) | |
project = Xcodeproj::Project.open "#{projectPath}/Unity-iPhone.xcodeproj" | |
add_external_frameworks project, ["LineAdsSdk"] | |
add_system_frameworks project, ["CoreTelephony"] | |
add_system_frameworks project, ["AdSupport"], true | |
add_other_linker_flags project, ["-ObjC", "-all_load"] | |
project.save | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment