2

I had a usecase so I have added retrofit library to use it locally in libs folder

You can see the package structure and error in the image below when trying to import Timber android libary.

enter image description here

In the app/build.gradle file, I have added dependency:

    implementation 'com.jakewharton.timber:timber:4.7.1'

In the libs/retrofit/build.gradle file, there also I added dependency:

  // I also tried using api instead of implementation

  implementation 'com.jakewharton.timber:timber:4.7.1'

Now, I synced, did invalidate cache and restart, clean, rebuild project.

Then tried to use Timber.d("some log") call in one of the files in libs/retrofit directory.

It resulted in error:

Add library: 'Gradle com.jakewharton.timber:timber:4.7.1@aar' to Classpath 

Note, the Timber.d("other log") works fine in one of the files in app directory, example app/MainActivity.kt

What I am doing wrong?

Also, to note Retrofit code works perfectly fine in app module. The issue is using a Timber logging library is not working in any of the modules in libs

dsf
  • 1,203
  • 1
  • 6
  • 11

2 Answers2

0

In my opinion, the answer lies in the question asked in this thread itself.

What happened, is that when I went through this situation myself, I saw this thread in the Google Search results.

After adding the dependency, for example:-

implementation 'com.jakewharton.timber:timber:4.7.1'

and thereafter syncing, I saw that it was merely a page refresh issue.

That is I switched to another source file which was opened in another tab and came back to this in which the following code was issued (the place of the aforesaid error):-

Timber.tag(...).e(...)

Timber usage.

Abhinav Saxena
  • 1,990
  • 2
  • 24
  • 55
0

Timber is packaged as an AAR file, that means it can only be used in android modules of your project.

The solution would be to convert your kotlin module to an android module by applying the plugins below in your build.gradle file of that module

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
Francis S
  • 138
  • 1
  • 7