通过ProGuard防止混淆类成员名称
我的班ClassMultiPoint
有子班。
public class ClassMultiPoints {
public String message;
public List<ClassPoints> data;
public class ClassPoints
{
public String id;
public List<ClassPoint> points;
public class ClassPoint
{
public String speed;
public String bearing;
}
}
}
我oPoints
将从解析中获得对象的价值GSON
:
oPoints = gson.fromJson( jsonString, ClassMultiPoints.class);
我尝试使用oPoints.message
。
当我运行我的应用程序而没有proguard
运行成功时。当proguard
我的应用崩溃时运行我的应用时。
我认为问题是:proguard
将'oPoints.message'
班级的属性重命名为short 'a'
。
我尝试保持方法和属性的名称不变,但是proguard
将其重命名:
proguard.cfg:
-injars bin/classes-injars libs
-outjars bin/classes-processed.jar
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-dontskipnonpubliclibraryclasses
-optimizationpasses 5
-printmapping map.txt
-flattenpackagehierarchy
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.MapActivity
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-libraryjars libs/commons-io-2.2.jar
-libraryjars libs/ftp4j-1.7.1.jar
-libraryjars libs/gson-2.2.2.jar
-keep public class org.apache.commons.io.**
-keep public class it.sauronsoftware.ftp4j.**
-keep public class com.google.gson.**
-keep public class com.mypackagename.ActivityMonitor$*
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.content.Context {
public void *(android.view.View);
public void *(android.view.MenuItem);
}
-keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
保留第一个(静态)类的方法和属性的名称的正确方法是什么?
回答:
感谢Waqas!
我为我的情况找到了解决方案:
-optimizationpasses 5-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt
-optimizations !code/simplification/arithmetic,!field/*,!class/merging*/
-allowaccessmodification
-repackageclasses ''
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.MapActivity
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-libraryjars libs/commons-io-2.2.jar
-libraryjars libs/gson-2.2.2.jar
-keep public class org.apache.commons.io.**
-keep public class com.google.gson.**
-keep public class com.google.gson.** {public private protected *;}
##---------------Begin: proguard configuration for Gson ----------
-keepattributes *Annotation*,Signature
-keep class com.mypackage.ActivityMonitor.ClassMultiPoints.** { *; }
-keep public class com.mypackage.ActivityMonitor$ClassMultiPoints { public protected *; }
-keep public class com.mypackage.ActivityMonitor$ClassMultiPoints$ClassPoints { public protected *; }
-keep public class com.mypackage.ActivityMonitor$ClassMultiPoints$ClassPoints$ClassPoint { public protected *; }
# To support Enum type of class members
-keepclassmembers enum * { *; }
##---------------End: proguard configuration for Gson ----------
另外,我不在@SerializedName("message")
课堂上使用,上述配置无需序列化即可正常工作。
以上是 通过ProGuard防止混淆类成员名称 的全部内容, 来源链接: utcz.com/qa/401913.html