Unable to Run Android Project: Gradle Project Refresh Failed

I’m running

OSX 10.9.5
javac 1.8.0_11

I was having a number of issues with Android Studio (it got stuck in a tight loop and stopped responding every time I tried to build a project), so I completely removed it (using the instructions here) as well as my sdk folder.

I reinstalled Android Studio and then updated (1.0.2 Build #AI135.1653844 built December 18 2014) Installed the recommended SDK packages and images for each of API 19, 20, and 21, as well as the support library.

I created a new project with all of the default settings, and was able to run the Hello World project on the Nexus 5 API 21 x86 emulator image that was in my AVD already.

Next, I tried to check out a project that required JDK 7+ from Version Control. Some random Googling found https://github.com/wikimedia/apps-android-wikipedia.git and that also ran in the emulator with no problem.

Then I imported the project I’m actually trying to build from github (I’m fairly sure it works for other people, but I’d rather not name it) and went through the same process. First, the Gradle sync failed because build tools 19.1.0 weren’t installed. It also didn’t start as an Android project: I got a message about it detecting the Android Framework, and needing to be configured (a dialog box with checkboxes for “Android” and “AndroidManifest.xml”). I configured the project, installed the 19.1.0 build tools, and resynced gradle. The gradle build succeeded, with 9 warnings (‘… cannot find annotation method…’). I then tried to Run the project, and the gradle build failed with a bunch of

    com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)

Following instructions here I opened File > Project Structure and checked that my JDK location was in fact pointing to 1.8 install (/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home, as /usr/libexec/java_home returns)

In the build.gradle for the module, I added

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8

inside the android stanza and did a sync. It asked me to reload the project, so I did.

That had the same error, so I went into the toplevel build. gradle, and added

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8

and did another sync, but this failed because the android() DSL method was not found. Using the instructions here I updated the gradle classpath from 1.0.0rc4 to just 1.0.0 (the url in the wrapper was already 2.2.1) That failed in the same way, so I took the other suggestion offered by Android Studio, to apply a gradle plugin. I noticed that the build.gradle for the module has a plugin com.android.application. I apply that plugin to the toplevel build.gradle and sync.

Then it fails with the super helpful message ‘Gradle project refresh failed. Error: A problem occurred configuring root project…’ There was no other text, and nothing in the Gradle console.

More Googling, and I find this which suggests I should try targeting 1.7 instead, so I change the four 1_8 to 1_7. Again, no luck. Same problem occurred configuring root project.

I’m really out of ideas. Any suggestions?


Put the compileOptions only in the app module build.gradle file. If you want to use Java 1.8, use gradle-retrolamdba to convert the bytecode so it runs on Android. If you want to use Java 1.7, make sure the SDK Location under the Project Structure settings is set to a 1.7 jdk.

Leave a Reply

Your email address will not be published. Required fields are marked *