添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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;
  • Do I need to add something in build.gradle?
  • I am using Android Studio 2021.1.1, is that the problem?
  • yeah deprecated, you can only use them if you have checked android.support when creating a project. and here are the equivalent artifacts name of android.support to androidx. – Suresh Chaudhari Apr 21, 2022 at 3:38

    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.

    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.

    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.

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.