Mahi
Mahi

Reputation: 1752

can't import android.support.v4.app notificationcompat in android studio?

I was learning android notification tutorial using this link but when I started using

 Notification notification = new NotificationCompat.Builder(this, App.CHANNEL_1_ID);

this code, I can't import android.support.v4.app. NotificationCompat , how to do that? It only imports

import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;

import android.app.Notification;

  1. Do I need to add something in build.gradle?
  2. I am using Android Studio 2021.1.1, is that the problem?

Upvotes: 0

Views: 7085

Answers (1)

Suresh Chaudhary
Suresh Chaudhary

Reputation: 698

androidx is new support library for the replacement v4.support library. And androidx is recommended. I suggest you to use search filter to find tutorial later than 2020~2021.

However you can still use v4.support library by checking "Use legacy android.support library" option while creating a project.

enter image description here

While this is not enough, because latest build tools will not support deprecated libraries, you have to keep compleSdkVersion 28 or below. You are also required to downgrade your Android Gradle Plugin to 3.6.4 and gradle wrapper to 6.0

Make sure these lines are not present in gradle.properties

android.useAndroidX=true
android.enableJetifier=true

Now you can follow the above tutorial.

Use

android.arch.core:core
android.arch.core:common

instead of 

androidx.arch.core:core-common
androidx.arch.core:core

Here is the full list of equivalent artifacts of support library to androidx

I do not recommend you to follow above tutorial find latest tutorial. Tech is rapidly changing, following an outdated tutorial might slow your learning process and keep you behind.

Upvotes: 1

Related Questions