「Unity/fabricのcrashlytics」の版間の差分
提供: 初心者エンジニアの簡易メモ
| 行71: | 行71: | ||
</pre> | </pre> | ||
| − | firebaseのlogに載った | + | ===firebaseのlogに載った=== |
| + | androidでは掲載できた。iosではアプリが途中で止まり、ログは出なかった・・。 | ||
<pre> | <pre> | ||
Non-fatal Exception: java.lang.Exception | Non-fatal Exception: java.lang.Exception | ||
2019年6月10日 (月) 14:29時点における最新版
目次
firebase直のcrashlytics
- firebaseからcrashlyticsを選択
- 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インストール
- fabricでアカウントをつくる
- https://www.fabric.io/downloads/unity からFabric.unitypackageファイルをDL
- unityのメインメニューからAssets/importpackage/CustomPackageを選択し
- DLしてきたFabric.unitypackageを選択しimportボタンを押す
- unityのメインメニューからFabric/PrepareFabricからFabricへログインする
- crashlyticsを選択しinstallボタンを押しimportボタンを押す
- AndroidManifest.xml編集を追加する場合はApplyボタンを押す
- sceneにcrashlyticsオブジェクトをドラッグする
fabricとfirebaseを連携
- fabricにログイン
- fabricの左側にあるfirebaseメニューをクリック
- そこからfirebaseにログインし連携する
- 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)
