GSON

2013-05-15 8 views
7

का उपयोग करते समय प्रोगार्ड समस्या मैं अपने आवेदन में जीसन का उपयोग कर रहा हूं और इसके लिए, मैं जेसन का उपयोग करने वाले नाम के साथ कुछ कक्षाओं का उपयोग कर रहा हूं। मेरा आवेदन अच्छी तरह से काम करता है, लेकिन प्रोगार्ड लिखते समय, एप्लिकेशन दुर्घटनाग्रस्त हो जाता है, मुझे लगता है कि कुछ कक्षाएं घट रही हैं। मेरी त्रुटि है:GSON

java.lang.ClassCastException: com.google.gson.internal.StringMap com.sample.package.GsonClass

+0

इस ProGuard त्रुटि लगता नहीं है ... –

+0

मैं बाहर ProGuard साथ इसे करने की कोशिश, और यह सिर करने के लिए अच्छी तरह से काम करता है – Jithu

उत्तर

18

में ढाला नहीं जा सकता है आप के लिए इन पंक्तियों को जोड़ने की आवश्यकता अपने ProGuard ताकि gson वर्ग अपने अनुप्रयोग साइन इन करते समय रखा जाता है ..

##---------------Begin: proguard configuration for Gson ---------- 
# Gson uses generic type information stored in a class file when working with fields. Proguard 
# removes such information by default, so configure it to keep all of it. 
-keepattributes Signature 


# Gson specific classes 
-keep class sun.misc.Unsafe { *; } 
#-keep class com.google.gson.stream.** { *; } 

# Application classes that will be serialized/deserialized over Gson 
-keep class com.google.gson.examples.android.model.** { *; } 

##---------------End: proguard configuration for Gson ---------- 
+1

यहाँ लिंक है उस फ़ाइल का संशोधन: http://code.google.com/p/google-gson/source/browse/trunk/examples/android-proguard-example/proguard.cfg –

+1

-keep class com.google.gson.examples। android.model। ** {*; } यह मेरे लिए काम करता है लेकिन जब मैंने एपीके पर रिवर्स इंजीनियरिंग लगाया, तो मुझे सदस्यों में बदलाव के साथ सभी मॉडल वर्ग नहीं मिला, यह सुरक्षा उद्देश्य तोड़ता है, क्या कोई अन्य विकल्प नहीं है, हम मॉडल को भी खराब कर सकते हैं? – umesh

+1

मुझे भी '-keepattributes * एनोटेशन * ' –

1

एक अन्य कारण है: उपयोग करने से पहले

List<T> list = gson.fromJson(jsonString, type); 

आप इस तरह, सही typeToken निर्माण करना चाहिए:

Type type = new TypeToken<List<T>>(){}.getType(); 
List<T> list = gson.fromJson(jsonString,type)