JakeWharton / timber

A logger with a small, extensible API which provides utility on top of Android's normal Log class.
https://jakewharton.github.io/timber/docs/5.x/
Apache License 2.0
10.41k stars 959 forks source link

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

Closed findyourexit closed 1 year ago

findyourexit commented 2 years ago

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:

gmk57 commented 2 years ago

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.

JakeWharton commented 2 years ago

Are you calling from a Java or Kotlin source file?

gmk57 commented 2 years ago

This only happens when calling from Java.

NizarETH commented 2 years ago

Same issue too

Capture d’écran 2022-02-22 à 16 39 00
uvery9 commented 2 years ago

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

findyourexit commented 2 years ago

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

This is not a solution, this is a workaround.

niklasdahlheimer commented 2 years ago

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?

killvetrov commented 2 years ago

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.

Quyunshuo commented 2 years ago

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

killvetrov commented 1 year ago

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.

Chivorns commented 1 year ago

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

androidacy-user commented 1 year ago

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.