1

I have this code snippet for my local notifications to work on Oreo devices.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    NotificationChannel channel = new NotificationChannel(CHANNEL_ID, 
            CHANNEL_NAME,
            level);

    manager.createNotificationChannel(channel);
}

On my window desktop this is fine, no issues. However on my macbook, lint complains about NotificationChannel requiring SDK 26 and my min is 21. However if I change the version check to

if (Build.VERSION.SDK_INT >= 26) 

the error goes away. I've tried restarting Android studio, clean/rebuild. Nothing works. When I do code inspection and use the suggested hints, its changing the Version_Code to 26. Its kinda bothering me having it act different on my 2 machines but same exact code. Anyone else seen this issue before?

compileSdkVersion = 26
buildToolsVersion = "26.0.2"

minSdkVersion = 21
targetSdkVersion = 26
Le2e410
  • 323
  • 4
  • 18
  • did you set targetSdkVersion and if you set what is it – sanemars Apr 27 '18 at 02:48
  • Same question as above but for your compileSdkVersion, which needs to be [at least 26](https://developer.android.com/reference/android/os/Build.VERSION_CODES#O) for this field to be available to you. – stkent Apr 27 '18 at 04:19
  • I added my gradle statements. Theyre the same on both computers, only the mac complains. – Le2e410 Apr 27 '18 at 11:52
  • I reinstalled android studio and the error went away. I think the version number had something to do with it. It was on 2.3.1. – Le2e410 Apr 28 '18 at 01:37
  • Possible duplicate of [Android Studio 3.1: Erroneous unresolved references in editor](https://stackoverflow.com/questions/49545037/android-studio-3-1-erroneous-unresolved-references-in-editor) – fireb86 Nov 05 '18 at 11:08

2 Answers2

0

Same problem with android studio 3.2.1 after I switched from an old project to another. Very annoying. I solved with these steps:

  • Delete {projectDir}/.idea/libraries folder
  • File -> Sync Project with Gradle Files
  • File -> Sync Project with File System
fireb86
  • 1,723
  • 21
  • 35
0

Oreo is android 8.
Instead your code, using below code:

if (Build.VERSION.SDK_INT >= 26) {
    NotificationChannel channel = new NotificationChannel(CHANNEL_ID, 
            CHANNEL_NAME,
            level);
    manager.createNotificationChannel(channel);
}
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68