NinaLabo

個人ゲーム開発者の技術メモ

【Unity】GoogleMobileAds で CocosPods エラー

エラー内容

Unity で広告配信を実装しようと GoogleMobileAds をインストールしたところ、Unityで再生した時にエラーが出るようになりました。プラットフォームが Android の時は問題なかったのですが、iOSにした途端エラーが出るようになりました。広告表示の実装自体はまだだったのに、インストールしただけでエラーになるとは..

 

*実行するとダイアログが2個立ち上がります。

f:id:ninagreen:20181020201536p:plainf:id:ninagreen:20181020202244p:plain

 

*Consoleにもエラーが表示されます

Failed to install CocoaPods for the current user.

 

It will not be possible to install Cocoapods in the generated Xcode project which will result in link errors when building your application.

 

For more information see:

  https://guides.cocoapods.org/using/getting-started.html

 

 

'gem install activesupport -v 4.2.6 --user-install' failed with code (2):

 

 

ERROR:  Could not find a valid gem 'activesupport' (= 4.2.6), here is why:

          Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: tlsv1 alert protocol version (https://rubygems.org/specs.4.8.gz)

 

 

UnityEngine.Debug:LogError(Object)

Google.Logger:Log(String, LogLevel)

Google.IOSResolver:Log(String, Boolean, LogLevel)

Google.IOSResolver:LogToDialog(String, Boolean, LogLevel)

Google.<InstallCocoapods>c__AnonStorey0:<>m__1(Int32, CommandItem[], Result, CommandLineDialog)

Google.<RunCommandsAsync>c__AnonStorey2:<>m__2(Result)

GooglePlayServices.ProgressReporter:SignalComplete()

GooglePlayServices.ProgressReporter:CommandLineToolCompletion(Result)

GooglePlayServices.<RunAsync>c__AnonStorey2:<>m__3()

Google.RunOnMainThread:ExecuteNext()

Google.RunOnMainThread:<ExecuteAll>m__6()

Google.RunOnMainThread:RunAction(Action)

Google.RunOnMainThread:ExecuteAll()

UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

 

解決方法

本当に色々試したのですが、最終的には Mac の OS が El Captain だったのを High Sierra にアップデートしました。Xcode も 7.3.1 だったので、Xcode 10.0 にアップデートしました。ついでに、Unity も 2017.3 から 2018.2 にアップデートしました。

 

 

試したこと

1. ターミナルから実行

エラーで表示されているインストールコマンドをターミナルから実行してみました

$ gem install activesupport -v 4.2.6 --user-install

ERROR:  Could not find a valid gem 'activesupport' (= 4.2.6), here is why:

          Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: tlsv1 alert protocol version (https://rubygems.org/specs.4.8.gz)

 確かにダイアログで表示されるのと同じエラーが出ました。

 

2. エラー内容の read server hello A を調べる

エラー内容を調べていたら下記のサイトを見つけました。

Bundler: How to troubleshoot RubyGems and Bundler TLS/SSL Issues

 

「Why am I seeing read server hello A?」というタイトルを見て、同じ現象かなと思いました。記事内ではまず診断用のコマンド実行するように書いてありました。

ruby -ropen-uri -e 'eval open("https://git.io/vQhWq").read'

結果は、このように表示されました。

Here's your Ruby and OpenSSL environment:

 

Ruby:           2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15]

RubyGems:       2.0.14

Compiled with:  OpenSSL 0.9.8zc 19 Mar 2015

Loaded version: OpenSSL 0.9.8zg 14 July 2015

SSL_CERT_FILE:  /System/Library/OpenSSL/cert.pem

SSL_CERT_DIR:   /System/Library/OpenSSL/certs

 

With that out of the way, let's see if you can connect to rubygems.org...

 

Bundler connection to rubygems.org:       failed    (uninitialized constant Bundler)

RubyGems connection to rubygems.org:      failed    (SSL/TLS protocol version mismatch)

Ruby net/http connection to rubygems.org: failed 

 

Unfortunately, this Ruby can't connect to rubygems.org. 😡

Your Ruby can't connect to rubygems.org because your version of OpenSSL is too old. You'll need to upgrade your OpenSSL install and/or recompile Ruby to use a newer OpenSSL.

よくわからなかったのですが、❌ がついているなら駄目なんだろうと思いました。

 

3. Rubyの更新を試みる

エラーメッセージには、OpenSSLが古いとあったのですが、Rubyが古いんじゃないかと勘違いしました。 また、「Updating RubyGems: You might be able to upgrade RubyGems using the self-update command:」とあったので、Rubyをアップデートすることにしました。

 

下記を実行したのですが、もう最新だよと言われて??となりました。この時点でやめておけばよかったのにこれからどんどん深みにハマります。

$ gem update --system

Latest version currently installed. Aborting.

 

4. 権限がないエラーとの戦い 

色々調べていると、 source オプションを付けて実行している記事を見かけたので試してみました。

$ gem update --system --source http://rubygems.org/

Updating rubygems-update

ERROR:  While executing gem ... (Gem::FilePermissionError)

    You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

先ほどとは異なり、権限がないと言われます。

$ sudo gem update --system --source http://rubygems.org/

 sudo を付けて実行してみました。

WARNING: Improper use of the sudo command could lead to data loss

or the deletion of important system files. Please double-check your

typing when using sudo. Type "man sudo" for more information.

 

To proceed, enter your password, or type Ctrl-C to abort.

 

Password:

Updating rubygems-update

Fetching: rubygems-update-2.7.7.gem (100%)

Successfully installed rubygems-update-2.7.7

Parsing documentation for rubygems-update-2.7.7

Installing ri documentation for rubygems-update-2.7.7

Installing darkfish documentation for rubygems-update-2.7.7

Installing RubyGems 2.7.7

YAML safe loading is not available. Please upgrade psych to a version that supports safe loading (>= 2.0).

ERROR:  While executing gem ... (Errno::EPERM)

    Operation not permitted - /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/gem

警告は出つつも途中までは実行されます。でも、最後にやっぱり権限がない(Operation not permitted) と言われました。

 

5. ローカルで ruby をセットアップしてみる

もうよくわからなくなってしまい... Rubyをローカルにダウンロードしてインストールすればいいんじゃないかと思ってしまいました。

下記のページから rubygems-2.7.7.zip をダウンロードしてzipを解凍します。

Download RubyGems | RubyGems.org | your community gem host

展開したフォルダへ移動し、以下のコマンドを実行しました。

YAML safe loading is not available. Please upgrade psych to a version that supports safe loading (>= 2.0).

ERROR:  While executing gem ... (Errno::EPERM)

    Operation not permitted - /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/gem

結果は同じでした...

6. brew をインストール

エラーの内容を調べていくと、rbenv か RVM を使えば解決できるよ、と書いてありました。

ruby - Installing gem or updating RubyGems fails with permissions error - Stack Overflow

 

rbenv をインストールしようと思ったのですが、rbenv は Homebrew でインストールするため、まずは Homebrew をインストールする必要があるらしいとわかり、以下のコマンドでインストールしました。

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew update

 また、

brew doctor

で、問題がないかをチェックできるらしいので実行してみました。

Warning: You are using macOS 10.11.

We (and Apple) do not provide support for this old version.

You will encounter build failures and other breakages.

Please create pull-requests instead of asking for help on Homebrew's

GitHub, Discourse, Twitter or IRC. As you are running this old version,

you are responsible for resolving any issues you experience.

 

Warning: An outdated version (2.10.1) of Git was detected in your PATH.

Git 2.14.3 or newer is required for Homebrew.

Please upgrade:

  brew install git

 

Warning: Your Xcode (7.3.1) is outdated.

Please update to Xcode 8.2.1 (or delete it).

Xcode can be updated from the App Store.

 mac OS が古いこと、git が古いこと、Xcode が古いことで、warning が出ました。ただ、この時はとりあえず無視して作業を続けました。

7. rbenv をインストール

ようやく rbenv を インストールします。

$ brew install rbenv

 

無事成功したようなので、使えるバージョンを確認します。

$ rbenv install -list

 

2.5.3 が最新のようだったので、インストールしてデフォルト設定にしました。

$ rbenv install 2.5.3

$ rbenv global 2.5.3

 

パスを通します。~/.bashrc ファイルに以下を記述します。

export PATH=$HOME/.rbenv/bin:$PATH

eval "$(rbenv init -)"

以下のコマンドで反映させます。

$ source ~/.bashrc

7. rbenv で activesupport をインストール

最初にエラーになったコマンドもう1度、rbenv経由で実行します。

$ rbenv exec gem install activesupport -v 4.2.6 --user-install

無事インストールできたように見えました。成功したように見えました。

(あまりにホッとしてログを記録し忘れました)

 

8. Unity で再生

Unity に戻り、アプリを再生して実行してみます。当然問題ないと思ってましたが... なんと結果は変わらず、同じエラーが出ました。

開発環境を更新すると使えないソフトが出てきてしまう可能性もあるのでためらっていましたが、もう打つ手もなく、潔く環境を更新することにしました...