Retrofit 2 HTTP method annotation is required (e.g., @GET, @POST, etc.)

后端 未结 4 789
耶瑟儿~
耶瑟儿~ 2021-02-04 09:01

What\'s wrong with my Retrofit configuration? I\'m having this error when I\'m adding Basic Authentication with my OkHttpClient but when I used the default client without Interc

4条回答
  •  一个人的身影
    2021-02-04 09:32

    It look like you are using proguard and it is stripping annotations. To get saved from it add this lines to your proguard-rules.pro

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

    if not using proguard make sure that you havn't written something in your app build.gradle something like this

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    

    Note: Android does not come normally with many of the javax.annotation library by default.

    if it is not so then try adding this in your gradle dependency (build.gradle)

    provided 'org.glassfish:javax.annotation:10.0-b28'
    

提交回复
热议问题