我有这些课程:
public class OfferList {
public List<Offer> offers;
}
public class Offer {
public String offer_id;
public String group_id;
public String n_hours;
public boolean is_new;
}
并定义了这项服务:
@Rest(rootUrl = "http://MYURL/json", converters = { GsonHttpMessageConverter.class })
//if defined, the url will be added as a prefix to every request
public interface EscolasPertoDeMimRESTService {
@Get("/offers/{user_id}/{date}")
@Accept(MediaType.APPLICATION_JSON)
OfferList getOffers(String user_id, long date);
}
这里叫做:
(...)
@RestService
OfferRestService offersService;
(...)
@Background
void loadListItems() {
mLoadingOffers = true;
showProgressDialog();
OfferList ol = null;
try {
ol = offersService.getOffers(myPrefs.userID().get(), myPrefs.lastCheckedForOffers().get());
showDebug("ol.offers.size(): " + ol.offers.size()); //OK shows ol.offers.size(): 24
Offer o = ol.offers.get(0); //After exporting: Crash
showDebug("ol.offers[0].group_id" + o.group_id);
} catch (Exception e) {
showDebug(e.getMessage()); //After exporting shows: "com.google.gson.internal.StringMap cannot be cast to com.humihara.escolaspertodemim.Offer"
}
setupAdapter(ol);
mLoadingOffers = false;
}
(...)
在调试中一切正常,但是当我导出并签名时,应用程序崩溃。
发送GET并且来自服务器的响应是有效的JSON商品列表。 显然,我得到的结果是带有StringMap的OfferList而不是Offer(s)。
这是我的proguard-project.txt(我使用的是android sdk默认加上这些):
-keep public class com.humihara.escolaspertodemim.** { *; }
-keep public class org.springframework.** { *; }
-keep public class com.google.gson.** { *; }
-keep public class com.google.ads.** { *; }
-keep public class com.androidannotations.** { *; }
-keep public class org.acra.** { *; }
-keep public class * extends android.support.v4.app.FragmentActivity
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet); }
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int); }
-dontwarn org.simpleframework.**
-dontnote org.simpleframework.**
-dontwarn org.codehaus.jackson.**
-dontnote org.codehaus.jackson.**
-dontwarn com.fasterxml.jackson.**
-dontnote com.fasterxml.jackson.**
-dontwarn com.google.code.rome.**
-dontnote com.google.code.rome.**
-dontwarn org.apache.commons.httpclient.**
-dontnote org.apache.commons.httpclient.**
我搜索了邮件列表和stackoverflow,在那里我获取了proguard的额外定义,但现在我不知道还能做什么。 有人可以告诉我我的代码或proguard-project.txt中必须更改哪些内容才能使其正常工作?
更新
检查Jackson Json parser returns nulls on all object members on Android after optimizing with Proguard
后我想我错过了:
-dontskipnonpubliclibraryclassmembers
默认的android proguard定义:
-dontskipnonpubliclibraryclasses
我并没有注意到他们的表情不一样。
我最终得到了这个proguard-project.txt:
-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault
-dontskipnonpubliclibraryclassmembers
-keep class com.humihara.escolaspertodemim.** { *; }
-keep public class * extends android.support.v4.app.FragmentActivity
-dontwarn org.simpleframework.**
-dontnote org.simpleframework.**
-dontwarn org.codehaus.jackson.**
-dontnote org.codehaus.jackson.**
-dontwarn com.fasterxml.jackson.**
-dontnote com.fasterxml.jackson.**
-dontwarn com.google.code.rome.**
-dontnote com.google.code.rome.**
-dontwarn org.apache.commons.httpclient.**
-dontnote org.apache.commons.httpclient.**
现在一切正常。
答案 0 :(得分:1)
对于使用反射来访问注释的代码,您应该保留注释:
-keepattributes *Annotation*