如何避免改型2 Android中请求头模型中的ProGuard混淆?
1.没有proguard,一切正常。启用Proguard时,所有 头部和身体模型变得模糊 2.2无法通过模型对象传递数据如何避免改型2 Android中请求头模型中的ProGuard混淆?,android,retrofit,retrofit2,android-webservice,Android,Retrofit,Retrofit2,Android Webservice,1.没有proguard,一切正常。启用Proguard时,所有 头部和身体模型变得模糊 2.2无法通过模型对象传递数据 D/OkHttp: Content-Type: application/json Content-Length: 80 {"a":{"a":"123","b":"***","c":"","d":"Data","f":"1.0"},"b":{"a":""}} --> END POST (80-byte body) 下面提到的Proguard规则已添加到我的代码中,但仍
D/OkHttp: Content-Type: application/json
Content-Length: 80
{"a":{"a":"123","b":"***","c":"","d":"Data","f":"1.0"},"b":{"a":""}}
--> END POST (80-byte body)
下面提到的Proguard规则已添加到我的代码中,但仍然存在相同的问题,请帮助我解决此问题
# Retrofit
-dontwarn retrofit2.**
-dontwarn org.codehaus.mojo.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepattributes *Annotation*
-keepattributes RuntimeVisibleAnnotations
-keepattributes RuntimeInvisibleAnnotations
-keepattributes RuntimeVisibleParameterAnnotations
-keepattributes RuntimeInvisibleParameterAnnotations
-keepattributes EnclosingMethod
-keepclasseswithmembers class * {
@retrofit2.* <methods>;
}
-keepclasseswithmembers interface * {
@retrofit2.* <methods>;
}
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on RoboVM on iOS. Will not be used at runtime.
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
-keepclassmembers class * {
*** get*();
void set*(***);
}
-keepattributes Signature
-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
使用以下命令
-keep class retrofit2.** { *; }
-keep class okhttp3.internal.** { *; }
-dontwarn okhttp3.internal.**
-dontwarn retrofit2.**
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
# Retrofit
-dontnote retrofit2.Platform # Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform$IOS$MainThreadExecutor # Platform used when running on RoboVM on iOS. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8 # Platform used when running on Java 8 VMs. Will not be used at runtime.
# OkHttp 3
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
-保持类2.*{*;}
-保持类okhttp3.internal.*{*;}
-dontwarn okhttp3.internal**
-dontwarn 2**
-keepclassswithmembers类*{
@2.http.*;
}
这对proguard有效
其他不需要的东西使用下面的方法
-keep class retrofit2.** { *; }
-keep class okhttp3.internal.** { *; }
-dontwarn okhttp3.internal.**
-dontwarn retrofit2.**
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
# Retrofit
-dontnote retrofit2.Platform # Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform$IOS$MainThreadExecutor # Platform used when running on RoboVM on iOS. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8 # Platform used when running on Java 8 VMs. Will not be used at runtime.
# OkHttp 3
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
启用proguard后,它将混淆所有请求参数。因此,要解决此问题,您必须在请求类中进行以下更改: 假设这是您的请求类:
class DemoRequest{
@SerializedName("name")//here this SerializedName will avoid obfuscate of variables
private String name;
.
.
.
}
希望它能帮助你。
谢谢假设您的包名为com.example.android,并且您的所有API请求模型类都位于名为“requests”的包中 然后将此行添加到应用程序模块的proguard中:
-keep class com.example.android.requests.** { *; }
将此行添加到可能具有请求模型的所有类似包中。这样这些类就不会被混淆
快乐编码 海,还是一样的问题海,还是一样的问题:-(