这里博主分享下自己在Android Studio中遇到“Cannot resolve symbol ‘xxx’”的解决方法,希望对大家有所帮助。
1.将有问题的依赖注释掉(ctrl+/)
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation(name: 'lib-dds-1.2.6.1-release', ext: 'aar')
// implementation 'com.android.support:appcompat-v7:28.0.0'
// implementation 'com.google.android.exoplayer:exoplayer-core:2.6.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'
}
2.点击右上角的Sync Now
如果出现错误提示:
Android Studio and Gradle are using different locations for the JDK.
Android Studio: D:\Android Studio\jre
Gradle: C:\Program Files\Java\jdk-13.0.2
Using different JDK locations might cause Gradle to spawn multiple daemons
when executing tasks for Android Studio and other external processes.
More info…
Select a JDK from the File System
Do not show this warning again
大家可以去看我另一篇博文,Android Studio and Gradle are using different locations for the JDK.
3.等Android Studio完成gradle后,取消注释,再次点击Sync Now
还有第二种情况,Sync Now后依赖依旧出现飘红
出现此情况的原因之一就是,该依赖的代码中引用了另一个第三方架包,比如V4包,V7包,因此需要在项目中添加该依赖缺少的架包。
只需手动在其前面添加
//noinspection GradleCompatible
或者你可以选择该项依赖,shift+alt+enter自动添加其注释。
这样在添加//noinspection GradleCompatible,就不会出现红线了。