JakeWharton / timber

A logger with a small, extensible API which provides utility on top of Android's normal Log class.

Home Page:https://jakewharton.github.io/timber/docs/5.x/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot resolve method 'plant(timber.log.Timber.DebugTree)'

findyourexit opened this issue · comments

commented
  • Android Studio version: Android Studio Bumblebee | 2021.1.1 Patch 1 (Build #AI-211.7628.21.2111.8139111)
  • Timber version: com.jakewharton.timber:timber:5.0.1

Reproduction steps:

  1. Simply add the above dependency to an Android project (ensuring to use Android Studio Bumblebee+)
  2. Observe the Cannot resolve method 'plant(timber.log.Timber.DebugTree)' Lint error message:

image

Additional notes:

  • Didn't seem to occur on prior version of Android Studio (Arctic Fox and prior).
  • Does seem to affect Android Studio Bumblebee (Stable), Chipmunk (Beta) and Dolphin (Canary).
  • Doesn't appear to occur with pre-5.0.0 versions of Timber.
  • Loosely related to this issue.
  • Could be an Android Studio bug rather than a bug with Timber, though I figured best to report it here as it doesn't seem to affect pre-5.0.0 versions of Timber as mentioned previously.
  • In case the issue is in fact with Android Studio, @gmk57 has reported it on Android Studio bug tracker.

If anybody could try to reproduce it in Intellij IDEA, that might me helpful. The issue may be neither in Timber nor in AS, but in Kotlin plugin, and in that case should be reported to JetBrains.

Are you calling from a Java or Kotlin source file?

This only happens when calling from Java.

Same issue too

Capture d’écran 2022-02-22 à 16 39 00

Convert Java File to Kotlin File can easily solve the problem.
image

commented

Convert Java File to Kotlin File can easily solve the problem. image

This is not a solution, this is a workaround.

This issue has also been discussed here.

@gmk57 has mentioned a ticket in the Android Studio bugtracker. The Google engineer noted that it could be an issue that Timber.plant() and Timber.DebugTree() resolve to different files:
Timber.plant get resolved to a binary .class while new Timber.DebugTree - to the sources, even if these 2 methods are in the same file. So it may be caused by the plugin itself or a way Android Studio attaches .aar libraries.

Probably also related to this bug in the kotlin plugin

Maybe this helps to find the cause of this issue?

Let's be clear that this is just false positive highlighting in IDEA, code compiles fine. Title/comments of this issue make it look like a more severe problem. It is not specific to Timber, it manifests with many other Kotlin-first libraries consumed in Java code.

The issue is related to IDEA Kotlin plugin:
https://youtrack.jetbrains.com/issue/KTIJ-19699/IDE-False-positive-type-mismatch-in-Java-code-for-Kotlin-nested-class-non-direct-inheritor-from-external-library

Currently in backlog for next IDEA release 2022.2.

Same problem, but we can wrap the initialization code with a Kotlin class.

The issue is related to IDEA Kotlin plugin: https://youtrack.jetbrains.com/issue/KTIJ-19699/IDE-False-positive-type-mismatch-in-Java-code-for-Kotlin-nested-class-non-direct-inheritor-from-external-library

So recently this issue had been marked as fixed, stating that compiling libraries with Kotlin compiler 1.8 resolves this (properly writes InnerClasses attribute, details in recent issue comments). It is discussed whether Idea may get a workaround for highlighting of libraries compiled with earlier versions.

Again, to reiterate, this only concerns usage of Kotlin libraries in Java code, and is not Timber-specific issue. So I think this issue can be closed.

For workaround solution to avoid annoying warning message every time we stay on our Java class and to avoid the class appear in red color as it might confused with the error, I think you can try with my answer here: https://stackoverflow.com/a/75388643/7257373

The issue is related to IDEA Kotlin plugin: https://youtrack.jetbrains.com/issue/KTIJ-19699/IDE-False-positive-type-mismatch-in-Java-code-for-Kotlin-nested-class-non-direct-inheritor-from-external-library

So recently this issue had been marked as fixed, stating that compiling libraries with Kotlin compiler 1.8 resolves this (properly writes InnerClasses attribute, details in recent issue comments). It is discussed whether Idea may get a workaround for highlighting of libraries compiled with earlier versions.

Again, to reiterate, this only concerns usage of Kotlin libraries in Java code, and is not Timber-specific issue. So I think this issue can be closed.

still would be awesome for timber to fix the issue - as stated in the google issue tracker, it needs compiled with a newer compiler to fix the issue. IntelliJ is hardly going to work around it themeselves.