feat: release 包移除 HttpLoggingInterceptor 依赖

This commit is contained in:
yangxisong 2025-12-16 12:01:16 +08:00
parent 787df0801b
commit 9f0b64a619
6 changed files with 60 additions and 21 deletions

View File

@ -1,13 +1,17 @@
Room 数据持久化Worker管理上传任务初次上传+重试共5次重试间隔10s线性增加多上传任务顺序处理
网络请求 Retrofit
### debug release 区别
| BuildType | 域名 | 是否打印日志 |
|----------|------|--------------|
| debug | http://192.168.2.7:18828 | 是 |
| release | https://track.23544.com | 否 |
| BuildType | 域名 | 是否打印日志 | HttpLoggingInterceptor依赖 |
|-----------|--------------------------|--------|--------------------------|
| debug | http://192.168.2.7:18828 | 是 | 有 |
| release | https://track.23544.com | 否 | 无 |
### 使用
#### 1.0.12
#### 1.0.13
```kotlin
repositories {
google()
@ -34,6 +38,24 @@ debugImplementation("com.yuanxuan:tracking_point:x.x.x-SNAPSHOT")
//生产环境
releaseImplementation("com.yuanxuan:tracking_point:x.x.x")
```
### 常见问题
```kotlin
// aar中 使用 `retrofit:3.0.0` `okhttp:5.3.2` 如果你的项目使用的 `okhttp:4.x` 或更久的版本
implementation("com.squareup.okhttp3:okhttp:4.12.0")
debugImplementation("com.yuanxuan:tracking_point:1.0.13-SNAPSHOT") {
// 排除掉aar中的 okhttp 相关依赖
exclude(group = "com.squareup.okhttp3")
}
// 因为这是测试版的aar 还需要添加拦截器
debugImplementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
// release版 就只需要排除掉okhttp
implementation("com.yuanxuan:tracking_point:1.0.13") {
exclude(group = "com.squareup.okhttp3", module = "okhttp")
}
```
```kotlin
/**
* 初始化
@ -48,8 +70,8 @@ TrackingManager.init(
/**
* 实现 ITrackingPointUserInfo 获取 UserInfo 的方法
*/
class TrackingPointUserInfoImp: ITrackingPointUserInfo {
override fun uploadUserInfo(): UserInfo? {
class TrackingPointUserInfoImp : ITrackingPointUserInfo {
override fun uploadUserInfo(): UserInfo? {
return UserInfo(
userId = 123456,
userName = "username",
@ -65,9 +87,9 @@ class TrackingPointUserInfoImp: ITrackingPointUserInfo {
TrackingManager.push(
eventType = "dianji", //通过管理平台获取
eventParams = EventParams(
buttonId = "${view.id}",
buttonId = "R.id.xxxxx", //最好传控件的 R.id.xxx 方便找到此控件
page = "Main",
url = ""
url = ""
)
)
```

View File

@ -7,7 +7,7 @@ plugins {
id("maven-publish")
}
group = "com.yuanxuan"
version = "1.0.12"
version = "1.0.13"
val baseReleaseUrl: Provider<String> = providers.gradleProperty("baseReleaseUrl")
@ -117,7 +117,7 @@ dependencies {
implementation(libs.androidx.work.ktx)
implementation(libs.retrofit)
implementation(libs.retrofit.converter.moshi)
implementation(libs.okhttp.logging.interceptor)
debugImplementation(libs.okhttp.logging.interceptor)
implementation(libs.moshi)
ksp(libs.moshi.kotlin.codegen)
implementation(libs.androidx.room)

View File

@ -0,0 +1,14 @@
package com.yuanxuan.tracking_point.library.http
import com.yuanxuan.tracking_point.library.util.Logger
import okhttp3.Interceptor
import okhttp3.logging.HttpLoggingInterceptor
object HttpLogger {
fun interceptor(): Interceptor =
HttpLoggingInterceptor { message ->
Logger.debug(message)
}.apply {
level = HttpLoggingInterceptor.Level.BODY
}
}

View File

@ -1,9 +1,7 @@
package com.yuanxuan.tracking_point.library.http
import com.yuanxuan.tracking_point.library.BuildConfig
import com.yuanxuan.tracking_point.library.util.Logger
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
import java.util.concurrent.TimeUnit
@ -11,18 +9,12 @@ import kotlin.jvm.java
internal object RetrofitClient {
private val okHttpClient: OkHttpClient by lazy {
val httpLoggingInterceptor by lazy {
HttpLoggingInterceptor { message ->
Logger.debug(message)
}.apply {
level = HttpLoggingInterceptor.Level.BODY
}
}
OkHttpClient.Builder()
.connectTimeout(15L, TimeUnit.SECONDS)
.readTimeout(30L, TimeUnit.SECONDS)
.writeTimeout(30L, TimeUnit.SECONDS)
.addInterceptor(httpLoggingInterceptor)
.addInterceptor(HttpLogger.interceptor())
.build()
}

View File

@ -24,6 +24,9 @@ internal data class DeviceInfo(
@JsonClass(generateAdapter = true)
data class EventParams(
/**
* 最好传view的"R.id.xxxxx" 方便找到控件
*/
val buttonId: String,
val page: String,
val url: String

View File

@ -0,0 +1,8 @@
package com.yuanxuan.tracking_point.library.http
import okhttp3.Interceptor
object HttpLogger {
fun interceptor(): Interceptor =
Interceptor { chain -> chain.proceed(chain.request()) }
}