facebook twitter hatena line email

Unity/fabricのcrashlytics

提供: 初心者エンジニアの簡易メモ
2019年6月10日 (月) 14:29時点におけるAdmin (トーク | 投稿記録)による版

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索

firebase直のcrashlytics

  1. firebaseからcrashlyticsを選択
  2. unityのfirebaseをDLし、FirebaseCrashlytics.unitypackageをAssets/Import〜からImportする。

以下を追加しcrashlyticsを初期化する。

        // Initialize Firebase
        Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
            var dependencyStatus = task.Result;
            if (dependencyStatus == Firebase.DependencyStatus.Available)
            {
                // Create and hold a reference to your FirebaseApp,
                // where app is a Firebase.FirebaseApp property of your application class.
                // Crashlytics will use the DefaultInstance, as well;
                // this ensures that Crashlytics is initialized.
                Firebase.FirebaseApp app = Firebase.FirebaseApp.DefaultInstance;

                // WARNING: Do not call Crashlytics APIs from asynchronous tasks;
                // they are not currently supported.

                // Set a flag here for indicating that your project is ready to use Firebase.
            }
            else
            {
                UnityEngine.Debug.LogError(System.String.Format(
                  "Could not resolve all Firebase dependencies: {0}", dependencyStatus));
                // Firebase Unity SDK is not safe to use here.
            }
        });

強制的にクラッシュ

参考:https://firebase.google.com/docs/crashlytics/force-a-crash?authuser=0&platform=unity

public class TitleScript : MonoBehaviour {

    int updatesBeforeException;

    // Use this for initialization
    void Start () {
      updatesBeforeException = 0;
    }

    // Update is called once per frame
    void Update()
    {
        // Call the exception-throwing method here so that it's run
        // every frame update
        throwExceptionEvery60Updates();
    }

    // A method that tests your Crashlytics implementation by throwing an
    // exception every 60 frame updates. You should see non-fatal errors in the
    // Firebase console a few minutes after running your app with this method.
    void throwExceptionEvery60Updates()
    {
        if (updatesBeforeException > 0)
        {
            updatesBeforeException--;
        }
        else
        {
            // Set the counter to 60 updates
            updatesBeforeException = 60;

            // Throw an exception to test your Crashlytics implementation
            throw new System.Exception("test exception please ignore");
        }
    }
}

firebaseのlogに載った

androidでは掲載できた。iosではアプリが途中で止まり、ログは出なかった・・。

Non-fatal Exception: java.lang.Exception
Exception : test exception please ignore
    TitleScript.throwExceptionEvery60Updates (TitleScript)
    TitleScript.Update (TitleScript)

fabric経由のcrashlytics

こちらは旧版で非推奨です。

fabricのcrashlyticsインストール

  1. fabricでアカウントをつくる
  2. https://www.fabric.io/downloads/unity からFabric.unitypackageファイルをDL
  3. unityのメインメニューからAssets/importpackage/CustomPackageを選択し
  4. DLしてきたFabric.unitypackageを選択しimportボタンを押す
  5. unityのメインメニューからFabric/PrepareFabricからFabricへログインする
  6. crashlyticsを選択しinstallボタンを押しimportボタンを押す
  7. AndroidManifest.xml編集を追加する場合はApplyボタンを押す
  8. sceneにcrashlyticsオブジェクトをドラッグする

fabricとfirebaseを連携

  1. fabricにログイン
  2. fabricの左側にあるfirebaseメニューをクリック
  3. そこからfirebaseにログインし連携する
  4. firebase側からもデータ参照できることを確認

androidのANRのログ

ANRのログは端末側(/data/ant/traces.txt)には残ってるが、fabricでは検出できなかった。

強制的にcrashさせる

Fabric.Crashlytics.Crashlytics.Log("onCrash");
Fabric.Crashlytics.Crashlytics.Crash();

上記crashでcrashlyticsに上がるcrashログ

 Caused by java.lang.RuntimeException
 Forced runtime exception
 	
 io.fabric.unity.crashlytics.android.CrashlyticsAndroidWrapper$1.run (CrashlyticsAndroidWrapper.java:12)
 	
 java.lang.Thread.run (Thread.java:818)