Cronet 支持DnsHttpsSvcb

Cronet 设置`UseDnsHttpsSvcb`等实验选项支持HTTPS 类型的dns请求,从dns HTTPS记录中就能获取到支持的alpn,用来确定升级http3。

77379815db
pull/2348/head
ag2s20150909 2 years ago
parent b918029eff
commit 15fbc844f1
  1. 20
      app/build.gradle
  2. 24
      app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt
  3. 11
      epublib/build.gradle
  4. 1
      gradle.properties
  5. 4
      gradle/wrapper/gradle-wrapper.properties

@ -16,7 +16,7 @@ def version = "3." + releaseTime()
def gitCommits = Integer.parseInt('git rev-list HEAD --count'.execute().text.trim()) def gitCommits = Integer.parseInt('git rev-list HEAD --count'.execute().text.trim())
android { android {
compileSdkVersion 33 compileSdk 33
buildToolsVersion "33.0.0" buildToolsVersion "33.0.0"
namespace 'io.legado.app' namespace 'io.legado.app'
kotlinOptions { kotlinOptions {
@ -47,6 +47,8 @@ android {
project.ext.set("archivesBaseName", name + "_" + version) project.ext.set("archivesBaseName", name + "_" + version)
multiDexEnabled true multiDexEnabled true
buildConfigField "String", "Cronet_Version", "\"$CronetVersion\""
javaCompileOptions { javaCompileOptions {
annotationProcessorOptions { annotationProcessorOptions {
arguments += [ arguments += [
@ -63,7 +65,6 @@ android {
} }
buildTypes { buildTypes {
release { release {
buildConfigField "String", "Cronet_Version", "\"$CronetVersion\""
if (project.hasProperty("RELEASE_STORE_FILE")) { if (project.hasProperty("RELEASE_STORE_FILE")) {
signingConfig signingConfigs.myConfig signingConfig signingConfigs.myConfig
} }
@ -73,7 +74,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
} }
debug { debug {
buildConfigField "String", "Cronet_Version", "\"$CronetVersion\""
if (project.hasProperty("RELEASE_STORE_FILE")) { if (project.hasProperty("RELEASE_STORE_FILE")) {
signingConfig signingConfigs.myConfig signingConfig signingConfigs.myConfig
} }
@ -82,13 +83,15 @@ android {
minifyEnabled false minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
} }
android.applicationVariants.all { variant -> }
variant.outputs.all {
def flavor = variant.productFlavors[0].name android.applicationVariants.all { variant ->
outputFileName = "${name}_${flavor}_${defaultConfig.versionName}.apk" variant.outputs.all {
} def flavor = variant.productFlavors[0].name
outputFileName = "${name}_${flavor}_${defaultConfig.versionName}.apk"
} }
} }
flavorDimensions "mode" flavorDimensions "mode"
productFlavors { productFlavors {
app { app {
@ -125,6 +128,7 @@ android {
} }
dependencies { dependencies {
compileOnly "com.android.tools.build:gradle:$agp_version"
//noinspection GradleDependency,GradlePackageUpdate //noinspection GradleDependency,GradlePackageUpdate
coreLibraryDesugaring('com.android.tools:desugar_jdk_libs:1.2.2') coreLibraryDesugaring('com.android.tools:desugar_jdk_libs:1.2.2')
testImplementation('junit:junit:4.13.2') testImplementation('junit:junit:4.13.2')

@ -12,6 +12,7 @@ import org.chromium.net.CronetEngine.Builder.HTTP_CACHE_DISK
import org.chromium.net.ExperimentalCronetEngine import org.chromium.net.ExperimentalCronetEngine
import org.chromium.net.UploadDataProviders import org.chromium.net.UploadDataProviders
import org.chromium.net.UrlRequest import org.chromium.net.UrlRequest
import org.json.JSONObject
import splitties.init.appCtx import splitties.init.appCtx
@ -29,6 +30,7 @@ val cronetEngine: ExperimentalCronetEngine? by lazy {
enableHttp2(true) //设置支持http/2 enableHttp2(true) //设置支持http/2
enablePublicKeyPinningBypassForLocalTrustAnchors(true) enablePublicKeyPinningBypassForLocalTrustAnchors(true)
enableBrotli(true)//Brotli压缩 enableBrotli(true)//Brotli压缩
setExperimentalOptions(options)
} }
try { try {
val engine = builder.build() val engine = builder.build()
@ -40,6 +42,28 @@ val cronetEngine: ExperimentalCronetEngine? by lazy {
} }
} }
val options by lazy {
val options = JSONObject()
//设置域名映射规则
//MAP hostname ip,MAP hostname ip
// val host = JSONObject()
// host.put("host_resolver_rules","")
// options.put("HostResolverRules", host)
//启用DnsHttpsSvcb更容易迁移到http3
val dnsSvcb = JSONObject()
dnsSvcb.put("enable", true)
dnsSvcb.put("enable_insecure", true)
dnsSvcb.put("use_alpn", true)
options.put("UseDnsHttpsSvcb", dnsSvcb)
options.put("AsyncDNS", JSONObject("{'enable':true}"))
options.toString()
}
fun buildRequest(request: Request, callback: UrlRequest.Callback): UrlRequest? { fun buildRequest(request: Request, callback: UrlRequest.Callback): UrlRequest? {
val url = request.url.toString() val url = request.url.toString()
val headers: Headers = request.headers val headers: Headers = request.headers

@ -3,12 +3,12 @@ plugins {
} }
android { android {
compileSdkVersion 32 compileSdk 33
buildToolsVersion '32.0.0' //buildToolsVersion '32.0.0'
namespace 'me.ag2s.epublib' namespace 'me.ag2s.epublib'
defaultConfig { defaultConfig {
minSdkVersion 21 minSdk 21
targetSdkVersion 32 targetSdk 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro" consumerProguardFiles "consumer-rules.pro"
@ -19,8 +19,6 @@ android {
minifyEnabled false minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
} }
android {
}
} }
compileOptions { compileOptions {
@ -33,5 +31,6 @@ android {
} }
dependencies { dependencies {
compileOnly "com.android.tools.build:gradle:$agp_version"
implementation "androidx.annotation:annotation:1.5.0" implementation "androidx.annotation:annotation:1.5.0"
} }

@ -19,6 +19,7 @@ android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete": # Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official kotlin.code.style=official
kotlin.incremental.useClasspathSnapshot=true
android.enableResourceOptimizations=true android.enableResourceOptimizations=true
android.enableNewResourceShrinker=true android.enableNewResourceShrinker=true
android.experimental.enableNewResourceShrinker.preciseShrinking=true android.experimental.enableNewResourceShrinker.preciseShrinking=true

@ -1,6 +1,6 @@
#Mon May 23 22:07:39 CST 2022 #Mon Sep 26 08:03:55 CST 2022
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME

Loading…
Cancel
Save