From 975da67bb0613f5b6928269f6ccd2b2df4b9a3b4 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Sun, 17 Mar 2024 11:21:30 +0800 Subject: [PATCH] [skip ci] autoUpdate cronet proguard rules --- .github/scripts/cronet.sh | 21 +++++ .github/workflows/cronet.yml | 1 + app/build.gradle | 2 +- app/proguard-rules.pro | 162 +---------------------------------- 4 files changed, 27 insertions(+), 159 deletions(-) diff --git a/.github/scripts/cronet.sh b/.github/scripts/cronet.sh index f1eb40009..85ef950b9 100644 --- a/.github/scripts/cronet.sh +++ b/.github/scripts/cronet.sh @@ -53,6 +53,25 @@ function write_github_env_variable() { echo "$1=$2" >> $GITHUB_ENV } +function sync_proguard_rules() { + local raw_github_git="https://raw.githubusercontent.com/chromium/chromium/$lastest_cronet_version" + local proguard_paths=( + base/android/proguard/chromium_code.flags + components/cronet/android/cronet_impl_common_proguard.cfg + components/cronet/android/cronet_impl_native_proguard.cfg + components/cronet/android/cronet_impl_platform_proguard.cfg + components/cronet/android/cronet_shared_proguard.cfg + ) + + local proguard_rules_path="$GITHUB_WORKSPACE/app/cronet_proguard_rules.pro" + rm -f proguard_rules_path + echo "fetch cronet proguard rules from upstream $raw_github_git" + for path in ${proguard_paths[@]} + do + echo "fetching $path ..." + curl "$raw_github_git/$path" >> proguard_rules_path + done +} ########## # 获取本地cronet版本 path=$GITHUB_WORKSPACE/gradle.properties @@ -66,6 +85,8 @@ if version_compare $current_cronet_version $lastest_cronet_version; then # 更新gradle.properties sed -i s/CronetVersion=.*/CronetVersion=$lastest_cronet_version/ $path sed -i s/CronetMainVersion=.*/CronetMainVersion=$lastest_cronet_main_version/ $path + # 更新cronet_proguard_rules.pro + sync_proguard_rules # 添加更新日志 sed "15a* 更新cronet: $lastest_cronet_version" -i $GITHUB_WORKSPACE/app/src/main/assets/updateLog.md # 生成pull request信息 diff --git a/.github/workflows/cronet.yml b/.github/workflows/cronet.yml index 5e9281c8f..6cad0c99a 100644 --- a/.github/workflows/cronet.yml +++ b/.github/workflows/cronet.yml @@ -50,3 +50,4 @@ jobs: *cronet.json *updateLog.md gradle.properties + cronet_proguard_rules.pro diff --git a/app/build.gradle b/app/build.gradle index 05020d495..b99978bef 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -90,7 +90,7 @@ android { applicationIdSuffix '.debug' versionNameSuffix 'debug' minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro', 'cronet_proguard_rules.pro' } } //noinspection GrDeprecatedAPIUsage diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 49c3da243..0c0f10985 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -191,9 +191,11 @@ -keep class tyrantgit.explosionfield.**{*;} -keep class freemarker.**{*;} -keep class com.gyf.barlibrary.** {*;} -##JSOUP + +## JSOUP -keep class org.jsoup.**{*;} -keep class **.xpath.**{*;} +-dontwarn org.jspecify.annotations.NullMarked -keep class org.slf4j.**{*;} -dontwarn org.slf4j.** @@ -222,7 +224,7 @@ -keep class org.mozilla.** { *; } -dontwarn org.mozilla.javascript.engine.RhinoScriptEngineFactory -###EPUB +## EPUB -dontwarn nl.siegmann.epublib.** -dontwarn org.xmlpull.** -keep class nl.siegmann.epublib.**{*;} @@ -253,162 +255,6 @@ # 繁简转换 -keep class com.github.liuyueyi.quick.transfer.** {*;} - -#-------------------Cronet------------------------------------ -# Contains flags that can be safely shared with Cronet, and thus would be -# appropriate for third-party apps to include. - -# Keep all annotation related attributes that can affect runtime --keepattributes RuntimeVisible*Annotations --keepattributes AnnotationDefault - -# Keep the annotations, because if we don't, the ProGuard rules that use them -# will not be respected. These classes then show up in our final dex, which we -# do not want - see crbug.com/628226. --keep @interface org.chromium.base.annotations.AccessedByNative --keep @interface org.chromium.base.annotations.CalledByNative --keep @interface org.chromium.base.annotations.CalledByNativeUnchecked --keep @interface org.chromium.base.annotations.DoNotInline --keep @interface org.chromium.base.annotations.UsedByReflection --keep @interface org.chromium.base.annotations.IdentifierNameString - -# Android support library annotations will get converted to androidx ones -# which we want to keep. --keep @interface androidx.annotation.Keep --keep @androidx.annotation.Keep class * --keepclasseswithmembers,allowaccessmodification class * { - @androidx.annotation.Keep ; -} --keepclasseswithmembers,allowaccessmodification class * { - @androidx.annotation.Keep ; -} - -# Keeps for class level annotations. --keep,allowaccessmodification @org.chromium.base.annotations.UsedByReflection class ** {} - -# Keeps for method level annotations. --keepclasseswithmembers,allowaccessmodification class ** { - @org.chromium.base.annotations.AccessedByNative ; -} --keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class ** { - @org.chromium.base.annotations.CalledByNative ; -} --keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class ** { - @org.chromium.base.annotations.CalledByNativeUnchecked ; -} --keepclasseswithmembers,allowaccessmodification class ** { - @org.chromium.base.annotations.UsedByReflection ; -} --keepclasseswithmembers,allowaccessmodification class ** { - @org.chromium.base.annotations.UsedByReflection ; -} -# Even unused methods kept due to explicit jni registration: -# https://crbug.com/688465. --keepclasseswithmembers,includedescriptorclasses,allowaccessmodification class !org.chromium.base.library_loader.**,** { - native ; -} --keepclasseswithmembernames,includedescriptorclasses,allowaccessmodification class org.chromium.base.library_loader.** { - native ; -} - -# Use assumevalues block instead of assumenosideeffects block because Google3 proguard cannot parse -# assumenosideeffects blocks which overwrite return value. --assumevalues class org.chromium.base.Log { - static boolean isDebug() return false; -} - -# Never inline classes, methods, or fields with this annotation, but allow -# shrinking and obfuscation. -# Relevant to fields when they are needed to store strong references to objects -# that are held as weak references by native code. --if @org.chromium.base.annotations.DoNotInline class * { - *** *(...); -} --keep,allowobfuscation,allowaccessmodification class <1> { - *** <2>(...); -} --keepclassmembers,allowobfuscation,allowaccessmodification class * { - @org.chromium.base.annotations.DoNotInline ; -} --keepclassmembers,allowobfuscation,allowaccessmodification class * { - @org.chromium.base.annotations.DoNotInline ; -} - -# Never merge classes horizontally or vertically with this annotation. -# Relevant to classes being used as a key in maps or sets. --keep,allowaccessmodification,allowobfuscation,allowshrinking @org.chromium.base.annotations.DoNotClassMerge class * - -# Keep all CREATOR fields within Parcelable that are kept. --keepclassmembers class org.chromium.** implements android.os.Parcelable { - public static *** CREATOR; -} - -# Don't obfuscate Parcelables as they might be marshalled outside Chrome. -# If we annotated all Parcelables that get put into Bundles other than -# for saveInstanceState (e.g. PendingIntents), then we could actually keep the -# names of just those ones. For now, we'll just keep them all. --keepnames,allowaccessmodification class org.chromium.** implements android.os.Parcelable {} - -# Keep all enum values and valueOf methods. See -# http://proguard.sourceforge.net/index.html#manual/examples.html -# for the reason for this. Also, see http://crbug.com/248037. --keepclassmembers enum org.chromium.** { - public static **[] values(); -} - -# Mark members annotated with IdentifierNameString as identifier name strings --identifiernamestring class * { - @org.chromium.base.annotations.IdentifierNameString *; -} - -# -identifiernamestring doesn't keep the module impl around, we have to -# explicitly keep it. --if @org.chromium.components.module_installer.builder.ModuleInterface interface * --keep,allowobfuscation,allowaccessmodification class * extends <1> { - (); -} -# Proguard config for apps that depend on cronet_impl_native_java.jar. - -# This constructor is called using the reflection from Cronet API (cronet_api.jar). --keep class org.chromium.** { *; } --keep class * extends org.chromium.net.CronetProvider{ - public (android.content.Context); -} - -# Suppress unnecessary warnings. --dontnote org.chromium.net.ProxyChangeListener$ProxyReceiver --dontnote org.chromium.net.AndroidKeyStore -# Needs 'void setTextAppearance(int)' (API level 23). --dontwarn org.chromium.base.ApiCompatibilityUtils -# Needs 'boolean onSearchRequested(android.view.SearchEvent)' (API level 23). --dontwarn org.chromium.base.WindowCallbackWrapper - -# Generated for chrome apk and not included into cronet. --dontwarn org.chromium.base.multidex.ChromiumMultiDexInstaller --dontwarn org.chromium.base.library_loader.LibraryLoader --dontwarn org.chromium.base.SysUtils --dontwarn org.chromium.build.NativeLibraries - -# Objects of this type are passed around by native code, but the class -# is never used directly by native code. Since the class is not loaded, it does -# not need to be preserved as an entry point. --dontnote org.chromium.net.UrlRequest$ResponseHeadersMap -# https://android.googlesource.com/platform/sdk/+/marshmallow-mr1-release/files/proguard-android.txt#54 --dontwarn android.support.** - -# Please add these rules to your existing keep rules in order to suppress warnings. -# This is generated automatically by the Android Gradle plugin. --dontwarn android.util.StatsEvent$Builder --dontwarn android.util.StatsEvent --dontwarn org.chromium.base.FeatureList --dontwarn org.chromium.base.FeatureMap - -# Please add these rules to your existing keep rules in order to suppress warnings. -# This is generated automatically by the Android Gradle plugin. --dontwarn org.jspecify.annotations.NullMarked - -#-------------------Cronet------------------------------------ - # Class.forName调用 -keep class io.legado.app.lib.cronet.CronetInterceptor{*;} -keep class io.legado.app.lib.cronet.CronetLoader{*;}