在iOS应用中安装Google Analytics时出现错误。

3

我试图将Google Analytics集成到我的项目中,但惊讶地发现现在需要使用CocoaPods安装Google Analytics。

我按照此处的文档进行操作:

https://developers.google.com/analytics/devguides/collection/ios/v3/?hl=en

我在终端上调用了pod init命令,然后编辑了我的podfile文件为:

# Uncomment this line to define a global platform for your project
# platform :ios, '6.0'

target 'Unity-iPhone' do
pod 'Google/Analytics', '~> 1.0.0'
end

target 'Unity-iPhone Tests' do

end

当我调用pod install时,终端显示以下错误:
更新本地规格存储库,分析依赖项[!]无法找到Google/Analytics(〜> 1.0.0)的规格[!]CocoaPods无法更新master repo。如果这是一个意外问题并且仍然存在,您可以运行pod repo update --verbose进行检查。
它还没有生成.xcworkspace文件。
我该如何解决这个问题?
编辑:
我尝试了Steffen的答案来重新设置主repo,现在我得到了这个错误。
分析依赖项[!]无法满足以下要求: - Google/Analytics(〜> 1.0.0)由需要
尽管我的podfile仍包含“pod 'Google/Analytics', '~> 1.0.0'”

你使用的是哪个版本的CocoaPods?你的项目部署目标是什么? - Steffen D. Sommer
部署目标为6.0,cocoapod版本为cocoapods-0.38.2。 - Seyong Cho
你能否尝试将 platform :ios, '6.0' 放在你的 Podfile 顶部,看看是否会改变错误信息? - Steffen D. Sommer
嗨,Steffen,看起来它没有改变错误消息。 - Seyong Cho
我已经没有更多的想法了,但是我认为如果你只想让它运行起来,只需简单地指定 pod 'Google/Analytics', '1.0.0' 就可以了。 - Steffen D. Sommer
3个回答

9

我在 OS X El Capitan Version 10.11.5 上遇到了这个问题。

  1. Open terminal command prompt
  2. Path to your XCode project folder

    $ cd /path/to/xcode/myProject/
    
  3. Create the Podfile using command

    $ pod init
    
  4. Add the line pod 'Google/Analytics' to the generated Podfile
     # Uncomment this line to define a global platform for your project
     # platform :ios, '8.0'
     # Uncomment this line if you're using Swift
     # use_frameworks!

     target 'myProject' do 
     pod 'Google/Analytics'
     end
  1. Try to install the pod which fails

    $ pod install
    -bash: pod: command not found
    
  2. Try to install cocoapods which also fails

    $ sudo gem install cocoapods 
    ERROR:  Error installing cocoapods: activesupport requires Ruby version >= 2.2.2.
    
  3. You need to install activesupport which then lets you install cocoapods okay but then the pod install fails with a new bug

    $ sudo gem install activesupport -v 4.2.6
    $ sudo gem install cocoapods
    $ pod install
    [!] Unable to find a specification for 'Google/Analytics'
    
  4. Perform these last steps and the pod install will finally succeed

    $ pod repo remove master
    $ pod setup
    $ pod install
    

NB 一些命令行操作需要很长时间才能完成,终端不会给出任何提示,看起来好像出现了故障,但实际上是在静默地工作,因此需要耐心等待。

很遗憾,在2016年我们仍然需要使用命令行。


1
将项目部署目标设置为7.0解决了这个问题。

1

听起来你的主代码库可能出现了一些问题。我建议尝试以下步骤:

pod repo remove master
pod setup

谢谢您的帮助。我更新了问题,因为在尝试后这次似乎出现了不同的错误。 - Seyong Cho

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接