真正解決方案:Cannot resolve symbol 'xxx' (Android Studio 3.1.4)
阿新 • • 發佈:2019-02-17
最近更新了Android Studio 到最新版本3.1.4,但是卻出現了一個問題,
Cannot resolve symbol ‘Theme’ in styles.xml (Android Studio)
Failed to load AppCompat ActionBar with unknown error.
Cannot resolve symbol ‘OkhttpUtils’
…
有時候會出現類似theme主題找不到,甚至AppCompatActivity 這個類也找不到,
更嚴重有時候引入的所有Github 上的類庫都找不到了,都快要吐血崩潰了。
好在經過 一番苦戰,終於摸清楚了脾氣,找到了終極解決方案。
終極解決方案:
1.哪個Jar包有問題就把該配置註釋掉,比如下面這個:
dependencies {
//implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
//implementation 'com.android.support:design:28.0.0-alpha3'
//implementation 'com.android.support:support-v4:28.0.0-alpha3'
//implementation 'com.android.support:recyclerview-v7:28.0.0-alpha3'
}
2.點選Sync Now
3.然後解開註釋
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support:design:28.0.0-alpha3'
implementation 'com.android.support:support-v4:28.0.0-alpha3'
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha3'
}
4.再點選Sync Now
5.問題解決.世界安好
其他解決方案一:
其他解決方案二:
其他解決方案三:
解決方案,修改版本
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
為
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
完整修改build.gradle內容如下:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:28.0.0-alpha1'
implementation 'com.android.support:support-v4:28.0.0-alpha1'
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha1'
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'
}
其他解決方案四:
也有可能是jar包因為網路原因沒下載更新好。。。
刪除這個資料夾下的所有jar,或者找到沒識別的jar刪除再重新下載
/Users/(使用者名稱)/.gradle/
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
其他解決方案五:
1.哪個Jar包有問題就把該配置註釋掉,比如下面這個:
dependencies {
//implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
//implementation 'com.android.support:design:28.0.0-alpha3'
//implementation 'com.android.support:support-v4:28.0.0-alpha3'
//implementation 'com.android.support:recyclerview-v7:28.0.0-alpha3'
}
2.點選Sync Now
3.然後解開註釋
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support:design:28.0.0-alpha3'
implementation 'com.android.support:support-v4:28.0.0-alpha3'
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha3'
}
4.再點選Sync Now
5.問題解決.世界安好