diff --git a/app/.gitignore b/app/.gitignore index 796b96d1c..e431c26b5 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1 +1,2 @@ /build +/so \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index f2cc4727e..3d38e0742 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 } diff --git a/app/cronetlib/src/cronet_api-src.jar b/app/cronetlib/src/cronet_api-src.jar deleted file mode 100644 index c175fb4e0..000000000 Binary files a/app/cronetlib/src/cronet_api-src.jar and /dev/null differ diff --git a/app/cronetlib/src/cronet_impl_common_java-src.jar b/app/cronetlib/src/cronet_impl_common_java-src.jar deleted file mode 100644 index 6e9402d80..000000000 Binary files a/app/cronetlib/src/cronet_impl_common_java-src.jar and /dev/null differ diff --git a/app/cronetlib/src/cronet_impl_native_java-src.jar b/app/cronetlib/src/cronet_impl_native_java-src.jar deleted file mode 100644 index 83a357a91..000000000 Binary files a/app/cronetlib/src/cronet_impl_native_java-src.jar and /dev/null differ diff --git a/app/cronetlib/src/cronet_impl_platform_java-src.jar b/app/cronetlib/src/cronet_impl_platform_java-src.jar deleted file mode 100644 index 48c544ef7..000000000 Binary files a/app/cronetlib/src/cronet_impl_platform_java-src.jar and /dev/null differ diff --git a/app/download.gradle b/app/download.gradle new file mode 100644 index 000000000..a42f545af --- /dev/null +++ b/app/download.gradle @@ -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() + + } + + +} + + diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt index 2038e461a..e55cd9c06 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt @@ -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) { diff --git a/build.gradle b/build.gradle index 967f30950..36559ec3b 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } }