如何保留在 Flutter 应用程序的发布版本期间 R8 报告丢失的一些 com.google.android.play.core.* 类?

问题描述 投票:0回答:2

当我构建 APK 时,它的大小为 30MB。我最近从 7.4 升级到 AGP 8.1,不确定这是否会搞砸什么。

Task :app:minifyReleaseWithR8 FAILED
失败。短信是:

运行 R8 时检测到缺少类。请添加缺少的类或应用 /home/csaba/repos/flutter/track_my_indoor_exercise/build/app/outputs/mapping/release/missing_rules.txt 中生成的其他保留规则。

引用的文件包含:

# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn com.google.android.play.core.splitcompat.SplitCompatApplication
-dontwarn com.google.android.play.core.splitinstall.SplitInstallException
-dontwarn com.google.android.play.core.splitinstall.SplitInstallManager
-dontwarn com.google.android.play.core.splitinstall.SplitInstallManagerFactory
-dontwarn com.google.android.play.core.splitinstall.SplitInstallRequest$Builder
-dontwarn com.google.android.play.core.splitinstall.SplitInstallRequest
-dontwarn com.google.android.play.core.splitinstall.SplitInstallSessionState
-dontwarn com.google.android.play.core.splitinstall.SplitInstallStateUpdatedListener
-dontwarn com.google.android.play.core.tasks.OnFailureListener
-dontwarn com.google.android.play.core.tasks.OnSuccessListener
-dontwarn com.google.android.play.core.tasks.Task

我尝试添加

-keep class com.google.android.play.core.splitcompat.** { *; }
-keepclassmembernames class com.google.android.play.core.splitcompat.** { *; }
-keepclassmembers class com.google.android.play.core.splitcompat.** { *; }
-keep class com.google.android.play.core.splitinstall.** { *; }
-keepclassmembernames class com.google.android.play.core.splitinstall.** { *; }
-keepclassmembers class com.google.android.play.core.splitinstall.** { *; }
-keep class com.google.android.play.core.tasks.** { *; }
-keepclassmembernames class com.google.android.play.core.tasks.** { *; }
-keepclassmembers class com.google.android.play.core.tasks.** { *; }

进入我的 ProGuard,然后甚至尝试添加

-keep class com.google.android.play.core.splitcompat.SplitCompatApplication
-keep class com.google.android.play.core.splitinstall.SplitInstallException
-keep class com.google.android.play.core.splitinstall.SplitInstallManager
-keep class com.google.android.play.core.splitinstall.SplitInstallManagerFactory
-keep class com.google.android.play.core.splitinstall.SplitInstallRequest$Builder
-keep class com.google.android.play.core.splitinstall.SplitInstallRequest
-keep class com.google.android.play.core.splitinstall.SplitInstallSessionState
-keep class com.google.android.play.core.splitinstall.SplitInstallStateUpdatedListener
-keep class com.google.android.play.core.tasks.OnFailureListener
-keep class com.google.android.play.core.tasks.OnSuccessListener
-keep class com.google.android.play.core.tasks.Task

但同一个班级仍报告失踪。就像 ProGuard 文件被忽略什么的。

较长的任务错误:

> Task :app:minifyReleaseWithR8 FAILED
AGPBI: {"kind":"error","text":"Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /home/csaba/repos/flutter/track_my_indoor_exercise/build/app/outputs/mapping/release/missing_rules.txt.","sources":[{}]}
AGPBI: {"kind":"error","text":"Missing class com.google.android.play.core.splitcompat.SplitCompatApplication (referenced from: void io.flutter.app.FlutterPlayStoreSplitApplication.<init>() and 5 other contexts)\nMissing class com.google.android.play.core.splitinstall.SplitInstallException (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.lambda$installDeferredComponent$1(int, java.lang.String, java.lang.Exception))\nMissing class com.google.android.play.core.splitinstall.SplitInstallManager (referenced from: com.google.android.play.core.splitinstall.SplitInstallManager io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.splitInstallManager and 5 other contexts)\nMissing class com.google.android.play.core.splitinstall.SplitInstallManagerFactory (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.<init>(android.content.Context, io.flutter.embedding.engine.FlutterJNI))\nMissing class com.google.android.play.core.splitinstall.SplitInstallRequest$Builder (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.installDeferredComponent(int, java.lang.String))\nMissing class com.google.android.play.core.splitinstall.SplitInstallRequest (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.installDeferredComponent(int, java.lang.String))\nMissing class com.google.android.play.core.splitinstall.SplitInstallSessionState (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager$FeatureInstallStateUpdatedListener.onStateUpdate(com.google.android.play.core.splitinstall.SplitInstallSessionState) and 1 other context)\nMissing class com.google.android.play.core.splitinstall.SplitInstallStateUpdatedListener (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.<init>(android.content.Context, io.flutter.embedding.engine.FlutterJNI) and 2 other contexts)\nMissing class com.google.android.play.core.tasks.OnFailureListener (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.installDeferredComponent(int, java.lang.String))\nMissing class com.google.android.play.core.tasks.OnSuccessListener (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.installDeferredComponent(int, java.lang.String))\nMissing class com.google.android.play.core.tasks.Task (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.installDeferredComponent(int, java.lang.String) and 1 other context)","sources":[{}],"tool":"R8"}
Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /home/csaba/repos/flutter/track_my_indoor_exercise/build/app/outputs/mapping/release/missing_rules.txt.

Missing class com.google.android.play.core.splitcompat.SplitCompatApplication (referenced from: void io.flutter.app.FlutterPlayStoreSplitApplication.<init>() and 5 other contexts)
Missing class com.google.android.play.core.splitinstall.SplitInstallException (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.lambda$installDeferredComponent$1(int, java.lang.String, java.lang.Exception))
Missing class com.google.android.play.core.splitinstall.SplitInstallManager (referenced from: com.google.android.play.core.splitinstall.SplitInstallManager io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.splitInstallManager and 5 other contexts)
Missing class com.google.android.play.core.splitinstall.SplitInstallManagerFactory (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.<init>(android.content.Context, io.flutter.embedding.engine.FlutterJNI))
Missing class com.google.android.play.core.splitinstall.SplitInstallRequest$Builder (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.installDeferredComponent(int, java.lang.String))
Missing class com.google.android.play.core.splitinstall.SplitInstallRequest (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.installDeferredComponent(int, java.lang.String))
Missing class com.google.android.play.core.splitinstall.SplitInstallSessionState (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager$FeatureInstallStateUpdatedListener.onStateUpdate(com.google.android.play.core.splitinstall.SplitInstallSessionState) and 1 other context)
Missing class com.google.android.play.core.splitinstall.SplitInstallStateUpdatedListener (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.<init>(android.content.Context, io.flutter.embedding.engine.FlutterJNI) and 2 other contexts)
Missing class com.google.android.play.core.tasks.OnFailureListener (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.installDeferredComponent(int, java.lang.String))
Missing class com.google.android.play.core.tasks.OnSuccessListener (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.installDeferredComponent(int, java.lang.String))
Missing class com.google.android.play.core.tasks.Task (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.installDeferredComponent(int, java.lang.String) and 1 other context)

出错时的规则文件:https://github.com/TrackMyIndoorWorkout/TrackMyIndoorWorkout/blob/11d7bc8a1a6407dfe257ccbe6a68ac531c36719e/android/app/proguard-rules.pro

android flutter proguard android-r8
2个回答
0
投票

事实证明这确实与 Flutter 有关。我还没有透露我的整个 proguard 规则,因为我对每个 Flutter 插件都有避免

MissingPluginException
的规则(关于这一点,请参阅 https://csaba.page/blog/the-dreaded-missing-plugin-exception.html以及我使用的规则https://csaba.page/blog/flutter-android-crash-remedies.html)。完整的规则文件如下:https://github.com/TrackMyIndoorWorkout/TrackMyIndoorWorkout/blob/11d7bc8a1a6407dfe257ccbe6a68ac531c36719e/android/app/proguard-rules.pro

我再次查看了较长(详细)的任务错误。我注意到了

referenced from: 
部分,并参考了
io.flutter.app...
io.flutter.embedding.engine...
。并注意到我对此有一些规则,因为在过去的某个时候我处理了 Flutter 问题 https://github.com/flutter/flutter/issues/78625#issuecomment-804164524

我注释掉了

-keep class io.flutter.app.** { *; }
-keep class io.flutter.** { *; }
规则,现在应用程序发布构建成功了。那部分规则现在是这样的:

# https://github.com/flutter/flutter/issues/78625#issuecomment-804164524
#-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
#-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }

有了这个,我不需要添加任何关于引用的

dontwarn
类的
keep
com.google.android.play.core...
规则。我仍然需要测试该构建是否按预期运行。


0
投票

将以下行添加到应用程序的

release
build.gradle
部分:

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

这会为您的 Android 应用程序配置混淆器规则文件,我不知道为什么默认情况下不包含它。

© www.soinside.com 2019 - 2024. All rights reserved.