我需要一些来自 Javascript 的项目,所以我使用 Gson 将 JSON 字符串转换为值,如下面的代码。
从 Java 脚本:
var Items = [{ "ItemName": "Item1", "ItemPos": "1", "ItemValue":"value1"},{ "ItemName": "Item2", "ItemPos": "2", "ItemValue":"value2"}];
调用原生 Android 方法,将这些值作为JSON.parse(items)传递。
在 Native 类中,我检索了这些值,如下所示,
List<Items> ItemsList;
Gson gson = new Gson();
ItemsList= gson.fromJson(args[0].toString(), new TypeToken<List<Items>>(){}.getType());
我已将 Item 类声明如下。
public class Items
{
public String Name;
public String Position;
public String Value;
}
这些实现方法在本机源代码中运行良好。但是在混淆了源代码之后,这些实现方法不起作用。我收到“查找失败”错误。在反编译混淆代码时,在“未找到匿名类”的地方不存在 Item 类。甚至List ItemsList 的声明也不存在。如何解决这个问题?
编辑 1:MyProguard.pro
-injars input.jar
-outjars output.jar
-libraryjars android.jar
-libraryjars android-support-v4.jar
-libraryjars annotations.jar
-libraryjars gson-2.2.1.jar
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-keepparameternames
-renamesourcefileattribute SourceFile
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
-keep public class * {
public protected *;
}
-keepclassmembernames class * {
java.lang.Class class$(java.lang.String);
java.lang.Class class$(java.lang.String, boolean);
}
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-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>;
}
我已经通过“ java -jar proguard.jar @MyProguard.pro ”混淆了源代码