Question

I have these classes:

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;
}

And defined this service:

@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);
}

Which is called here:

(...)
@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;
}
(...)

Everything works fine in debug, but when I export and sign, the app crashes.

The GET is sent and the response from the server is a valid JSON offer list. Apparently the result I get is an OfferList with StringMap(s) instead of Offer(s).

This is my proguard-project.txt (I'm using the android sdk defaults plus these):

-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.**

I have searched the mailing list plus stackoverflow where I picked up the extra definitions for proguard, but now I don't know what else to do. Can someone please tell me what I must change in my code or proguard-project.txt to make it work?

UPDATE:

After checking Jackson Json parser returns nulls on all object members on Android after optimizing with Proguard

I guess I was missing:

-dontskipnonpubliclibraryclassmembers

The default android proguard defines:

-dontskipnonpubliclibraryclasses

and I didn't noticed they aren't the same expression.

I ended up with this 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.**

And now everything works fine.

Était-ce utile?

La solution

For code that uses reflection to access annotations, you should preserve the annotations:

-keepattributes *Annotation*
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top