ios 通过 CocoaPods 使用 Google Analytics 时,“链接器命令失败,退出代码为 1”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35290063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'Linker command failed with exit code 1' when using Google Analytics via CocoaPods
提问by SimonTheEngineer
I'm trying to add Google Analytics to an iOS app written in Swift. I've followed the guide that adds the frameworks via CocoaPods and added a bridging header but I'm still getting:
我正在尝试将 Google Analytics 添加到用 Swift 编写的 iOS 应用程序中。我遵循了通过 CocoaPods 添加框架的指南并添加了桥接头,但我仍然得到:
Linker command failed with exit code 1
My podfile does have use_frameworks! so I'm wondering if that has anything to do with it... there is no additional information on the Analytics site from what I can see.
我的 podfile 确实有 use_frameworks!所以我想知道这是否与它有关...从我所看到的,分析网站上没有其他信息。
EDIT: I've noticed that after viewing the full error message the following is displayed:
编辑:我注意到在查看完整的错误消息后会显示以下内容:
ld: '/Users/simon/Programming/VenueNow/Pods/GoogleUtilities/Libraries/libGTM_NSData+zlib.a(GTMNSData+zlib.o)' does not contain bitcode.
You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64
And searching for that issue brings up that Google updated to support bit code but hadn't updated the cocoa pods framework at that time.
搜索该问题后发现 Google 已更新为支持位代码,但当时尚未更新可可豆荚框架。
采纳答案by starlabs
I had this same issue. Fortunately you can use Google Analytics with BitCode enabled, but it's a bit confusing due to how Google had set up their CocoaPods support.
我有同样的问题。幸运的是,您可以在启用 BitCode 的情况下使用 Google Analytics,但由于 Google 设置其 CocoaPods 支持的方式,这有点令人困惑。
There's actually 2 CocoaPods you can use:
您实际上可以使用 2 个 CocoaPods:
- 'Google/Analytics'
- 'GoogleAnalytics'
- '谷歌分析'
- '谷歌分析'
The first one is the "latest" but it's tied to the greater Google pods so it does not support Bitcode. The second one is for Analytics only and does support BitCode. However because the latter does not include extra Google pods some of the instructions on how to set it up are incorrect.
第一个是“最新的”,但它与更大的 Google pod 相关联,因此它不支持 Bitcode。第二个仅用于分析并且支持 BitCode。但是,由于后者不包含额外的 Google pod,一些关于如何设置它的说明是不正确的。
You have to use the v2 method of setting up analytics:
您必须使用 v2 方法来设置分析:
// Inside AppDelegate:
// Optional: automatically send uncaught exceptions to Google Analytics.
GAI.sharedInstance().trackUncaughtExceptions = true
// Optional: set Google Analytics dispatch interval to e.g. 20 seconds.
GAI.sharedInstance().dispatchInterval = 20
// Create tracker instance.
let tracker = GAI.sharedInstance().trackerWithTrackingId("XX-XXXXXXXX-Y")
The rest of the Google analytics api you can use the v3 documentation (you don't need to use v2).
其余的 Google 分析 api 您可以使用 v3 文档(您不需要使用 v2)。
The 'Google/Analytics' cocoapod as of this writing still does not support BitCode. See here
在撰写本文时,'Google/Analytics' cocoapod 仍然不支持 BitCode。看这里
回答by dokun1
Go to your build settings and switch the target's settings to ENABLE_BITCODE = YES
for now.
转到您的构建设置并将目标的设置切换到ENABLE_BITCODE = YES
现在。
回答by lucius degeer
Had this issue, but it wasn't related to the bitcode setting. I had somehow ended up with duplicate framework files in the Frameworks folder of my XCode project. I deleted all frameworks files that were red (and duplicates). This solved the "Apple Mach O, Linker Command failed with exit code 1" error.
有这个问题,但它与位码设置无关。我不知何故在我的 XCode 项目的 Frameworks 文件夹中得到了重复的框架文件。我删除了所有红色(和重复)的框架文件。这解决了“Apple Mach O,链接器命令失败,退出代码 1”错误。
回答by Aitor Pagán
This worked for me:
这对我有用:
you have to remove libPods.a library from Linked Frameworks and Libraries section of target.
您必须从目标的链接框架和库部分中删除 libPods.a 库。
回答by Atlas_Gondal
Make sure you open the .xcworkspacefile not the project file from xCode Project menu when working with pods. That should solve the issue with linking.
确保在使用pod 时打开.xcworkspace文件而不是来自 xCode Project 菜单的项目文件。这应该可以解决链接问题。
回答by dnaatwork.com
Close Xcode, rename the folder. Then make a new folder with the previous name. Run the project, stop the project. Delete the new folder, rename old folder and re-run.
关闭 Xcode,重命名文件夹。然后使用以前的名称创建一个新文件夹。运行项目,停止项目。删除新文件夹,重命名旧文件夹并重新运行。
My iPad Pro simulator is affected with this issue. Its something that makes me upset, so much hard work... hopefully Google works through bugs for the next SDK.
我的 iPad Pro 模拟器受此问题影响。它让我心烦意乱,如此辛苦的工作......希望谷歌能够解决下一个 SDK 的错误。
回答by Ahd Radwan
Some times appeared if you declare a constant in the header file without static notation. like this
如果在没有静态符号的情况下在头文件中声明一个常量,有时会出现。像这样
const int k = 10;
it should be:
它应该是:
static const int k = 10;
回答by Oubaida AlQuraan
Try to remove any trace of cocoapods pods using pod deintegrate
then
Run pod install
尝试使用pod deintegrate
then Run删除任何可可豆荚的痕迹pod install
回答by Jasveer
Build Settings > Enable Bitcode > No
构建设置 > 启用位码 > 否
回答by John
I had same the problem with xcode 7.3. It is because, some of my .h and .m files were added twice.
我在 xcode 7.3 上遇到了同样的问题。这是因为,我的一些 .h 和 .m 文件被添加了两次。