真正解决方案:Cannot resolve symbol 'xxx' (Android Studio 3.1.4)

最近更新了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.问题解决.世界安好


其他解决方案一:

真正解决方案:Cannot resolve symbol 'xxx' (Android Studio 3.1.4)_第1张图片

真正解决方案:Cannot resolve symbol 'xxx' (Android Studio 3.1.4)_第2张图片

其他解决方案二:

真正解决方案:Cannot resolve symbol 'xxx' (Android Studio 3.1.4)_第3张图片

其他解决方案三:

真正解决方案:Cannot resolve symbol 'xxx' (Android Studio 3.1.4)_第4张图片
解决方案,修改版本

 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'
}

参考地址:After Updating Android studio to 3.1.2 , I get “Failed to load AppCompat ActionBar with unknown error. ”

其他解决方案四:

也有可能是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.问题解决.世界安好

你可能感兴趣的:(Android,StackOverflow)