改造HTTP报告和QUOT; HTTP方法的注释是必需的"在斯卡拉美元的Andr​​oid C $Ç [英] Retrofit HTTP reporting "HTTP method annotation is required" in Scala code on Android

查看:277
本文介绍了改造HTTP报告和QUOT; HTTP方法的注释是必需的"在斯卡拉美元的Andr​​oid C $Ç的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行到一个问题,即改造库识别方法,但不是它的注解。它报告错误消息的标题之上。

(背景:我使用SBT与 SBT-Android的插件和改造1.6.1)

我的code是像这样:

 私人特质为MyService {
    @GET(/ API /测试)
    高清测试():可观察到的[任何]
}对象为MyService {
    私人VAL restAdapter =新RestAdapter.Builder()对setEndpoint(HTTP://某处)。.build()
    VAL服务= restAdapter.create(classOf [为MyService])    service.test()。认购(/ *你的想法* /)//这行标题抛出RuntimeException与上述消息
}

还有散落在GitHub上显然是从反应原理课程,例如一个非常相似的示例<一href=\"https://github.com/asarcar/functional_and_reactive_programming_course/blob/56964de0b687ee4907792a8c7ddc53002c4b7afe/ReactiveProgramming/class_examples/week4/build.sbt\"相对=nofollow>此处。我只想说,我的设置是一样的。

当我通过 RestMethodInfo.parseMethodAnnotations() requestMethod 变量确实为空,则<$ C步骤$ C>请求类型是简单。如果我添加了 @ FormUrlEn codeD 注释我的测试方法,在请求类型仍设置为简单的

在这可能是导致此任何想法?


解决方案

原来的Proguard被剥离的注释。

在此 GitHub的问题是有帮助的建议是:


  -keepattributes *注释*
-keep类改造** {*。 }
-keepclasseswithmembers类* {
@ retrofit.http *&lt;方法&GT ;; }
-keepattributes签名


和这个问题在本<一个也提到href=\"http://stackoverflow.com/questions/22288868/what-does-method-getresources-not-annotated-with-request-type-e-g-get-post\">SO帖子。

I'm running into an issue where the Retrofit library is recognizing the method but not its annotations. It's reporting the error message in the title above.

(Background: I'm using SBT with the sbt-android-plugin and Retrofit 1.6.1)

My code is like so:

private trait MyService {
    @GET("/api/test")
    def test(): Observable[Any]
}

object MyService {
    private val restAdapter = new RestAdapter.Builder().setEndpoint("http://somewhere").build()
    val service = restAdapter.create(classOf[MyService])

    service.test().subscribe(/* you get the idea */) // This line throws a RuntimeException with message in title above
}

There's a very similar example scattered around GitHub apparently from the Reactive principles course, e.g. here. Suffice it to say, my setup is the same.

When I step through RestMethodInfo.parseMethodAnnotations(), the requestMethod variable is indeed null, the requestType is SIMPLE. If I add the @FormUrlEncoded annotation to my test method, the requestType is still set to SIMPLE.

Any ideas on what could be causing this?

解决方案

Turns out Proguard was stripping the annotations.

The advice in this GitHub issue was helpful:

-keepattributes *Annotation*
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
@retrofit.http.* <methods>; }
-keepattributes Signature

And this issue is also mentioned in this SO post.

这篇关于改造HTTP报告和QUOT; HTTP方法的注释是必需的&QUOT;在斯卡拉美元的Andr​​oid C $Ç的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆