With API 28 and “androidx.appcompat” library project says “AppCompatActivity” symbol not found

天大地大妈咪最大 提交于 2020-02-26 12:05:01

问题


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

  • Clean project
  • Rebuild project
  • Invalidate Caches / Restart

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.

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'

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

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

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.


回答1:


you should replace the target class.

eg.

import android.support.v7.app.AppCompatActivity;

replace to :

import androidx.appcompat.app.AppCompatActivity;



回答2:


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

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.

Hope so it will help someone.




回答3:


Add Below lines in your gradle Properties:

android.useAndroidX=true android.enableJetifier=true

This will upgrade your project into Android X.



来源:https://stackoverflow.com/questions/53279989/with-api-28-and-androidx-appcompat-library-project-says-appcompatactivity-sy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!