简体   繁体   English

如何访问我的应用程序的派生数据文件夹本身?

[英]How to access my app’s derived data folder itself?

I'm in the middle of moving my iOS app's Firebase dependency from CocoaPods to Swift Package Manager.我正在将我的 iOS 应用程序的 Firebase 依赖项从 CocoaPods 转移到 Swift Package Manager。

Firebase's Crashlytics requires a script to be executed while the app is building (using the Run Script build phase). Firebase 的 Crashlytics 需要在构建应用程序时执行脚本(使用运行脚本构建阶段)。 Back in the CocoaPods days, I used to call the script the way documented by Google : "${PODS_ROOT}/FirebaseCrashlytics/run" .回到 CocoaPods 时代,我曾经按照Google 记录的方式调用脚本: "${PODS_ROOT}/FirebaseCrashlytics/run"

After I've switched to SPM, Firebase files are no longer in ${PODS_ROOT} , and there's no such variable available at all.在我切换到 SPM 后,Firebase 文件不再位于${PODS_ROOT} ,并且根本没有这样的变量可用。 I know the file I need is now located in the DerivedData folder, specifically it's at ~/Library/Developer/Xcode/DerivedData/MyApp-abcde/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run .我知道我需要的文件现在位于DerivedData文件夹中,特别是它位于~/Library/Developer/Xcode/DerivedData/MyApp-abcde/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run The problem is, the MyApp-abcde folder is not easily referenced.问题是, MyApp-abcde文件夹不容易被引用。

A Medium post I found suggested using the ${BUILD_DIR} build variable (in regard to the example above, it would resolve to <…>/MyApp-abcde/Build/Products ), and calling the dirname command to move up the directory hierarchy. 我发现的一篇中等文章建议使用${BUILD_DIR}构建变量(关于上面的示例,它将解析为<…>/MyApp-abcde/Build/Products ),并调用dirname命令以向上移动目录层次结构.

This hack worked only for running the app.此 hack 仅适用于运行该应用程序。 When I tried to archive it, ${BUILD_DIR} resolved to another path, namely <…>/MyApp-abcde/Build/Intermediates.noindex/ArchiveIntermediates/MyApp/BuildProductsPath .当我尝试归档它时, ${BUILD_DIR}解析到另一个路径,即<…>/MyApp-abcde/Build/Intermediates.noindex/ArchiveIntermediates/MyApp/BuildProductsPath I tried a few more build variables, such as ${SYMROOT} , in place of ${BUILD_DIR} , but they also produce different paths depending on the operation.我尝试了更多构建变量,例如${SYMROOT}代替${BUILD_DIR} ,但它们也会根据操作产生不同的路径。

So, here comes the question…那么,问题来了……

Is there a way to reliably reference my app's derived data folder's root (ie ~/Library/Developer/Xcode/DerivedData/MyApp-abcde ) using Xcode's build variables?有没有办法使用 Xcode 的构建变量可靠地引用我的应用程序的派生数据文件夹的根目录(即~/Library/Developer/Xcode/DerivedData/MyApp-abcde

You were close.你很接近。 This should work:这应该有效:

${BUILD_DIR%Build/*}SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run

I'm reworking my answer as I realized I haven't answered your question..我正在修改我的答案,因为我意识到我没有回答你的问题..

I have a run script that copies the build targets into a new folder.我有一个运行脚本,可以将构建目标复制到一个新文件夹中。 This works for both Build and Archive.这适用于构建和存档。 Note that you need the -L on copy to follow the symlink请注意,您需要在复制时使用 -L 来跟随符号链接

# Copy the built framework into a sibling to the project folder
if [[ "$CONFIGURATION" == "Debug" ]]; then
  mkdir -p "$PROJECT_DIR/../../iwins-ios-sdk/debug"
  rm -rf "$PROJECT_DIR/../../iwins-ios-sdk/debug/IWiNS_SDK.framework"
  cp -LR "$BUILD_DIR/Debug-iphoneos/IWiNS_SDK.framework" "$PROJECT_DIR/../../iwins-ios-sdk/debug"
else
  mkdir -p "$PROJECT_DIR/../../iwins-ios-sdk/release"
  rm -rf "$PROJECT_DIR/../../iwins-ios-sdk/release/IWiNS_SDK.framework"
  cp -LR "$BUILD_DIR/Release-iphoneos/IWiNS_SDK.framework" "$PROJECT_DIR/../../iwins-ios-sdk/release"
fi

Also, you can find all of the build envvars here: https://gist.github.com/gdavis/6670468此外,您可以在此处找到所有构建环境变量: https ://gist.github.com/gdavis/6670468

So, it appears that $BUILD_DIR is different for build/release, but by copying the files to a known location at build time, you'll know where to find them.因此,看起来 $BUILD_DIR 对于构建/发布是不同的,但是通过在构建时将文件复制到已知位置,您将知道在哪里可以找到它们。

Crashlytics run script Crashlytics 运行脚本

To build&run from Xcode:从 Xcode 构建和运行:

${BUILD_DIR%Build/*}SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run

To archive for distribution from Xcode Server at CI/CD:要从 Xcode Server 的 CI/CD 存档以进行分发:

${XCS_DERIVED_DATA_DIR%/*}/Dependencies/checkouts/firebase-ios-sdk/Crashlytics/run

To work for both at the same time:同时为两者工作:

if [[ "${XCS_DERIVED_DATA_DIR}" == "" ]]; then
  ${BUILD_DIR%Build/*}SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run
else
  ${XCS_DERIVED_DATA_DIR%/*}/Dependencies/checkouts/firebase-ios-sdk/Crashlytics/run
fi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何确保我的应用程序的后端 API 只能由应用程序本身访问? - How to ensure that my app's backend API is only accessible by the app itself? 派生数据中生成的未知文件夹 - Unknown folder generated in Derived data 您可以在iPhone上我自己的应用程序文件夹中更新数据文件的文件访问权限吗 - Can you update file access permission for data file within my own app folder on iPhone 如何为我的应用访问iPhone的铃声? - How do I access iPhone's ringtones for my app? 将访问应用程序的Documents文件夹的权限授予iOS 11中的另一个应用程序 - Give access to app's Documents folder to another app in iOS 11 为什么应用程序无法访问另一个应用程序的文档文件夹? - Why can't app access another app's document folder? 我的应用可以访问iOS中的Notes(Apple app)文件夹吗? - Can my app access the Notes (Apple app) folder in iOS? 如何访问我们的iOS应用程序的用户数据? - How can I access a user's data for our iOS app? iOS 应用程序:如何访问其他用户保存在 cognito identity id 文件夹下的 S3 对象 - iOS app: How to access S3 object saved under cognito identity id folder by another user Files App和我App的文档文件夹之间的交互 - Interaction between Files App and my App's document folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM