all green

プログラム、アプリ作成、Web等備忘録が中心です

UnityでGoogle Play ServicesのAPIを個別に追加する(LogPush編)

Google Play ServicesのAPIのうちLogPushに必要なものだけ追加する。
※PlayServicesResolverを使用


環境
Unity 5.3.4f1
LogPush-Unity-SDK_1.1.1
play-services-resolver-1.1.1

無料でプッシュ通知が行える便利なLogPush

push.logbk.net


手順通りにパッケージをインポートすると
google-play-services_libが入っているため
65K問題が発生してしまうケースがある。

個別にAPIを追加して回避できないかと思ったら
Googleが用意してくれているPlayServicesResolverという便利なものがあるらしい。


こちらの記事を参考に試してみた。
qiita.com

手順

1.Unityでプロジェクトを作成
2.LogPush.unitypackageをインポートする
3.LogPushの設定等を行いapkでプッシュ通知が受信できることを確認する
4.PlayServicesResolverをダウンロードする

github.com

5.play-services-resolver-1.1.1.unitypackageをインポート
6.Google Cloud Messaging 追加用のソースを作成

SampleDependenciesを参考に以下クラスを作成
Assets/Editor/フォルダ以下に設置

using Google.JarResolver;
using UnityEditor;

[InitializeOnLoad]
public static class LogPushDependencies
{

	private static readonly string PluginName = "your_plugin_name";

    /// <summary>
    /// Initializes static members of the <see cref="SampleDependencies"/> class.
    /// </summary>
    static LogPushDependencies()
    {

        PlayServicesSupport svcSupport = PlayServicesSupport.CreateInstance(
                                             "LogPush",
                                             EditorPrefs.GetString("AndroidSdkRoot"),
                                             "ProjectSettings");

        // add your dependencies here
		svcSupport.DependOn("com.google.android.gms", "play-services-gcm", "8.4+");
    }
}
7.追加を実行する

メニューから[Assets] - [Google Play Services] - [Resolve Client Jars]を選択

f:id:uwanosora22:20160518154254j:plain

追加後の構成
f:id:uwanosora22:20160518154324j:plain

8.google-play-services_libを削除する

google-play-services_libとかぶっているandroid-support-v4.jarを削除する


Plugins/Android/google-play-services_lib/
Plugins/Android/android-support-v4.jar

9.ビルドを行いLogPushでプッシュ通知が無事届くことを確認する