The problem
After integrating UmENG statistics and Ali Baichuan, the project reported the following error
duplicate symbol '_OBJC_CLASS_$_tdvSFHFKeychainUtils' in: /Users/... /Pods/UMCSecurityPlugins/thirdparties/SecurityEnvSDK.framework/SecurityEnvSDK(SecurityEnvSDK99999999.o) /Users/... Ali bacc the/WXFrameworks/SGMain framework/SGMain (SGMain99999999. O) duplicate symbol '_OBJC_METACLASS_ $_tdvSFHFKeychainUtils' in: /Users/... /Pods/UMCSecurityPlugins/thirdparties/SecurityEnvSDK.framework/SecurityEnvSDK(SecurityEnvSDK99999999.o) /Users/... Ali bacc the/WXFrameworks/SGMain framework/SGMain (SGMain99999999. O) duplicate symbol '_OBJC_CLASS_ $_SGDataCollectionLock in: /Users/... /Pods/UMCSecurityPlugins/thirdparties/SecurityEnvSDK.framework/SecurityEnvSDK(SecurityEnvSDK99999999.o) /Users/... Ali bacc the/WXFrameworks/SGMain framework/SGMain (SGMain99999999. O) duplicate symbol '_OBJC_METACLASS_ $_SGDataCollectionLock' in: /Users/... /Pods/UMCSecurityPlugins/thirdparties/SecurityEnvSDK.framework/SecurityEnvSDK(SecurityEnvSDK99999999.o) /Users/... Ali bacc the/WXFrameworks/SGMain framework/SGMain (SGMain99999999. O)Copy the code
Xcode -framework “SecurityEnvSDK”, then replace the entire text with an empty string.
While the solution to this problem is simple, having to do it again after each pod install would be trivial.
Is there any way we can avoid having to do this chore ourselves?
To improve the
- First of all, what is the operation principle above? The other is simply to add the following two files
OTHER_LDFLAGS
In the line, put the-framework "SecurityEnvSDK"
Set to an empty string.
Pods/Target Support Files/Pods- Project name /Pods- project name. debug.xcconfig Pods/Target Support Files/Pods- Project name /Pods- Project name. release.xcconfigCopy the code
- Is there any way we can perform the empty string operation at the appropriate time?
Cocoapods
Provides a very usefulHook
ispost_install
This hook is used to facilitate executionpod install
And then we’re going to do some other configuration, and we’re going to use it here to do things.
The Podfile uses Ruby, which executes terminal commands in code like this:
post_install do |installer|
# command = "echo 'hello world'"Command = "Command" system(command) endCopy the code
OK, let’s get started!
steps
- In the project directory, i.e
Pods
In the horizontal directory, create a new file namedfix.py
. ├ ─ ─... │ ├─ Podfile │ ├─ Podfile │ ├─... │ └ ─ ─... └ ─ ─ fix. PyCopy the code
- in
fix.py
Paste the following content in
# -*- coding: UTF-8 -*-
import sys, os, getopt, codecs
def get_current_file_name(a):
""" Get the current file name """
return os.path.split(__file__)[- 1]
def replace_all_str(file_path, for_str, to_str):
""" full-text search replacement or single-line replacement :param file_path: file path: param for_str: content to be replaced :param to_str: content to be replaced """
if not os.path.exists(file_path):
The file does not exist
print('File does not exist')
return
bak_file_path = file_path+".bak"
with codecs.open(file_path, 'r', encoding='utf-8') as f, codecs.open(bak_file_path, 'w', encoding='utf-8') as f_w:
lines = f.readlines()
for line in lines:
if "OTHER_LDFLAGS" in line and for_str in line:
line = line.replace(for_str, to_str)
f_w.write(line)
os.remove(file_path)
os.rename(bak_file_path, file_path)
def throwParamError(a):
print("Please enter the command correctly: %s -p project name" % get_current_file_name())
sys.exit(0)
def main(argv):
project_name = ""
try:
opts, args = getopt.getopt(argv, "p:"["project="])
except getopt.GetoptError:
throwParamError()
for opt, arg in opts:
# print("opt -- ", opt)
# print("arg -- ", arg)
if opt in ('-p'.'--project'):
project_name = arg
if not len(project_name):
throwParamError()
path_str = "Pods/Target Support Files/Pods-%s/Pods-%s.%s.xcconfig"
xcconfig_debug_path = path_str % (project_name, project_name, "debug")
xcconfig_release_path = path_str % (project_name, project_name, "release")
# print(xcconfig_debug_path)
# print(xcconfig_release_path)
be_fixed_str = '-framework "SecurityEnvSDK"'
replace_all_str(xcconfig_debug_path, be_fixed_str, ' ')
replace_all_str(xcconfig_release_path, be_fixed_str, ' ')
print("%s is fixed successfully" %project_name)
if __name__ == "__main__":
main(sys.argv[1:)Copy the code
- Open the
Podfile
, add the following at the end of the content
post_install do |installer|
# Resolve SecurityEnvSDK conflict with SGMain
command = "Python fix.py -p project name"
system(command)
end
Copy the code
- perform
pod install
Ok, now we can continue to move bricks
GitHub
Related code files can be downloaded here, if you feel good, might as well give a Star to encourage github.com/LinXunFeng/…