英文:
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.* <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.** { *;}
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论