我将构建和目标版本更新为28(Pie),并替换了相关的依赖项。现在我的项目说在AppCompatActivity上找不到符号。我试图

  • 清洁项目
  • 重建项目
  • 使缓存无效/重新启动

  • 但是结果是一样的。而且,当我在 Activity 类中的extends关键字之后尝试Ctrl + Space时,没有"AppCompatActivity建议。我试图调查它是否存在于libraries文件夹中,是否存在于其中。

    android - 使用API​​ 28和 “androidx.appcompat”库项目时,找不到 “AppCompatActivity”符号-LMLPHP

    现在,我应该怎么做才能使其正常工作?如果androidx库有任何变化/替代,请告诉我。这是我完整的build.gradle文件
    apply plugin: 'com.android.application'
    apply plugin: 'com.google.gms.google-services'
    
    android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "com.invogen.messagingapp"
            minSdkVersion 16
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
    //    implementation 'com.android.support:appcompat-v7:28.0.0'
    //    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    //    implementation 'com.android.support:design:28.0.0'
    //    implementation 'com.android.support:support-v4:28.0.0'
    
        // Libs for newer API 28
        implementation 'androidx.appcompat:appcompat:1.0.2'
        implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
        implementation 'com.google.android.material:material:1.1.0-alpha01'
        implementation 'androidx.cardview:cardview:1.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'
    
        // Libs for Firebase Functionality
        implementation 'com.google.firebase:firebase-core:16.0.5'
    //    implementation 'com.google.firebase:firebase-database:16.0.4'
        implementation 'com.google.firebase:firebase-messaging:17.3.4'
        implementation 'com.google.firebase:firebase-auth:16.0.5'
        implementation 'com.google.firebase:firebase-storage:16.0.4'
    
        // Lib for Firebase UI Elements
        implementation 'com.firebaseui:firebase-ui-database:4.2.1'
    
        // Libs for QR Code
        implementation 'com.google.zxing:core:3.2.1'
        implementation 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
    
        // Lib for Circle Image View (Profile Image)
        implementation 'de.hdodenhof:circleimageview:2.2.0'
    
        // Lib for Loading Images
        implementation 'com.squareup.picasso:picasso:2.71828'
    
        //Lib for Cropping Images
        api 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
    
    
    }
    apply plugin: 'com.google.gms.google-services'
    

    其他一些文章建议在Manifest文件中添加以下两个参数
    android:appComponentFactory="anystrings be placeholder"
    tools:replace="android:appComponentFactory"
    

    但是由于这两行项目同步出现多个错误,Android Studio说



    如果我必须在问题上添加更多详细信息,请告诉我。

    最佳答案

    您应该替换目标类。

    例如。

    import android.support.v7.app.AppCompatActivity;
    

    替换为:
    import androidx.appcompat.app.AppCompatActivity;
    

    关于android - 使用API​​ 28和 “androidx.appcompat”库项目时,找不到 “AppCompatActivity”符号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53279989/

    10-11 22:23
    查看更多