I use Retrofit2 , updated build.gradle after that the project stopped finding the HttpLoggingInterceptor . In the build.gradle section, the dependencies section now looks like this:

 compile 'com.squareup.retrofit2:retrofit:2.2.0' compile 'com.squareup.okhttp3:okhttp:3.6.0' compile 'com.squareup.okhttp3:logging-interceptor:3.6.0' 

What needs to be changed in build.gradle so that the project can find the HttpLoggingInterceptor ?

Code using the HttpLogginInterceptor :

  public BaseApi() { HeaderInterceptor headerInterceptor = new HeaderInterceptor(); HttpLoggingInterceptor logger = new HttpLoggingInterceptor(); logger.setLevel(HttpLoggingInterceptor.Level.BODY); client = new OkHttpClient.Builder() .connectTimeout(60, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS) .addInterceptor(logger) .addInterceptor(headerInterceptor) .build(); retrofit = new Retrofit.Builder() .baseUrl(BuildConfig.BASE_URL) .client(client) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build(); service = retrofit.create(MessengerApi.class); } 
  • @rjhdby The project throws an error when importing okhttp3.logging.HttpLoggingInterceptor; The loggin is highlighted in red. - Lucky_girl
  • @Lucky_girl, and if so try? compile('com.squareup.retrofit2:retrofit:2.1.0') { exclude module: 'okhttp' } - Yuriy SPb
  • @rjhdby Added code, by error I mean import error, project does not see okhttp3.logging.HttpLoggingInterceptor - Lucky_girl
  • @Yuriy SPb doesn't see this class anyway - Lucky_girl
  • 2
    @Lucky_girl then standard dances with a tambourine: Clean project, Invalidate caches / Restart, synchronization gradle - rjhdby

1 answer 1

Android Studio basically has IntelliJ IDEA, in which such situations periodically arise.

If suddenly the IDE has ceased to behave adequately, does not see the classes, does not want to arrange imports correctly - there are a number of actions that can bring her to life:

  1. File> Invalidate Caches / Restart. Usually this is enough.
  2. Build> Clean project. This helps when the IDE does not see the resources of R.*
  3. Occasionally it rescues the resynchronization of Gradle (very rarely, but it happened a couple of times)