android - 使用 API 28 和 "androidx.appcompat"库项目表示找不到 "AppCompatActivity"符号

标签 android android-studio gradle android-appcompat androidx

我将构建版本和目标版本更新为 28 (Pie) 并替换了相关依赖项。现在我的项目显示在 AppCompatActivity 上找不到 Symbol。我试过了

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

但结果是一样的。此外,当我在 Activity 类中的扩展关键字之后尝试 Ctrl+Space 时,没有 "AppCompatActivity 建议。我试图调查它是否存在于 libraries 文件夹,它就在那里。

enter image description here

现在,我应该怎么做才能让它发挥作用?如果 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 说

Compilation failed; see the compiler error output for details.

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

最佳答案

你应该替换目标类。

例如。

import android.support.v7.app.AppCompatActivity;

替换为:

import androidx.appcompat.app.AppCompatActivity;

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

相关文章:

android - 将Android Studio项目导入Intellij错误的gradle版本

Android Kotlin 从一个模块引用或导入库类到另一个模块

android - 我的应用仅使用存储权限,是否需要隐私政策?

android - 如何在 LazyVerticalGrid 中的项目之间显示水平和垂直分隔线?

android - 如何在 Android Studio 中修复 "Gradle error : Network is unreachable: connect "

android-studio - Android Studio 错误 : occurred starting process 'command '/home/private/Android/Sdk/ndk-bundle/toolchains/mips64el-linux-android-4. 9.. .''?

android - 如何将gradle项目转换为android项目

java - 在gradle中获取Android项目的classpath

javascript - Fit Screen Android WebApp(避免水平滚动)

android 如何修复 : method invocation 'getSystemService'