使用 API 28 和“androidx.appcompat"图书馆项目说“AppCompatActivity"未找到符号 [英] With API 28 and "androidx.appcompat" library project says "AppCompatActivity" symbol not found

查看:46
本文介绍了使用 API 28 和“androidx.appcompat"图书馆项目说“AppCompatActivity"未找到符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I updated my build and target version to 28 (Pie) and replaced the relevant dependencies. Now my project says Symbol not found on AppCompatActivity. I have tried to

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

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

But the result is the same. Moreover when I try Ctrl+Space after extends keyword in activity class there is no "AppCompatActivity suggestion. I tried to investigate if its present in libraries folder, it's present there.

现在,我该怎么做才能让它发挥作用?如果 androidx 库有任何变化/替代,请告诉我.这是我完整的 build.gradle 文件

Now, what should I do to make it work? If there is any variation/alternative with androidx libs please let me know. Here is my complete build.gradle file

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 文件中添加以下两个参数

Some other posts suggest adding the below two parameters in Manifest file

android:appComponentFactory="anystrings be placeholder"
tools:replace="android:appComponentFactory"

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

But with these two lines project sync with multiple error and Android Studio says

编译失败;详情请参阅编译器错误输出.

Compilation failed; see the compiler error output for details.

如果我必须在问题中添加更多细节,请告诉我.

If I have to add more detail to the question please let me know.

推荐答案

现在您可以轻松地将您的项目迁移到 androidx,只需点击 Refactor =>从菜单栏迁移到 Androidx.

Now you can easily migrate your project to androidx, Just click Refactor => Migrate to Androidx from menubar.

以前我是这样做的.
使用 Clean and buildRebuild project android studio 没有清理未使用的导入,比如从 android.support.v7 导入,所以我手动删除了它们从所有活动中.现在 android studio 从正确的库 androidx.appcompat 中建议 AppCompatActivity.

Previously I did as follow.
With Clean and build and Rebuild project android studio did not clean the unused imports like imports from android.support.v7 so I removed them all manually from all activities. Now android studio suggests AppCompatActivity from the correct library androidx.appcompat.

希望它会帮助某人.

这篇关于使用 API 28 和“androidx.appcompat"图书馆项目说“AppCompatActivity"未找到符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆