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

Inzimam Tariq IT picture Inzimam Tariq IT · Nov 13, 2018 · Viewed 28.1k times · Source

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.

enter image description here

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.

Answer

iamcxl picture iamcxl · Jan 29, 2019

you should replace the target class.

eg.

import android.support.v7.app.AppCompatActivity;

replace to :

import androidx.appcompat.app.AppCompatActivity;