无法在 Android Studio 中解析 R

Cannot resolve R in Android Studio

我尝试清理、重建、同步 gradle 文件... 这是我的 gradle 文件

apply plugin: 'com.android.application'

android { compileSdkVersion 21 buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "com.example.user.myapplication"
    minSdkVersion 14
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
} }

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:26.0.0-alpha1' }

这也会报错

在你的依赖之上添加

configurations.all {
    resolutionStrategy.force 'com.android.support:support-annotations:23.1.0'
}

并且您还需要添加这些依赖项。

androidTestCompile 'com.android.support:support-annotations:23.1.0'
    androidTestCompile 'com.android.support.test:runner:0.4.1'
    androidTestCompile 'com.android.support.test:rules:0.4.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.1'

大功告成。