如何修复 ProGuard 的错误

huangapple go评论79阅读模式
英文:

How to fix ProGuard bugs

问题

在我的应用程序中,我想启用 ProGuard 并编写 ProGuard 规则,但在生成 APK 后,在 logcat 中显示了一些错误。

在我的应用程序中,我想启用 ProGuard 并编写 ProGuard 规则,但在生成 APK 后,在 logcat 中显示了一些错误。

显示以下错误:

错误:D:\Projects\myapp\BaseApp.0.22\app\proguard-rules.pro,偏移量:3207,行:88,列:7,预期 [!]interface|@interface|class|enum

ProGuard 规则:

##########################
#        OKHTTP          #
##########################
-dontwarn javax.annotation.**
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
-dontwarn org.codehaus.mojo.animal_sniffer.*
-dontwarn okhttp3.internal.platform.ConscryptPlatform
##########################
#        OKIO            #
##########################
-dontwarn org.codehaus.mojo.animal_sniffer.*
##########################
#        RETROFIT        #
##########################
-keepattributes Signature, InnerClasses, EnclosingMethod
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
-keepclassmembers,allowshrinking,allowobfuscation interface * {
    @retrofit2.http.* <methods>;
}
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn javax.annotation.**
-dontwarn kotlin.Unit
-dontwarn retrofit2.KotlinExtensions
-dontwarn retrofit2.KotlinExtensions$*
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>
##########################
#        GSON            #
##########################
-keepattributes Signature
-keepattributes *Annotation*
-dontwarn sun.misc.**
-keep class com.google.gson.examples.android.model.** { <fields>; }
-keep class * implements 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
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}
##########################
#        GLIDE           #
##########################
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}
##########################
#        ROOM            #
##########################
-keep class * extends androidx.room.RoomDatabase
-dontwarn androidx.room.paging.**
##########################
#       EVENTBUS         #
##########################
-keepattributes *Annotation*
-keepclassmembers class * {
    @org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
    <init>(java.lang.Throwable);
}
##########################
#          YOYO          #
##########################
-keep class com.daimajia.easing.** { *; }
-keep interface com.daimajia.easing.* { *; }
-keep class com.daimajia.** { *; }
-dontwarn com.daimajia.**
-keepnames class com.daimajia.**
##########################
#        PDFVIEW         #
##########################
-keep class com.shockwave.**
##########################
#      DOWNLOADER        #
##########################
-keep class com.downloader.** {*;}
##########################
#       MY_FILES         #
##########################
-dontwarn com.app.app.data.model.**
-keep class com.app.app.data.model.** { *;}
-dontwarn com.app.app.utils.custom_view.**
-keep com.app.app.utils.custom_view.** { *;}

显示 第 88 行 的错误,而 第 88 行-keep com.app.app.utils.custom_view.** { *;}

我该如何修复这个问题?

英文:

In my application i want enable proguard and write proguard rules, but after generate apk show me some errors in in logcat.<br>

In my application i want enable proguard and write proguard rules, but after generate apk show me some errors in in logcat.<br>

Show me this error :

Error: D:\Projects\myapp\BaseApp.0.22\app\proguard-rules.pro, offset: 3207, line: 88, column: 7, Expected [!]interface|@interface|class|enum

ProGuard rules:

##########################
#        OKHTTP          #
##########################
-dontwarn javax.annotation.**
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
-dontwarn org.codehaus.mojo.animal_sniffer.*
-dontwarn okhttp3.internal.platform.ConscryptPlatform
##########################
#        OKIO            #
##########################
-dontwarn org.codehaus.mojo.animal_sniffer.*
##########################
#        RETROFIT        #
##########################
-keepattributes Signature, InnerClasses, EnclosingMethod
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
-keepclassmembers,allowshrinking,allowobfuscation interface * {
    @retrofit2.http.* &lt;methods&gt;;
}
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn javax.annotation.**
-dontwarn kotlin.Unit
-dontwarn retrofit2.KotlinExtensions
-dontwarn retrofit2.KotlinExtensions$*
-if interface * { @retrofit2.http.* &lt;methods&gt;; }
-keep,allowobfuscation interface &lt;1&gt;
##########################
#        GSON            #
##########################
-keepattributes Signature
-keepattributes *Annotation*
-dontwarn sun.misc.**
-keep class com.google.gson.examples.android.model.** { &lt;fields&gt;; }
-keep class * implements 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
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName &lt;fields&gt;;
}
##########################
#        GLIDE           #
##########################
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}
##########################
#        ROOM            #
##########################
-keep class * extends androidx.room.RoomDatabase
-dontwarn androidx.room.paging.**
##########################
#       EVENTBUS         #
##########################
-keepattributes *Annotation*
-keepclassmembers class * {
    @org.greenrobot.eventbus.Subscribe &lt;methods&gt;;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
    &lt;init&gt;(java.lang.Throwable);
}
##########################
#          YOYO          #
##########################
-keep class com.daimajia.easing.** { *; }
-keep interface com.daimajia.easing.* { *; }
-keep class com.daimajia.** { *; }
-dontwarn com.daimajia.**
-keepnames class com.daimajia.**
##########################
#        PDFVIEW         #
##########################
-keep class com.shockwave.**
##########################
#      DOWNLOADER        #
##########################
-keep class com.downloader.** {*;}
##########################
#       MY_FILES         #
##########################
-dontwarn com.app.app.data.model.**
-keep class com.app.app.data.model.** { *;}
-dontwarn com.app.app.utils.custom_view.**
-keep com.app.app.utils.custom_view.** { *;}

Show me error for line 88 and line 88 is -keep com.app.app.utils.custom_view.** { *;} !

How can i fix it?

答案1

得分: 0

根据错误提示,您在您的 ProGuard 规则中存在语法错误,即在关键字 keep 之后需要在提供名称之前指定类型。

在这种情况下,您漏掉了单词 class

只需将以下行进行更改:

-keep com.app.app.utils.custom_view.** { *;}

更改为:

-keep class com.app.app.utils.custom_view.** { *;}

有关自定义规则文件的更多信息,请阅读 ProGuard 手册

英文:

As the error specifies, you have a syntax error in your ProGuard rules which is after the keyword keep you need to specify the type before providing the name.

In this case you are missing the word class.

Just change the line

-keep com.app.app.utils.custom_view.** { *;}

to

-keep class com.app.app.utils.custom_view.** { *;}

For more information about customizing your rules file, read the ProGuard Manual.

huangapple
  • 本文由 发表于 2020年4月9日 18:44:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/61119348.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定