I upgraded Android Studio today to 3.1, and now Android Studio says it cannot resolve symbols for most of the resources (for example ThemeOverlay
in styles.xml
or ?attr/actionBarSize
). This doesn't seem to prevent me from building or running in an emulator so far, but these errors are making me nervous.
Has anyone else experienced this issue? How can I go about resolving it? I have tried syncing gradle and cleaning my project but it doesn't seem to help at all.
Any ideas?
I'm using Android Studio 3.1 with Gradle version 4.4 and Gradle Plugin 3.1.0
EDIT: This issue affects updating to Android Studio 3.1.1, 3.1.2, 3.1.3, 3.1.4 as well as Gradle Plugin to 3.1.1, 3.1.2, 3.1.3, and 3.1.4. However, the answer below still works.
Close the project and import it again. Worked for me today.
Close and reopen project as existing Android Studio project
The support library is out of sync.
This error happens because the support library gets out of sync with your project. To get it back in sync you can do the following steps:
- Open your app module's build.gradle file
Comment out the
implementation
lines for the support library. For me it looks like this://implementation 'com.android.support:appcompat-v7:27.1.1' //implementation 'com.android.support:recyclerview-v7:27.1.1' //implementation 'com.android.support.constraint:constraint-la
Sync your project with gradle. You will have some errors now. Don't worry about that.
Uncomment the
implementation
lines that you previously commented out.implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:recyclerview-v7:27.1.1' implementation 'com.android.support.constraint:constraint-la
Sync your project with gradle again.
The "Cannot Resolve Symbol" error should be gone now. This has worked for me several times on different projects.
Note
- If your project has multiple modules, then you need to follow the directions above for all of the modules at once.
For some reason, those attributes are not found anymore in the 26 libraries. For increasing those libraries you have to also increase your compileSdk
to 27.
It is probable you will also have to download the sdk 27
Short version, following goes on the app `graddle``
android {
compileSdkVersion 27
//...
}
dependencies {
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'
//...
}
Long version, check all following files:
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
build.gradle (Project)
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And finally build.gradle (app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "cl.cutiko.testingupdate"
minSdkVersion 21
targetSdkVersion 27
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:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:27.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Closing a project and then opening as existing one does wonders!
You can try to close the project and exit Android Studio (only closing and reimporting it didn't do it for me). Launch Android Studio and open the project again. That worked for me!
I closed and reopened project as existing Android Studio project (did not import it), and it worked! Thanks to Andrew Glukhoff 's comment.
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:26.1.0'
update your dependencies with the above in build.gradle(project)
and put the below code in build.gradle(Module:app)
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'io.realm:realm-gradle-plugin:3.7.1'
classpath 'com.google.gms:google-services:3.1.0'
For me the same symptom/error was caused by dragging and dropping a new image into 'drawable-xxhdpi' folder with a name Android Studio did not like - for example with a number or capital in the name.
No useful error message was given just the 'cannot resolve symbol R' message.
Even after synching the app and cleaning and rebuilding project, the issue remained that 'R' was not recognised with no other error indicated.
Closing and importing the project as suggested in other answers did not work, which makes sense given the root problem.
However, even though it appears this has not worked for others in the past, judging by other questions and answers on SO, deleting the new image from the drawable folder did work.
Similarly, and a better solution, obviously, renaming the image to remove any characters that Android does not like in resource names and then doing a clean and/or rebuild project also worked.
Problem #1
My problem was related with how I used an alpha/beta version of Android Plugin
File > Project Structure > Project
check your Android Plugin Version
I was using something called 3.3.0-beta
, and yet in another project 3.1.0-alpha
changing it to 3.2.0
seems to clear up my issue, don't forget to change the one in build.gradle(Project) too
Problem #2
I had an error in one of my .xml files. I missed a @string
resource. Please check all your xml files, and make sure they are all correct (opening an xml file should activate Android Studio linting, scroll through the file, it should complain in red if something is wrong)
Problem #3
In build.gradle
I imported different versions of the android support libraries. e.g.
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:27.1.0'
Please make sure they are the same version. And make sure that Android Studio doesn't complain anything inside your gradle
dependencies. It might be that some of your dependencies also imported different android support library versions.
Steps to take after #1, #2 and #3
Clean your project Build > Clean Project
Invalidate cache and restart File > Invalidate Caches / Restart
After restart, wait for gradle build to finish, then voila!
I updated my gradle version to 4.10.1 and did "fix and reimport". There were no libraries folder under .idea before. And then it worked
Similar error for me when I update to com.android.tools.build:gradle 3.3.1
and gradle-4.10.1
I have tried the following method but didn't work:
Clean Project
-Rebuild Project
Invalidate Caches / Restart
- Check
.xml
error (I didn't find any errors about xml ) - Modify
.iml
file
I fix this error by modify com.android.tools.build:gradle 3.2.1
and Restart my mac
, I didn't know which one can fix it, but it really work for me .
Example
setContentView(R.layout.activity_login_ativity);
- Put the cursor in R
- Click Alt+Enter
- Choose import class R
Work for me :)
来源:https://stackoverflow.com/questions/49523302/android-studio-3-1-cannot-resolve-symbol-themes-widget-attr-etc