【问题标题】:Flutter Local Notifications - Progaurd Rules does not allow to build release versionFlutter 本地通知 - Proguard 规则不允许构建发布版本
【发布时间】:2022-01-03 08:41:29
【问题描述】:

我在我的一个应用程序中使用了flutter_local_notifications,并根据文档设置了progaurd-rules.pro。

android/app/progaurd-rules.pro

## Gson rules
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}

-keep class com.dexterous.** { *; }

有了这个,我可以正常运行调试版本。但是,在构建发布版本时,我得到了例外:

Running Gradle task 'assembleRelease'...
ERROR:: R8: com.android.tools.r8.errors.b: Attribute Signature requires InnerClasses attribute. Check -keepattributes directive.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:minifyReleaseWithR8'.
> com.android.tools.r8.CompilationFailedException: Compilation failed to complete

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 16s
[!] The shrinker may have failed to optimize the Java bytecode.
    To disable the shrinker, pass the `--no-shrink` flag to this command.
    To learn more, see: https://developer.android.com/studio/build/shrink-code
Exception: Gradle task assembleRelease failed with exit code 1

现在,我不想使用“--no-shrink”。知道我的 progaurd-rules.pro 文件有什么问题吗?

【问题讨论】:

    标签: flutter flutter-local-notification


    【解决方案1】:

    我自己解决了这个问题。将-keepattributes InnerClasses 添加到文件中解决了这个问题。

    更新的 Progaurd:

    ## Gson rules
    # Gson uses generic type information stored in a class file when working with fields. Proguard
    # removes such information by default, so configure it to keep all of it.
    -keepattributes InnerClasses
    -keepattributes Signature
    
    # For using GSON @Expose annotation
    -keepattributes *Annotation*
    
    # Gson specific classes
    -dontwarn sun.misc.**
    #-keep class com.google.gson.stream.** { *; }
    
    # Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
    # JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
    -keep class * extends com.google.gson.TypeAdapter
    -keep class * implements com.google.gson.TypeAdapterFactory
    -keep class * implements com.google.gson.JsonSerializer
    -keep class * implements com.google.gson.JsonDeserializer
    
    # Prevent R8 from leaving Data object members always null
    -keepclassmembers,allowobfuscation class * {
      @com.google.gson.annotations.SerializedName <fields>;
    }
    
    -keep class com.dexterous.** { *; }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-06
      • 2022-11-29
      • 1970-01-01
      • 2022-07-27
      • 2014-02-06
      • 2020-11-16
      • 1970-01-01
      • 2020-12-03
      相关资源
      最近更新 更多