I use Log4J in a module of my Android application, which has to be Android agnostic, therefore I decided to use SLF4J Android implementation. But the problem is how to correctly configure the dependencies, so that the build will be successful, and I can reuse my non Android modules in other applications if I need to.
Asked
Active
Viewed 195 times
1 Answers
0
The solution was to add the following Gradle dependency in my non Android module.
implementation 'org.slf4j:slf4j-api:1.7.26'
In the Android module the SLF4J Android implementation should be added.
runtimeOnly 'org.slf4j:slf4j-android:1.7.26'

Vic
- 1,778
- 3
- 19
- 37
-
slf4j-android should be runtimeOnly. Anyway, my non-android unit-tests in src/test/java fail, because slf4j-android is in the test classpath, requiring android.util.Log, which is not in the runtime, since the tests are executed in a regular jvm. – Robin479 Aug 06 '19 at 17:49