1

enter image description hereWhen I import projects from github into Android studio I see various errors related to the gradle version. For all the miseries of Eclipse I dont ever remember needing to do an upgrade every time to all sorts of different reasons. Usually it was SDK only.

I see a lot of errors along the lines of:

Error:failed to find Build Tools revision 21.1.0
 <a href="install.build.tools">Install Build Tools 21.1.0 and sync project</a>

Failed to apply plugin [id 'com.android.application'] Gradle version 2.1 is required. Current version is 2.2.1. If using the gradlewrapper, try editing the distributionUrl in /Users/Mac1/Downloads/u2020-dagger2 /gradle/wrapper/gradle-wrapper.properties to gradle-2.1-all.zip

It seems odd that a system designed to reduce the complexity of dependencies would demand the installation of old versions of gradle or build tools. Why does this kind of thing happen. Does this mean it has no build tools or just not that version? Does it mean it must be the old version? It certainly seems to be encouraging backward compatibility by insisting in installing old versions of everything. Gradle, build tools etc. I don't mean to be rude, so I'll keep quiet about what I think of this. In the meantime, what are we supposed to do?

buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:0.14.1'
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
  }
}

allprojects {
  repositories {
    mavenCentral()
    maven {
      url 'https://oss.sonatype.org/content/repositories/snapshots/'
   }
}
}

Here is project level build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

 android {
    compileSdkVersion 21
    buildToolsVersion '21.1.0'

  defaultConfig {
    applicationId 'dagger.demo'
    minSdkVersion 15
    targetSdkVersion 21
    versionCode 1
    versionName '1.0'
   }
}

dependencies {
  compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
  apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
  provided 'org.glassfish:javax.annotation:10.0-b28'
}
Mobile Man
  • 291
  • 2
  • 5
  • 13
  • Time to upgrade. Post your `build.gradle`. – Jared Burrows Mar 23 '15 at 04:14
  • Time to upgrade what? I say its time to upgrade android studio to 2.0 if only it was available. Or maybe what I need is gradle 3.0! how about when it demands gradle 2.1 thats a downgrade, and the suggestion to goto wrapper is wrong, it needed an upgrad. – Mobile Man Mar 23 '15 at 04:21
  • post your build.gradle(Project level). – Shvet Mar 23 '15 at 04:23
  • Shouldn't there be a min build tools version rather than just build tools version? – Mobile Man Mar 23 '15 at 04:29
  • Here is similar post required change of both gradle etc. I've posted showing whats currently installed. I have latest Android SDK, and I think 21 as well. – Mobile Man Mar 23 '15 at 04:40
  • look at this guy: http://stackoverflow.com/questions/23999714/android-studio-gradle-buildtools-revision – Mobile Man Mar 23 '15 at 04:47
  • I've added another question about the nasty gradle wrapper advice thrown up by studio: http://stackoverflow.com/questions/29204272/how-to-tell-when-gradle-wrapper-is-on-off-in-android-studio – Mobile Man Mar 23 '15 at 06:23

1 Answers1

2

First, make sure you have the latest Gradle version or atleast 2.2.1. Then update your build.gradle:

Top build.gradle:

buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:1.1.3' // <-- updated
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
  }
}

allprojects {
  repositories {
    mavenCentral()
    maven {
      url 'https://oss.sonatype.org/content/repositories/snapshots/'
   }
}
}

App build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

 android {
    compileSdkVersion 22
    buildToolsVersion '21.0.0'

  defaultConfig {
    applicationId 'dagger.demo'
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 1
    versionName '1.0'
   }
}

dependencies {
  compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
  apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
  provided 'org.glassfish:javax.annotation:10.0-b28'
}
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
  • I got this wonderful message: Error:Gradle version 2.2 is required. Current version is 2.1. If using the gradle wrapper, try editing the distributionUrl in /Users/Mac1/Downloads/dagger-android-sample-master/gradle/wrapper/gradle-wrapper.properties to gradle-2.2-all.zip Please fix the project's Gradle settings. Fix Gradle wrapper and re-import project
    Gradle settings
    – Mobile Man Mar 23 '15 at 05:42
  • gradle -version says 2.2.1 I'm on 2.2.1 – Mobile Man Mar 23 '15 at 05:42
  • I went ahead and changed the gradle-wrapper.properties now its hanging on Gradle Executing Tasks [clean,:] for about 10 minutes. Also begs the question am I using a wrapper? well I don't know, and neither studio nor gradle seem to know either. – Mobile Man Mar 23 '15 at 05:49
  • So after this 10 minute clean I am onto another wonder message:Error:A problem occurred configuring project ':app'. > failed to find target android-22 : /Users/Mac1/Downloads/adt-bundle/sdk Gee! I think I have android-22 I'll post again what I've already installed. OK This message is true. I did not have android-22 build tools installed although when I installed studio I installed apparently everything but android-22 ... build tools for latest. – Mobile Man Mar 23 '15 at 05:50
  • OK. This last error was fair. I really am missing the android-22 build tools. Took care of that. Now it has another complaint: Failed to find Build Tools 21.1.0 after the syncing? Why does it want that? – Mobile Man Mar 23 '15 at 05:59
  • What is purpose of your change: buildToolsVersion '21.0.0' I'll try with this and see if it matters. BTW, what is the backward compat of build tools? Why not just always use the latest possible build tools? – Mobile Man Mar 23 '15 at 06:02
  • Ok. everything builds now .... man that tough. Again does anyone know about the wrapper. Is there an on/off switch? It is just the presence of the gradle wrapper properties file? or is there a hidden switch somewhere? – Mobile Man Mar 23 '15 at 06:07
  • Perhaps we should always whenever importing a new project go straight to the gradle/wrapper directory and see its outdated? – Mobile Man Mar 23 '15 at 06:07
  • I guess that's another question so here it is: http://stackoverflow.com/questions/29204272/how-to-tell-when-gradle-wrapper-is-on-off-in-android-studio – Mobile Man Mar 23 '15 at 06:22
  • @MobileMan Slow down. Your questions are completely redundant. You need to stay with Android, Android does not stay with you. You need to keep you software up to date. It is that simple. Use my answer, it upgrades to the latest builds and make sure you upgrade your gradle version. – Jared Burrows Mar 23 '15 at 14:17
  • @JaredBurrows it is not possible to upgrade to the latest API see my question http://stackoverflow.com/questions/39307497/is-there-a-list-of-compatible-versions-of-libraries-for-each-android-sdk-version – likejudo Sep 03 '16 at 13:52
  • @likejiujitsu I have been compiling with Android 24 for months. Read your error, you are missing java 8. – Jared Burrows Sep 03 '16 at 14:36