With API 28 and "androidx.appcompat" library project says "AppCompatActivity" symbol not found
Solution 1
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.
Solution 2
you should replace the target class.
eg.
import android.support.v7.app.AppCompatActivity;
replace to :
import androidx.appcompat.app.AppCompatActivity;
Solution 3
Add Below lines in your gradle Properties:
android.useAndroidX=true android.enableJetifier=true
This will upgrade your project into Android X.
Inzimam Tariq IT
Since the start of my MSc. GIS 2nd semester(Feb 2014) when I started Java Programming as course work subject, I'm in love with this field. I was very passionate to do something in this area So I started to program with my keen interest. Till now I have worked for 3 companies And currently I'm working in Tech Maven Geospatial as Android Developer. You can follow me on Google+ https://plus.google.com/109309640886924591969 Twitter https://twitter.com/InzimamTariq Facebook https://www.facebook.com/inzimam.tariq
Updated on September 25, 2020Comments
-
Inzimam Tariq IT over 3 years
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 inlibraries
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 completebuild.gradle
fileapply 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
fileandroid: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.
-
Gene Bo almost 5 yearsThis solution fixes the issue, but does require the aforementioned gradle update:
api 'com.google.android.material:material:1.0.0'
. For those on Day-1 of AndroidX like myself - I didn't realize it is a critical detail listed in the original question, that is part of the solution. Thanks to: stackoverflow.com/a/53936857/2162226 -
Joshua Pinter over 3 yearsNote, this didn't fix all the occurrences in our application codebase. I had to manually build and track down all the remaining issues. Not sure why but just be aware it's not a silver bullet and there will likely be some manual intervention required.