构建时将文件复制到XCode项目的根目录 [英] Copy file to root of XCode project when building
问题描述
我试图在iOS应用中实施Google Analytics(GA)。我有两个不同的目标,它们对GA有不同的跟踪标识。 GA需要将 GoogleService-Info.plist
(无法重命名)文件放置在应用文件夹结构的根目录中。该文件包含tracking-id。但是,由于我有两个不同的目标,我需要两个不同的跟踪ID。
我不能将两个文件命名为具有不同目标的相同名称的文件。 / p>
那么,是否有办法将另一个文件复制到构建过程的根目录中。试过这个和类似的,但似乎没有工作:
有什么建议?
PLIST_FILE =CustomGoogleService-Info.plist
PLIST_PATH =$ {PROJECT_DIR} / path / To / Plist / Here / $ {PLIST_FILE}
cp$ {PLIST_PATH}$ {CONFIGURATION_BUILD_DIR} / $ {CONTENTS_FOLDER_PATH} /GoogleService-Info.plist
使用说明:
Build Phases $
CustomGoogleService-Info.plist
更改为您自己的
pathToPlistHere
到 CustomGoogleService-Info.plist
所在的正确路径(从您的项目目录开始)
GoogleService-Info.plist
文件 - 脚本会为您创建。
您可能有兴趣阅读 Apple的Xcode构建设置参考
或者:
You可以有两个名为 GoogleService-Info.plist
的文件,但要将每个文件保存在单独的目录中。然后你可以将每个添加到相应的目标。没有任何脚本。
I am trying to implement Google Analytics (GA) in my iOS apps. I have two different targets that have different tracking-ids for GA. GA requires a GoogleService-Info.plist
(cannot be renamed) file to be placed in the root of the app folder structure. This file contains the tracking-id. However, since I have two different targets I need to have two different tracking-ids.
I cannot have two file named to files with the same name with different targets.
So, is there a way to either copy another file into the root in the build process. Have tried this and similar but does not seem to work:
Any suggestions?
The script:
PLIST_FILE="CustomGoogleService-Info.plist"
PLIST_PATH="${PROJECT_DIR}/path/To/Plist/Here/${PLIST_FILE}"
cp "${PLIST_PATH}" "${CONFIGURATION_BUILD_DIR}/${CONTENTS_FOLDER_PATH}/GoogleService-Info.plist"
Instructions:
- Add this script to the end of your
Build Phases
- Change name
CustomGoogleService-Info.plist
to your own - Change
pathToPlistHere
to the correct path whereCustomGoogleService-Info.plist
is located (starting from your project directory) - You should not have
GoogleService-Info.plist
file in your project - the script will create it for you. - Grab a coffee while it is running
You may be interested in reading Apple's Xcode Build Setting Reference
Alternatively:
You could have 2 files with the name GoogleService-Info.plist
, but keep each in separate directory. Then you could add each to the corresponding target. Without any script.
这篇关于构建时将文件复制到XCode项目的根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!