pull/1273/head
gedoor 3 years ago
parent 0bd978d6b7
commit 83ec9746a9
  1. 2
      app/build.gradle
  2. 2
      app/src/main/java/io/legado/app/App.kt
  3. 24
      app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt
  4. 5
      app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt

@ -182,7 +182,7 @@ dependencies {
//
implementation('com.squareup.okhttp3:okhttp:4.9.1')
appImplementation(fileTree(dir: 'cronetlib', include: ['*.jar', '*.aar']))
implementation(fileTree(dir: 'cronetlib', include: ['*.jar', '*.aar']))
googleImplementation 'com.google.android.gms:play-services-cronet:17.0.0'
//Glide

@ -23,7 +23,7 @@ class App : MultiDexApplication() {
override fun onCreate() {
super.onCreate()
CrashHandler(this)
if (AppConfig.isCronet) {
if (AppConfig.isCronet && !AppConfig.isGooglePlay) {
//预下载Cronet so
CronetLoader.preDownload()
}

@ -1,6 +1,7 @@
package io.legado.app.help.http.cronet
import android.util.Log
import io.legado.app.help.AppConfig
import okhttp3.Headers
import okhttp3.MediaType
import okhttp3.Request
@ -19,18 +20,21 @@ val executor: Executor by lazy { Executors.newCachedThreadPool() }
val cronetEngine: ExperimentalCronetEngine by lazy {
CronetLoader.preDownload()
val builder = ExperimentalCronetEngine.Builder(appCtx)
.setLibraryLoader(CronetLoader)//设置自定义so库加载
.setStoragePath(appCtx.externalCacheDir?.absolutePath)//设置缓存路径
.enableHttpCache(HTTP_CACHE_DISK, (1024 * 1024 * 50))//设置缓存模式
.enableQuic(true)//设置支持http/3
.enableHttp2(true) //设置支持http/2
.enablePublicKeyPinningBypassForLocalTrustAnchors(true)
//.enableNetworkQualityEstimator(true)
val builder = ExperimentalCronetEngine.Builder(appCtx).apply {
if (!AppConfig.isGooglePlay) {
setLibraryLoader(CronetLoader)//设置自定义so库加载
}
setStoragePath(appCtx.externalCacheDir?.absolutePath)//设置缓存路径
enableHttpCache(HTTP_CACHE_DISK, (1024 * 1024 * 50))//设置缓存模式
enableQuic(true)//设置支持http/3
enableHttp2(true) //设置支持http/2
enablePublicKeyPinningBypassForLocalTrustAnchors(true)
//enableNetworkQualityEstimator(true)
//Brotli压缩
builder.enableBrotli(true)
//builder.setExperimentalOptions("{\"quic_version\": \"h3-29\"}")
enableBrotli(true)
//setExperimentalOptions("{\"quic_version\": \"h3-29\"}")
}
val engine = builder.build()
Log.d("Cronet", "Cronet Version:" + engine.versionString)
//这会导致Jsoup的网络请求出现问题,暂时不接管系统URL

@ -6,6 +6,7 @@ import android.content.pm.ApplicationInfo
import android.os.Build
import android.text.TextUtils
import android.util.Log
import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.utils.getPrefString
import io.legado.app.utils.putPrefString
@ -50,10 +51,14 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() {
}
fun install(): Boolean {
if (AppConfig.isGooglePlay) {
return true
}
return soFile.exists()
}
fun preDownload() {
if (AppConfig.isGooglePlay) return
Coroutine.async {
md5 = getUrlMd5(md5Url)
if (soFile.exists() && md5 == getFileMD5(soFile)) {

Loading…
Cancel
Save