使用Gradle下载Cronet,自动计算md5

pull/1276/head
ag2s20150909 3 years ago
parent 5b7687393a
commit 7c8bd82029
  1. 1
      app/.gitignore
  2. 4
      app/build.gradle
  3. BIN
      app/cronetlib/src/cronet_api-src.jar
  4. BIN
      app/cronetlib/src/cronet_impl_common_java-src.jar
  5. BIN
      app/cronetlib/src/cronet_impl_native_java-src.jar
  6. BIN
      app/cronetlib/src/cronet_impl_platform_java-src.jar
  7. 108
      app/download.gradle
  8. 1
      app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt
  9. 1
      build.gradle

1
app/.gitignore vendored

@ -1 +1,2 @@
/build
/so

@ -3,6 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-parcelize'
apply plugin: 'kotlin-kapt'
apply plugin: 'de.timfreiheit.resourceplaceholders'
apply from:'download.gradle'
static def releaseTime() {
return new Date().format("yy.MMddHH", TimeZone.getTimeZone("GMT+8"))
@ -55,14 +56,17 @@ android {
}
buildTypes {
release {
buildConfigField "String", "Cronet_Version", "\"$CronetVersion\""
if (project.hasProperty("RELEASE_STORE_FILE")) {
signingConfig signingConfigs.myConfig
}
applicationIdSuffix '.release'
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
buildConfigField "String", "Cronet_Version", "\"$CronetVersion\""
if (project.hasProperty("RELEASE_STORE_FILE")) {
signingConfig signingConfigs.myConfig
}

@ -0,0 +1,108 @@
import java.security.MessageDigest
apply plugin: 'de.undercouch.download'
def BASE_PATH = "https://storage.googleapis.com/chromium-cronet/android/" + CronetVersion + "/Release/cronet/"
def assetsDir = projectDir.toString() + "/src/main/assets"
def libPath = projectDir.toString() + "/libs"
def soPath = projectDir.toString() + "/so"
/**
* MD5
* @param file
* @return
*/
static def generateMD5(final file) {
MessageDigest digest = MessageDigest.getInstance("MD5")
file.withInputStream() { is ->
byte[] buffer = new byte[1024]
//int numRead = 0
while ((numRead = is.read(buffer)) > 0) {
digest.update(buffer, 0, numRead)
}
}
return String.format("%032x", new BigInteger(1, digest.digest())).toLowerCase()
}
/**
* Cronet相关的jar
*/
task downloadJar(type: Download) {
src([
BASE_PATH + "cronet_api.jar",
BASE_PATH + "cronet_impl_common_java.jar",
BASE_PATH + "cronet_impl_native_java.jar",
BASE_PATH + "cronet_impl_platform_java.jar",
])
dest libPath
overwrite true
onlyIfModified true
}
/**
* Cronet的arm64-v8a so
*/
task downloadARM64(type: Download) {
src BASE_PATH + "libs/arm64-v8a/libcronet." + CronetVersion + ".so"
dest soPath + "/arm64-v8a.so"
overwrite true
onlyIfModified true
}
/**
* Cronet的armeabi-v7a so
*/
task downloadARMv7(type: Download) {
src BASE_PATH + "libs/armeabi-v7a/libcronet." + CronetVersion + ".so"
dest soPath + "/armeabi-v7a.so"
overwrite true
onlyIfModified true
}
/**
* Cronet的x86_64 so
*/
task downloadX86_64(type: Download) {
src BASE_PATH + "libs/x86_64/libcronet." + CronetVersion + ".so"
dest soPath + "/x86_64.so"
overwrite true
onlyIfModified true
}
/**
* Cronet的x86 so
*/
task downloadX86(type: Download) {
src BASE_PATH + "libs/x86/libcronet." + CronetVersion + ".so"
dest soPath + "/x86.so"
overwrite true
onlyIfModified true
}
/**
* Cronet版本时执行这个task
*/
task downloadCronet() {
dependsOn downloadJar, downloadARM64, downloadARMv7, downloadX86_64, downloadX86
doLast {
StringBuilder sb = new StringBuilder("{")
def files = new File(soPath).listFiles()
for (File file : files) {
println file.name.replace(".so", "")
sb.append("\"").append(file.name.replace(".so", "")).append("\":\"").append(generateMD5(file)).append("\",")
}
sb.append("\"version\":\"").append(CronetVersion).append("\"}")
println sb.toString()
println assetsDir
def f1 = new File(assetsDir + "/cronet.json")
if (!f1.exists()) {
f1.parentFile.mkdirs()
f1.createNewFile()
}
f1.text = sb.toString()
}
}

@ -15,6 +15,7 @@ class CronetInterceptor(private val cookieJar: CookieJar?) : Interceptor {
} else try {
//移除Keep-Alive,手动设置会导致400 BadRequest
builder.removeHeader("Keep-Alive")
builder.removeHeader("Accept-Encoding")
val cookieStr = getCookie(original.url)
//设置Cookie
if (cookieStr.length > 3) {

@ -13,6 +13,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:7.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'de.timfreiheit.resourceplaceholders:placeholders:0.4'
classpath 'de.undercouch:gradle-download-task:4.1.2'
}
}

Loading…
Cancel
Save