Add Chucker for debug

This commit is contained in:
Koitharu
2020-03-19 13:16:33 +02:00
parent 127978d3d7
commit 032d671c38
7 changed files with 31 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
<component name="ProjectDictionaryState"> <component name="ProjectDictionaryState">
<dictionary name="admin"> <dictionary name="admin">
<words> <words>
<w>chucker</w>
<w>desu</w> <w>desu</w>
<w>koin</w> <w>koin</w>
<w>kotatsu</w> <w>kotatsu</w>

View File

@@ -21,5 +21,10 @@
<option name="name" value="Google" /> <option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" /> <option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository> </remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://jitpack.io" />
</remote-repository>
</component> </component>
</project> </project>

View File

@@ -90,7 +90,9 @@ dependencies {
implementation 'com.tomclaw.cache:cache:1.0' implementation 'com.tomclaw.cache:cache:1.0'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.2' debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.2'
debugImplementation 'com.github.ChuckerTeam.Chucker:library:3.1.2'
releaseImplementation 'com.github.ChuckerTeam.Chucker:library-no-op:3.1.2'
testImplementation 'junit:junit:4.13' testImplementation 'junit:junit:4.13'
testImplementation 'org.json:json:20180813' testImplementation 'org.json:json:20190722'
} }

1
app/libs/.gitkeep Normal file
View File

@@ -0,0 +1 @@

Binary file not shown.

View File

@@ -6,9 +6,9 @@ import androidx.room.Room
import coil.Coil import coil.Coil
import coil.ImageLoader import coil.ImageLoader
import coil.util.CoilUtils import coil.util.CoilUtils
import com.itkacher.okhttpprofiler.OkHttpProfilerInterceptor import com.chuckerteam.chucker.api.ChuckerCollector
import com.chuckerteam.chucker.api.ChuckerInterceptor
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.internal.userAgent
import org.koin.android.ext.koin.androidContext import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin import org.koin.core.context.startKoin
@@ -31,10 +31,17 @@ class KotatsuApp : Application() {
PersistentCookieJar(SetCookieCache(), SharedPrefsCookiePersistor(applicationContext)) PersistentCookieJar(SetCookieCache(), SharedPrefsCookiePersistor(applicationContext))
} }
private val chuckerCollector by lazy(LazyThreadSafetyMode.NONE) {
ChuckerCollector(applicationContext)
}
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
initKoin() initKoin()
initCoil() initCoil()
if (BuildConfig.DEBUG) {
initErrorHandler()
}
AppCompatDelegate.setDefaultNightMode(AppSettings(this).theme) AppCompatDelegate.setDefaultNightMode(AppSettings(this).theme)
} }
@@ -79,6 +86,14 @@ class KotatsuApp : Application() {
}) })
} }
private fun initErrorHandler() {
val exceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler { t, e ->
chuckerCollector.onError("CRASH", e)
exceptionHandler?.uncaughtException(t, e)
}
}
private fun okHttp() = OkHttpClient.Builder().apply { private fun okHttp() = OkHttpClient.Builder().apply {
connectTimeout(20, TimeUnit.SECONDS) connectTimeout(20, TimeUnit.SECONDS)
readTimeout(60, TimeUnit.SECONDS) readTimeout(60, TimeUnit.SECONDS)
@@ -86,7 +101,7 @@ class KotatsuApp : Application() {
cookieJar(cookieJar) cookieJar(cookieJar)
addInterceptor(UserAgentInterceptor) addInterceptor(UserAgentInterceptor)
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
addInterceptor(OkHttpProfilerInterceptor()) addInterceptor(ChuckerInterceptor(applicationContext, collector = chuckerCollector))
} }
} }

View File

@@ -18,6 +18,9 @@ allprojects {
repositories { repositories {
google() google()
jcenter() jcenter()
maven {
url 'https://jitpack.io'
}
} }
} }