3

I am working on a Kotlin+Java hybrid project.

The Gradle version and plugin were recently upgraded to 3.1.3 and 4.4 respectively.

Now while compiling, I am getting an error of 'unresolved reference' in a few of the Kotlin files.

Eg. -

return when (item?.itemId) {
        android.R.id.home -> {
            finish()
            true
        }
        else -> super.onOptionsItemSelected(item)
    }

In the above code getting compilation error in android.R.id.home as unresolved reference.

Also in

root_low_rating_nps.viewTreeObserver.removeOnGlobalLayoutListener(keyboardLayoutListener)

Getting the 'unresolved reference' error in finding 'removeOnGlobalLayoutListener'

I have been stuck on this for 5 days.

Tried moving the Kotlin buildscript dependencies in the app module's build.gradle, invalidate caches and restart, refresh, deleting .idea/ folder.

Can anyone help resolve this issue?

Thanks

4
  • Does the same happen when building from the command line? For example, if you run ./gradlew assembleDebug. Commented Jul 23, 2018 at 9:52
  • @zsmb13 Yes. Same error. Commented Jul 23, 2018 at 9:56
  • I've hit with a similar issue too and worked around it by wrapping the unresolved class in a java class and using that java class in my Kotlin code… Now I'm hitting it again somewhere else… this is quite annoying… maybe downgrading Kotlin fixes it? Commented Jul 31, 2018 at 10:29
  • @CarlosFonseca Did you try the accepted solution(updating libraries)? Commented Aug 6, 2018 at 8:29

1 Answer 1

2

I was able to find a solution for this.

Turns out, (and I don't know the reason why), but after upgrading the Gradle version and Kotlin plugin, the older version of a library was causing some kind of interference. I updated

com.birbit:android-priority-jobqueue:1.3

to

com.birbit:android-priority-jobqueue:2.0.1

which was the latest available version and the issue was resolved.

If anyone else runs into this issue, try updating all your dependencies to the latest version.

And if anyone identifies the actual reason for this, please let me know as well.

Thanks

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.