LoginSignup
15
15

More than 5 years have passed since last update.

Stethoをrelease時に使用しないようにする方法

Posted at

注意

執筆時の最新バージョンは1.3.1です。

Stetho

StethoはFacebook製のデバッグ用ライブラリ。
使ってみるとかなり便利なのだが、Leakcanaryと違って、リリース用のダミー実装がない。
BuildConfig.DEBUGで判断してやるのもいいが、JARのサイズも500KBあるので、無視できない。

というわけで、リリース用の実装方法を書いてみる。

リリース実装方法

簡単に言うと、Leakcanary同様にreleaseソースにダミーのStethoを実装してやればよい。

すでにStethoが実装されているアプリを前提に書く。

  1. build.gradledependenciescompileからdebugCompileに変更する。

    app/build.gradle
    dependencies {
        debugCompile "com.facebook.stetho:stetho:${versions.stetho}"
        debugCompile "com.facebook.stetho:stetho-okhttp3:${versions.stetho}"
        debugCompile "com.facebook.stetho:stetho-js-rhino:${versions.stetho}"
    }
    
  2. releaseソースセットにStethoのダミークラス群を作る。

    app/src/release/kotlin/com/facebook/stetho/Stetho.kt
    class Stetho {
        companion object {
            @JvmStatic fun initializeWithDefaults(context: Context) = Unit
        }
    }
    

    StethoInterceptorinitializeWithDefaults以外のメソッドを使用している場合は、適宜実装する。

    app/src/release/kotlin/com/facebook/stetho/okhttp3/StethoInterceptor.kt
    class StethoInterceptor : Interceptor {
        override fun intercept(chain: Interceptor.Chain): Response {
            return chain.proceed(chain.request())
        }
    }
    

上記でリリース時はStethoを使わない実装になる。

15
15
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
15
15