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.
我今天将Android Studio升级到3.1,现在Android Studio说它无法解析大多数资源的符号(例如styles.xml中的ThemeOverlay或?attr / actionBarSize)。到目前为止,这似乎并没有阻止我在模拟器中构建或运行,但这些错误让我感到紧张。
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.
还有其他人遇到过这个问题吗?我怎样才能解决它?我尝试过同步gradle和清理我的项目,但它似乎没有任何帮助。
Any ideas?
有任何想法吗?
I'm using Android Studio 3.1 with Gradle version 4.4 and Gradle Plugin 3.1.0
我正在使用带有Gradle版本4.4和Gradle Plugin 3.1.0的Android Studio 3.1
EDIT: This issue affects updating to Android Studio 3.1.1, 3.1.2, 3.1.3 as well as Gradle Plugin to 3.1.1, 3.1.2 and 3.1.3. However, the answer below still works.
编辑:此问题影响到Android Studio 3.1.1,3.1.2,3.1.3以及Gradle Plugin到3.1.1,3.1.2和3.1.3的更新。但是,下面的答案仍然有效。
9 个解决方案
#1
118
Close the project and import it again. Worked for me today.
关闭项目并再次导入。今天为我工作。
#2
18
Close and reopen project as existing Android Studio project
关闭并重新打开项目作为现有的Android Studio项目
#3
#4
2
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
出于某种原因,在26个库中找不到这些属性。为了增加这些库,你还必须将compileSdk增加到27.很可能你还需要下载sdk 27
Short version, following goes on the app `graddle``
简短版本,继续应用程序`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
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)
build.gradle(项目)
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)
最后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'
}
#5
2
Closing a project and then opening as existing one does wonders!
关闭一个项目,然后打开现有的项目确实很奇怪!
#6
1
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!
您可以尝试关闭项目并退出Android Studio(仅关闭并重新导入它不会为我执行此操作)。启动Android Studio并再次打开该项目。这对我有用!
#7
1
I closed and reopened project as existing Android Studio project (did not import it), and it worked! Thanks to Andrew Glukhoff 's comment.
我关闭并重新打开项目作为现有的Android Studio项目(没有导入它),它工作了!感谢Andrew Glukhoff的评论。
#8
0
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
- 打开app模块的build.gradle文件
-
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.
使用gradle同步项目。你现在会有一些错误。别担心。
-
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.
再次使用gradle同步项目。
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.
- 如果您的项目有多个模块,那么您需要一次按照上面的说明操作所有模块。
#9
0
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)
使用build.gradle(project)中的上述内容更新依赖项
and put the below code in build.gradle(Module:app)
并将以下代码放在build.gradle中(模块: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'
#1
118
Close the project and import it again. Worked for me today.
关闭项目并再次导入。今天为我工作。
#2
18
Close and reopen project as existing Android Studio project
关闭并重新打开项目作为现有的Android Studio项目
#3
4
After upgrading Android Studio you can invalidate caché and restart
升级Android Studio后,您可以使caché无效并重新启动
File
> Invalidate Cache / Restart
文件>无效缓存/重新启动
#4
2
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
出于某种原因,在26个库中找不到这些属性。为了增加这些库,你还必须将compileSdk增加到27.很可能你还需要下载sdk 27
Short version, following goes on the app `graddle``
简短版本,继续应用程序`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
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)
build.gradle(项目)
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)
最后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'
}
#5
2
Closing a project and then opening as existing one does wonders!
关闭一个项目,然后打开现有的项目确实很奇怪!
#6
1
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!
您可以尝试关闭项目并退出Android Studio(仅关闭并重新导入它不会为我执行此操作)。启动Android Studio并再次打开该项目。这对我有用!
#7
1
I closed and reopened project as existing Android Studio project (did not import it), and it worked! Thanks to Andrew Glukhoff 's comment.
我关闭并重新打开项目作为现有的Android Studio项目(没有导入它),它工作了!感谢Andrew Glukhoff的评论。
#8
0
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
- 打开app模块的build.gradle文件
-
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.
使用gradle同步项目。你现在会有一些错误。别担心。
-
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.
再次使用gradle同步项目。
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.
- 如果您的项目有多个模块,那么您需要一次按照上面的说明操作所有模块。
#9
0
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)
使用build.gradle(project)中的上述内容更新依赖项
and put the below code in build.gradle(Module:app)
并将以下代码放在build.gradle中(模块: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'