feat: 引入 Conscrypt 解决 Android 8.1 TLS 握手失败
设备系统 conscrypt 版本过旧,连阿里云 OSS 的 HTTPS 握手被 reset。 引入 org.conscrypt:conscrypt-android:2.5.2 作为首选安全提供者, 在 Application.onCreate 中注册,所有网络请求自动使用现代 TLS。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,14 +2,17 @@ package com.xiaoqu.watch.app
|
||||
|
||||
import android.app.Application
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
import org.conscrypt.Conscrypt
|
||||
import timber.log.Timber
|
||||
import java.security.Security
|
||||
|
||||
/**
|
||||
* 应用入口(@HiltAndroidApp 触发 Hilt 代码生成)
|
||||
*
|
||||
* 初始化序列(必须保持 < 500ms):
|
||||
* 1. Timber 日志
|
||||
* 2. CrashHandler 崩溃恢复
|
||||
* 1. Conscrypt TLS 提供者(解决 Android 8.1 HTTPS 握手兼容)
|
||||
* 2. Timber 日志
|
||||
* 3. CrashHandler 崩溃恢复
|
||||
* 其他初始化延迟到 MainActivity/HomeFragment
|
||||
*/
|
||||
@HiltAndroidApp
|
||||
@@ -18,12 +21,16 @@ class WatchApplication : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
// 1. Timber 日志初始化
|
||||
// 1. 注册 Conscrypt 为首选 TLS 提供者(必须在任何网络请求之前)
|
||||
// 解决 Android 8.1 设备连阿里云 OSS 等服务器 TLS 握手失败的问题
|
||||
Security.insertProviderAt(Conscrypt.newProvider(), 1)
|
||||
|
||||
// 2. Timber 日志初始化
|
||||
Timber.plant(Timber.DebugTree())
|
||||
|
||||
// 2. 崩溃处理器(记录日志 + 杀进程,系统自动重启 Launcher)
|
||||
// 3. 崩溃处理器(记录日志 + 杀进程,系统自动重启 Launcher)
|
||||
CrashHandler(this).init()
|
||||
|
||||
Timber.d("WatchApplication initialized")
|
||||
Timber.d("WatchApplication initialized (Conscrypt TLS enabled)")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user