Getting unresolved reference on Android S - Kotlin
Asked Answered
B

1

6

I'm trying to use new Notification API setForegroundServiceBehavior. However, when trying to create a build I'm getting an unresolved reference I believe in Android S in general. (I'm working on a different project using Java and there seems to be no problem.)

    val builder = Notification.Builder(this, CH_ID)
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
        builder.setForegroundServiceBehavior(Notification.FOREGROUND_SERVICE_IMMEDIATE);
    }

Errors:

Unresolved reference: S
Unresolved reference: setForegroundServiceBehavior
Unresolved reference: FOREGROUND_SERVICE_IMMEDIATE

Gradle:

compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
    ...
    minSdkVersion 28
    targetSdkVersion 31
Barnett answered 28/1, 2022 at 13:17 Comment(7)
Don't know if it has anything to do with it, but I think it's recommended to use buildToolsVersion that is the same as compileSdkVersion . Maybe try "31.0.0" thereSelfaddressed
Tried changing buildToolsVersion to "31.0.0" but issue is still occurring.Barnett
Try 1. syncing project with grade files 2. Invalidate cache and restart.Aubade
no error am facing above code. may be check with invalidate cache and restart android studio will helpsBookshelf
@Barnett did you try?Aubade
As it turned out this was a problem caused by an outdated framework.jar being used in the project. Since it has higher priority during build time, the change in sdk is being overwritten/ignored.Barnett
how did you resolved this? I'm getting same issue.Baptism
E
2

Update you buildToolsVersion to “32.0.0” and compileSdkVersion and targetSdkVersion to 32. Or newer versions.

Edgewise answered 18/2, 2022 at 1:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.