8

I've gone through the tutorial here and everything works except for my build.gradle. Everything in the 'android' section is is underlined and displays a "Cannot resolve symbol" error message. This is in Android Studio 0.3.1. I've even tried re-installing Android Studio and it still doesn't work.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 18
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
}
jd50
  • 235
  • 2
  • 3
  • 6
  • Looks alright to me. I didn't have much luck with Android Studio 0.3.1. You might want to try [the latest Android Studio](http://tools.android.com/download/studio/canary/latest) (currently 0.3.2). – anon Nov 05 '13 at 04:53
  • You should use 0.3.2 if you would like to work with sdk 19 – Gabriele Mariotti Nov 06 '13 at 10:22
  • Thanks, I actually upgraded to 0.3.2, unfortunately it didn't fix my problem. – jd50 Nov 06 '13 at 14:32
  • Had the same problem and fixed with the answer on this SO post http://stackoverflow.com/a/30828772/1550233 – johnw182 Oct 18 '15 at 14:20
  • Had the same problem and fixed with the answer on this SO post http://stackoverflow.com/a/30828772/1550233 – johnw182 Oct 18 '15 at 14:21

2 Answers2

4

I've had it recently with Android Studio 1.3. The only working solution was to remove the .gradle and .idea folders and re-import it in Android Studio.

ticofab
  • 7,551
  • 13
  • 49
  • 90
  • Had this problem also but was able to skip deleting the `.idea` but followed the same steps and it worked. – pjco Aug 05 '15 at 19:00
  • Additionally, I had to remove the .AndroidStudio1.3 folder in the user directory to get it working... Unfortunately, this deletes also all your preferences.. – Ben Sep 03 '15 at 08:06
2

Seems like you've got version mismatch and Android Studio or Gradle fails to resolve dependencies.

First update Android SDK - update to latests versions, be sure to get SDK platforms v18 & v19.

Then decide which version you're targeting - v18 or v19. If v18, then android section of build config should look like

android {
    compileSdkVersion 18
    buildToolsVersion "18.1.1"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 18
    }
}

and if targeting v19:

android {
    compileSdkVersion 19
    buildToolsVersion "19"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 19
    }
}
mindeh
  • 1,808
  • 14
  • 12
  • I have both SDK v18 and v19, I tried configuring both in the build.gradle and I'm getting the same error. If I change it to a version that I don't have installed from the SDK manager I get a Gradle error saying that it can't find that revision, so I know it's at least checking that part. – jd50 Nov 05 '13 at 22:39
  • Beats me.. Couple of wild guesses - try upgrading Gradle to 0.8 if its older (config requires merely 0.6); also check if environment variable for Android home is set: e.g. `export ANDROID_HOME=/Users/mindaugas/Applications/android-sdk-mac_x86`. Btw, do you run this from command line or IDE? I presumed command line – mindeh Nov 05 '13 at 23:19
  • ANDROID_HOME is set. I can run gradle from both the CLI (./gradlew within the project directory) and the IDE and it runs fine. I was having an issue with the support library at one point, I assumed it had something to do with my build.gradle. Maybe it's just an issue with the editor... – jd50 Nov 06 '13 at 05:25