package androidx.appcompat.widget does not exist Android Studio

Reoxey :

I have created a custom Class which extends ImageView. It was working perfectly fine until AndroidX shows up.

Here, the java code

import android.content.Context;
import android.graphics.BitmapFactory;
import android.util.Base64;
import android.widget.RelativeLayout;

import androidx.appcompat.widget.AppCompatImageView;


public class CloseView extends AppCompatImageView {

    public CloseView(Context context) {
        super(context);
        init();
    }
...

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Android shows 2 errors for this file

  1. error: cannot find symbol class AppCompatImageView
  2. error: package androidx.appcompat.widget does not exist

Has anyone able to fix this issue?

S-Sh :

You should completely migrate to AndroidX to use its classes

  1. Enable AndroidX in Gradle settings:
android.useAndroidX=true
android.enableJetifier=true
  1. Replace dependencies
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

instead of

 implementation 'com.android.support:appcompat-v7:28.0.0'
 implementation 'com.android.support:support-v4:28.0.0'

See: https://developer.android.com/jetpack/androidx/migrate

Edit:

AndroidX is the newest replacement to all the previous numbered support libraries. Read more about it here before you start using it.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=309161&siteId=1