feat: release 包移除 HttpLoggingInterceptor 依赖
This commit is contained in:
parent
787df0801b
commit
9f0b64a619
40
Readme.md
40
Readme.md
|
|
@ -1,13 +1,17 @@
|
||||||
Room 数据持久化;Worker管理上传任务,初次上传+重试共5次,重试间隔10s线性增加;多上传任务顺序处理;
|
Room 数据持久化;Worker管理上传任务,初次上传+重试共5次,重试间隔10s线性增加;多上传任务顺序处理;
|
||||||
网络请求 Retrofit
|
网络请求 Retrofit
|
||||||
|
|
||||||
### debug release 区别
|
### debug release 区别
|
||||||
| BuildType | 域名 | 是否打印日志 |
|
|
||||||
|----------|------|--------------|
|
| BuildType | 域名 | 是否打印日志 | HttpLoggingInterceptor依赖 |
|
||||||
| debug | http://192.168.2.7:18828 | 是 |
|
|-----------|--------------------------|--------|--------------------------|
|
||||||
| release | https://track.23544.com | 否 |
|
| debug | http://192.168.2.7:18828 | 是 | 有 |
|
||||||
|
| release | https://track.23544.com | 否 | 无 |
|
||||||
|
|
||||||
### 使用
|
### 使用
|
||||||
#### 1.0.12
|
|
||||||
|
#### 1.0.13
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
|
|
@ -34,6 +38,24 @@ debugImplementation("com.yuanxuan:tracking_point:x.x.x-SNAPSHOT")
|
||||||
//生产环境
|
//生产环境
|
||||||
releaseImplementation("com.yuanxuan:tracking_point:x.x.x")
|
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
|
```kotlin
|
||||||
/**
|
/**
|
||||||
* 初始化
|
* 初始化
|
||||||
|
|
@ -48,8 +70,8 @@ TrackingManager.init(
|
||||||
/**
|
/**
|
||||||
* 实现 ITrackingPointUserInfo 获取 UserInfo 的方法
|
* 实现 ITrackingPointUserInfo 获取 UserInfo 的方法
|
||||||
*/
|
*/
|
||||||
class TrackingPointUserInfoImp: ITrackingPointUserInfo {
|
class TrackingPointUserInfoImp : ITrackingPointUserInfo {
|
||||||
override fun uploadUserInfo(): UserInfo? {
|
override fun uploadUserInfo(): UserInfo? {
|
||||||
return UserInfo(
|
return UserInfo(
|
||||||
userId = 123456,
|
userId = 123456,
|
||||||
userName = "username",
|
userName = "username",
|
||||||
|
|
@ -65,9 +87,9 @@ class TrackingPointUserInfoImp: ITrackingPointUserInfo {
|
||||||
TrackingManager.push(
|
TrackingManager.push(
|
||||||
eventType = "dianji", //通过管理平台获取
|
eventType = "dianji", //通过管理平台获取
|
||||||
eventParams = EventParams(
|
eventParams = EventParams(
|
||||||
buttonId = "${view.id}",
|
buttonId = "R.id.xxxxx", //最好传控件的 R.id.xxx 方便找到此控件
|
||||||
page = "Main",
|
page = "Main",
|
||||||
url = ""
|
url = ""
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ plugins {
|
||||||
id("maven-publish")
|
id("maven-publish")
|
||||||
}
|
}
|
||||||
group = "com.yuanxuan"
|
group = "com.yuanxuan"
|
||||||
version = "1.0.12"
|
version = "1.0.13"
|
||||||
|
|
||||||
|
|
||||||
val baseReleaseUrl: Provider<String> = providers.gradleProperty("baseReleaseUrl")
|
val baseReleaseUrl: Provider<String> = providers.gradleProperty("baseReleaseUrl")
|
||||||
|
|
@ -117,7 +117,7 @@ dependencies {
|
||||||
implementation(libs.androidx.work.ktx)
|
implementation(libs.androidx.work.ktx)
|
||||||
implementation(libs.retrofit)
|
implementation(libs.retrofit)
|
||||||
implementation(libs.retrofit.converter.moshi)
|
implementation(libs.retrofit.converter.moshi)
|
||||||
implementation(libs.okhttp.logging.interceptor)
|
debugImplementation(libs.okhttp.logging.interceptor)
|
||||||
implementation(libs.moshi)
|
implementation(libs.moshi)
|
||||||
ksp(libs.moshi.kotlin.codegen)
|
ksp(libs.moshi.kotlin.codegen)
|
||||||
implementation(libs.androidx.room)
|
implementation(libs.androidx.room)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
package com.yuanxuan.tracking_point.library.http
|
package com.yuanxuan.tracking_point.library.http
|
||||||
|
|
||||||
import com.yuanxuan.tracking_point.library.BuildConfig
|
import com.yuanxuan.tracking_point.library.BuildConfig
|
||||||
import com.yuanxuan.tracking_point.library.util.Logger
|
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.logging.HttpLoggingInterceptor
|
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
import retrofit2.converter.moshi.MoshiConverterFactory
|
import retrofit2.converter.moshi.MoshiConverterFactory
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
@ -11,18 +9,12 @@ import kotlin.jvm.java
|
||||||
|
|
||||||
internal object RetrofitClient {
|
internal object RetrofitClient {
|
||||||
private val okHttpClient: OkHttpClient by lazy {
|
private val okHttpClient: OkHttpClient by lazy {
|
||||||
val httpLoggingInterceptor by lazy {
|
|
||||||
HttpLoggingInterceptor { message ->
|
|
||||||
Logger.debug(message)
|
|
||||||
}.apply {
|
|
||||||
level = HttpLoggingInterceptor.Level.BODY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
OkHttpClient.Builder()
|
OkHttpClient.Builder()
|
||||||
.connectTimeout(15L, TimeUnit.SECONDS)
|
.connectTimeout(15L, TimeUnit.SECONDS)
|
||||||
.readTimeout(30L, TimeUnit.SECONDS)
|
.readTimeout(30L, TimeUnit.SECONDS)
|
||||||
.writeTimeout(30L, TimeUnit.SECONDS)
|
.writeTimeout(30L, TimeUnit.SECONDS)
|
||||||
.addInterceptor(httpLoggingInterceptor)
|
.addInterceptor(HttpLogger.interceptor())
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@ internal data class DeviceInfo(
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class EventParams(
|
data class EventParams(
|
||||||
|
/**
|
||||||
|
* 最好传view的"R.id.xxxxx" 方便找到控件
|
||||||
|
*/
|
||||||
val buttonId: String,
|
val buttonId: String,
|
||||||
val page: String,
|
val page: String,
|
||||||
val url: String
|
val url: String
|
||||||
|
|
|
||||||
|
|
@ -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()) }
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue