注意
執筆時の最新バージョンは1.3.1です。
Stetho
StethoはFacebook製のデバッグ用ライブラリ。
使ってみるとかなり便利なのだが、Leakcanaryと違って、リリース用のダミー実装がない。
BuildConfig.DEBUG
で判断してやるのもいいが、JARのサイズも500KBあるので、無視できない。
というわけで、リリース用の実装方法を書いてみる。
リリース実装方法
簡単に言うと、Leakcanary同様にrelease
ソースにダミーのStethoを実装してやればよい。
すでにStethoが実装されているアプリを前提に書く。
-
build.gradle
のdependencies
をcompile
からdebugCompile
に変更する。app/build.gradledependencies { debugCompile "com.facebook.stetho:stetho:${versions.stetho}" debugCompile "com.facebook.stetho:stetho-okhttp3:${versions.stetho}" debugCompile "com.facebook.stetho:stetho-js-rhino:${versions.stetho}" }
-
release
ソースセットにStethoのダミークラス群を作る。app/src/release/kotlin/com/facebook/stetho/Stetho.ktclass Stetho { companion object { @JvmStatic fun initializeWithDefaults(context: Context) = Unit } }
StethoInterceptor
やinitializeWithDefaults
以外のメソッドを使用している場合は、適宜実装する。app/src/release/kotlin/com/facebook/stetho/okhttp3/StethoInterceptor.ktclass StethoInterceptor : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { return chain.proceed(chain.request()) } }
上記でリリース時はStethoを使わない実装になる。