11
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Firebase Performance Monitoringをデバッグ以外で導入する

Posted at

概要

Firebase Performance Monitoring、存在は知っていたのですが、測っていないのですがコンパイル時に処理を差し込むので、ビルドに時間がかかりそうなので、あまり入れたくないというのがありました。
具体的には app:transformClassesWithFirebasePerformancePluginForDebug という感じのタスクになってここで織り込まれるようです。
現在はFirebase Performance MonitoringにBuildTypeで無効にする機能があるので、デバッグ時では導入せずに、リリースでだけ入れることができます。

具体的には以下のページで書かれているとおりです。
https://firebase.google.com/docs/perf-mon/get-started-android?hl=en
https://firebase.google.com/docs/perf-mon/disable-sdk?hl=ja&platform=android

Firebase Performance Monitoringのデバッグ

デバッグのビルドタイプ用のsrc/debugフォルダを作って、AndroidManifest.xmlを作って以下のように入れておきます。
これによって、デバッグ時にログを出すことができ、起動時間やセッションの名前などが表示されるようになります。

    <meta-data
      android:name="firebase_performance_logcat_enabled"
      android:value="true" />

debug版でビルドが遅い問題を解決する

下記でビルド時にコードが埋め込まれなくなるため、ビルドが遅い問題を解決します。しかし、ネットワークのログと@AddTraceを使ったログ以外のログ、例えば、起動時間などのログが送られてしまいます。

app/build.gradle

  buildTypes {
    debug {
      FirebasePerformance {
        // Set this flag to 'false' to disable @AddTrace annotation processing and
        // automatic HTTP/S network request monitoring
        // for a specific build variant at compile time.
        instrumentationEnabled false
      }
    }
  }

debug版でデータが送られてしまうのを防ぐ

デバッグ時に同じパッケージ名でやっていると、LeakCanaryなどでデバッグ版アプリのパフォーマンスがかなり悪くなっている場合がるので、そもそもログを送らないということも可能です。
(課金のテストのためにパッケージ名をリリース版と揃えられるようにしている場合などに同じパッケージでデータが汚染されてしまうことを防ぐことが可能です。)

デバッグのビルドタイプ用のsrc/debugフォルダを作って、AndroidManifest.xmlを作って以下のように入れておきます。
これによりデバッグでは完全にFirebase Performance Monitoringのログが送られなくなります。

  <application>
    <meta-data
      android:name="firebase_performance_collection_enabled"
      android:value="false" />
  </application>

終わりに

このようなかゆいところに手が届くオプションが追加されており、Firebase Performance Monitoring自体は結構昔からあるもので、結構成熟してきている感じがあります。

11
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?