What does getResources method mean, not annotated with request type (for example, GET, POST)?

private interface ResourcesApi {
        @POST("/synchronize")
        void getResources(@Body Map<String, Map<String, Object>> map,
                          Callback<DataModel> callback);
    }

with call code:

mApi.getResources(data, this);

The class implements a callback to determine success / failure.

Stacktrace:

03-09 18:05:15.182  28570-28746/? E/AndroidRuntime﹕ FATAL EXCEPTION: pool-2-thread-1
    java.lang.IllegalStateException: Method getResources not annotated with request type (e.g., GET, POST).
            at retrofit.RestMethodInfo.parseMethodAnnotations(RestMethodInfo.java:179)
            at retrofit.RestMethodInfo.init(RestMethodInfo.java:115)
            at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:327)
            at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:262)
            at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:313)
            at retrofit.CallbackRunnable.run(CallbackRunnable.java:38)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
            at java.lang.Thread.run(Thread.java:856)
+4
source share
3 answers

This means that the annotation @POSTcannot be found at run time. Without the type of the HTTP method (and the relative URL that it contains), Retrofit cannot complete the request.

Do you use Proguard or another tool to trim "unused" code? If so, ask him to keep the Retrofit annotations.

+5
source

, , proguard, :

-keep class com.google.gson.** { *; }
-keep class com.google.inject.** { *; }
-keep class org.apache.http.** { *; }
-keep class org.apache.james.mime4j.** { *; }
-keep class javax.inject.** { *; }
-keep class retrofit.** { *; }
+5

Agree with @chad's answer, add below lines if you still get a failure.

-keepattributes Signature
-keep class sun.misc.Unsafe { *; }
0
source

Source: https://habr.com/ru/post/1530879/


All Articles