2017-07-10 1 views
0

Je crée une rénovation simple, mais je reçois cette erreur:Android Rénovation ne peut pas résoudre le symbole AuthenticationInterceptor

Cannot resolve symbol AuthenticationInterceptor

ici:

public static <S> S createService(
     Class<S> serviceClass, final String authToken) { 
    if (!TextUtils.isEmpty(authToken)) { 
     AuthenticationInterceptor interceptor = 
       new AuthenticationInterceptor(authToken); 

     if (!httpClient.interceptors().contains(interceptor)) { 
      httpClient.addInterceptor(interceptor); 

      builder.client(httpClient.build()); 
      retrofit = builder.build(); 
     } 
    } 

    return retrofit.create(serviceClass); 
} 

Mon build gradle ressemble à ceci:

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile 'com.android.support:appcompat-v7:25.3.1' 
    compile 'com.keiferstone:nonet:2.0.4' 
    compile 'com.github.GrenderG:Toasty:1.2.5' 
    compile 'com.lmntrx.livin.library.droidawesome:droid-awesome:1.1.9' 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support.constraint:constraint-layout:1.0.2' 
    compile 'me.pushy:sdk:1.0.28' 
    compile 'com.squareup.retrofit2:retrofit:2.3.0' 
    compile 'com.google.code.gson:gson:2.6.2' 
    compile 'com.squareup.retrofit2:converter-gson:2.0.2' 
} 

Répondre

2

Il semble que vous ayez utilisé this example

Dans les commentaires:

I use retrofit 2 but AuthenticationInterceptor is in red color and when i put the cursor on i have message like Cannot resolve symbol 'AuthenticationInterceptor '

Réponse:

to be honest, the AuthenticationInterceptor is a custom Interceptor implementation. I'll update the code snippet asap to include this class.

Ajouter dans votre code, il devrait être ok:

public class AuthenticationInterceptor implements Interceptor { 

    private String authToken; 

    public AuthenticationInterceptor(String token) { 
     this.authToken = token; 
    } 

    @Override 
    public Response intercept(Chain chain) throws IOException { 
     Request original = chain.request(); 

     Request.Builder builder = original.newBuilder() 
       .header("Authorization", authToken); 

     Request request = builder.build(); 
     return chain.proceed(request); 
    } 
} 
+0

Bonjour je devais changer une partie de votre code à ce 'public okhttp3.Response intercept (Chaîne de chaîne) jette IOException {', maintenant je reçois moins d'erreurs, il ne peut pas résoudre le symbole retrofit ici 'retrofit = builder.build();' – Olipol

+0

Ainsi j'utilise ce tutoriel https://futurestud.io/tutorials/oauth-2-on-android-with-retrofit – Olipol

+0

Il est défini ci-dessus, dans votre lien: 'privé statique Retrofit retrofit = builder.build();' – ToYonos