我创建了一个自定义类,该类扩展了ImageView。直到出现AndroidX为止,它的工作情况都非常好。

在这里,java代码

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显示此文件2错误
  • 错误:找不到符号类AppCompatImageView
  • 错误:包androidx.appcompat.widget不存在

  • 有谁能解决这个问题?

    最佳答案

    您应该完全迁移到AndroidX以使用其类

  • 在Gradle设置中启用AndroidX:
  • android.useAndroidX=true
    android.enableJetifier=true
    
  • 替换依赖项
  • implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    

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

    另请:https://developer.android.com/jetpack/androidx/migrate

    编辑:

    AndroidX是所有以前编号的支持库的最新替代品。在开始使用它之前,请阅读有关它的更多信息here

    10-08 02:59