Search code examples
android-studiomobile-application

Cannot resolve R in Android Studio


I tried to clean,rebuild,sync gradle files... This is my gradle file

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

This also gives error


Solution

  • add above your dependencies

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

    and also you need to add these dependencies.

    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'
    

    and you are done.