The latest version of Gradle is 2.14.1, right? Therefore, I have this:
gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
gradle.build
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.14.1'
}
}
But Android studio says it can't find it.
The version of the Android Gradle Build tool is completely independent of Gradle.
For example, yes, the recommended Gradle is 2.14.1 or higher, but the latest stable Android Gradle Build tool is 2.2.2
classpath 'com.android.tools.build:gradle:2.2.2'
EDIT (Mar. 2017) versions are now 3.3 or higher & build tool 2.3
It seems that you have misunderstood about Gradle and Android Gradle Build Tools.
In gradle-wrapper.properties, you can set the version about the Gradle; last 2.14.1
But in build.gradle, you set the Android Gradle Build tool; last 2.1.2
They are not the same thing.
Related
I noticed that when loading up your project in Android Studio (currently running 3.1 on Canary Channel), it likes to force you to upgrade Gradle Build Tools and sometimes Gradle itself when it detects it isn't using the latest. The 2 pieces I'm talking about are:
In the root build.gradle:
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0-alpha03'
}
}
And in gradle/wrapper/gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip
Note that I do not specify buildToolsVersion in my Gradle scripts (According to google documentation, this means it tries to use the latest version). I like not specifying it because it's 1 less version I have to continuously change in my Gradle scripts.
For the most part, my question is in regards to best practices. For our software, we tag versions we release to production with the mindset that we might need to go back and hotfix any of those releases. When going back to older hotfixes, should I allow Android Studio to upgrade build tools? Or should I prevent it from doing so (assuming I can, maybe by specifying buildToolsVersion manually)? If the latter case, I don't know how to keep Android Studio from continuously prompting me to upgrade in these cases. Sometimes it seems to fail syncing if I don't upgrade the build tools.
What's the best policy here and what are the functional differences between the two main choices I've outlined?
EDIT:
Here is a screenshot of the prompt I get. It's worded in such a way that it sounds like a build will not be possible unless I upgrade the tools:
And if I click "Update manually" to prevent it from doing so, I get:
I think "Cancel and update manually" in update dialog suits your needs.
If canceled once, you can see the message in status line. (Please see test8)
Also, if you have selected to update, you can manually set it lower again, I think.
Selecting "Update manually" causes build error once, but no error seems to happen if build it again. Please see tests 6-8 below.
Selecting lower gradle plugin version also seems having no problem, as I've tested again from test2 after all tests done.
Updated 2017/12/12
Related resources (to check current version):
Gradle
Gradle - releases
Dec 06, 2017
v4.4
Gradle plugin (>= 3.0.0)
NB: Please see Add Build Dependencies Programmatic access section for details.
Google's maven repo - master index com.android.tools.build
Google's maven repo - build tools group index gradle
3.0.1 or 3.1.0-alpha05
POM file url sample (for stable channel, >= 3.0.0):
NB: These are one of paths that gradle will access to get files
https://maven.google.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom or
https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
POM file url sample (for alpha channel, >= 3.0.0):
https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.0-alpha05/gradle-3.1.0-alpha05.pom
Old gradle plugin (<= 2.3.x)
Maven repo - gradle artifacts
Below here for information:
To see versions:
Android Studio version: Help > About
Gradle plugin version:
build.gradle(Project)
sample: classpath 'com.android.tools.build:gradle:3.1.0-alpha03'
Gradle version:
gradle-wrapper.properties
sample: distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip
NB1: Each gradle plugin version has required Gradle version.
See the table in Update Gradle section of this link.
For example: Gradle plugin 3.0.0 requires Gradle 4.1 or higher.
NB2: Some gradle plugin version has required buildToolsVersion, but basically having no relations to it.
For example: Gradle plugin 3.0.0 requires buildToolsVersion 26.0.2 or higher.
NB3: Some gradle plugin version has release notes with "This is a minor update to support Android Studio xxx"
For example: In the section of Gradle plugin 3.0.0
3.0.1 (November 2017)
This is a minor update to support Android Studio 3.0.1
I used same buildToolsVersion (27.0.1) for all tests below.
Android Studio: 2.2.x is 2.2.3 I think.
I used (android-studio-ide-171.4408382-windows) for Android Studio 3.0.x.
,not current one, but I've already downloaded it ago.
Test 1:
Android Studio: 2.2.x
Gradle plugin: 2.3.3
Gradle: 3.3
buildToolsVersion: 27.0.1
buildscript/repositories: jcenter()
build: pass
Test 2:
Android Studio: 3.0.x
Gradle plugin: 2.3.3
Gradle: 3.3
buildToolsVersion: 27.0.1
buildscript/repositories: jcenter()
build: pass
NB: When changing Android Studio version from 2.2.x to 3.0.x for same project, I saw an update dialog, but not the one in the question.
I've selected "Show tomorrow" for it.
Test 3:
Android Studio: 3.0.x
Gradle plugin: 2.3.3
Gradle: 4.2.1
buildToolsVersion: 27.0.1
buildscript/repositories: jcenter()
build: pass
Test 4:
Android Studio: 3.0.x
Gradle plugin: 3.0.1
Gradle: 4.2.1
buildToolsVersion: 27.0.1
buildscript/repositories: jcenter()
build: failed
Gradle sync failed: Could not find com.android.tools.build:gradle:3.0.1.
...
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
NB: Have to change repository settings.
Test 5:
Android Studio: 3.0.x
Gradle plugin: 3.0.1
Gradle: 4.2.1
buildToolsVersion: 27.0.1
buildscript/repositories: google()
build: passed
Test 6:
Android Studio: 3.0.x
Gradle plugin: 3.0.0-alpha9
Gradle: 4.2.1
buildToolsVersion: 27.0.1
buildscript/repositories: google()
Update dialog is shown.
build: failed after choosing "Cancel and update manually"
In message window:
Error:The project is using an incompatible version of the Android Gradle plugin.
Please update your project to use version 3.0.0.
Search in build.gradle files
NB: This is because gradle plugin 3.0.0 or higher is already released.
Test 7:
Android Studio: 3.0.x
Gradle plugin: 3.1.0-alpha03
Gradle: 4.2.1
buildToolsVersion: 27.0.1
buildscript/repositories: google()
Update dialog is NOT shown.
build: failed
Event log:
Gradle sync failed: Could not find org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.4-3.
NB1: Have to add kotlin.
NB2: kotlin requires mavenCentral repository.
See Kotlin - Using Gradle
Test 8:
Android Studio: 3.0.x
Gradle plugin: 3.1.0-alpha03
Gradle: 4.2.1
buildToolsVersion: 27.0.1
buildscript/repositories: google(), mavenCentral()
Update dialog is NOT shown.
build: passed
A message is shown in status line when I click classpath...gradle line in build.config, but no problem.
build.gradle(Project)
buildscript {
repositories {
google()
mavenCentral()
// jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0-alpha03'
// classpath 'com.android.tools.build:gradle:3.0.0-alpha9'
// classpath 'com.android.tools.build:gradle:3.0.1'
// classpath 'com.android.tools.build:gradle:3.0.0'
// classpath 'com.android.tools.build:gradle:2.3.3'
// classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.0'
}
}
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-all.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip
Status line
"A newer version of com.android.tools.build:gradle than 3.1.0-alpha03 is available: 3.1.0-alpha04"
I've recently updated the gradle version of my project from 2.14.1 to 3.0. Since then the gradle build is failing every time with this error:
Error:Cause: org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection cannot be cast to org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection
Possible causes for this unexpected error include:Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
I've searched google and found some solutions like this one but nothing is working. Does anyone know how to fix it?
Upgrade your gradle build tools to the latest version.
One easy way to do this is to add the latest version of the build tools as a dependency in your build.gradle file, for example:
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0-beta1'
}
You can then run gradle tasks and gradle will download everything you need.
After Android Studio 2.2 stable released on Sep 19 2016 , the latest version of the build tools is 2.2.0 . So you can fix it by :
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
}
As Android Studio 2.4 stable is not ready to release yet (May 4 2017), the latest stable version of build tools is 2.3.1 .
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
}
If you update this build tools version to 2.3.* , you should also update gradle wrapper version to 3.3 in /yourProjectRoot/gradle/wrapper/gradle-wrapper.properties file. (i know it is not matching question Gradle build failing after update to 3.0, but i strongly suggest you to use latest build tool as google recommended)
BTW: version 2.3.1 of build tool is only exist on jCenter, not MavenCentral, so if you run into error below when run gradlew command line in terminal
Could not find com.android.tools.build:gradle:2.3.1.
Searched in the following locations:
https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.3.1/gradle-2.3.1.pom
https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.3.1/gradle-2.3.1.jar
just replace mavenCentral() with jcenter() like
repositories {
jcenter()
//mavenCentral()
}
For latest update of Android Studio 3.0
In gradle-wrapper.properties(File Name) change URL of distributionUrl to the following:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
If you use gradle plugin 2.1.3,
It's simple to solve:
update your gradle plugin to version 2.2.0-beta1
Notes: this is a beta version, maybe you can get any other issues.
https://discuss.gradle.org/t/classcastexception-in-gradle-nightly-3-0-20160609/17979
Happy coding :)
Okay I got it working. For anyone facing the same problem the way it worked for me is as follows:
Go to your external .gradle folder (for me it was C:\Users\drilon.gradle). Inside caches and daemon folder delete all the version folder (they look like this "2.14.1", or "3.0"). Also go to wrapper -> dists -> delete everything there.
Inside your project root (for me it was C:\Users\drilon\AndroidStudioProjects\PorjectName) go to the .gradle folder and delete everything there.
Rebuild the project
EDIT:
Turns out this solution was setting the gradle version back to 2.14.1. ending0421's solution is the working one.
For latest update of Android Studio 3.3.1 below code work.
1) gradle-wrapper.properties add below line.
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
2)build.gradle in project level add below classpath
dependencies
{
classpath 'com.android.tools.build:gradle:3.1.0'
}
if your gradle version is: 3.0.1 then use below code in your gradle-wrapper.properties distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
if 3.1.2 then use below code in your gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
After 1 hour R&D No Solution as worked for me...
But still i have solution follow this its work 100%
step 1: upgrade your build.gradle(Project:<your project name>)
Example : classpath 'com.android.tools.build:gradle:2.1.3' // old gradle file
classpath 'com.android.tools.build:gradle:2.3.1' // upgraded file
OR
classpath 'com.android.tools.build:gradle:3.1.0'
Step 2 : Upgrade compileSdkVersion buildToolsVersion
Example : compileSdkVersion 23 buildToolsVersion "23.0.3 // old api's
compileSdkVersion 25 buildToolsVersion "25.0.2" // upgraded api's
Step 3: upgrade gradle-wrapper.properties
Example : distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip // old or any version
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip // new or any version
Step 4 : finally goto build>rebuild project...
Still You face some problem commit or inbox me....
......End #Ambilpura
You should check your Gradle Plugin version and Gradle version before updating.
Check Gradle Plugin Version in your project level build.gradle file-
buildscript {
repositories {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:gradle.plugin.version'
}
}
Check Gradle Version in your gradle-wrapper.properties-
distributionUrl=https\://services.gradle.org/distributions/gradle-gradle.version.zip
At the time of this answer, below were the latest versions. You can match your versions on this page.
Simply delete everything inside gradle folder in main project folder and Rebuild the
project. It will start working.
If your gradle plugin 3.0.0 for studio version 3.0, Add this in gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
simple answer try this...
goto build.gradle(PROJECT) and check the gradle version as shown below
'com.android.tools.build:gradle:2.1.3' or 3.0 or 3.1 or xx.xx
now open gradle-wrapper.properties see this line of code if gradle version is 2.x this the code below...
distributionUrl=https://services.gradle.org/distributions/gradle-2.14.1-all.zip
gradle-2.14.1-all.zip line of code must be same as gradle version
example:
example:
mine is 2.x so...
classpath 'com.android.tools.build:gradle:2.1.3' in build.gradle so
distributionUrl=https://services.gradle.org/distributions/gradle-2.14.1-all.zip
in gradle-wrapper.properties.
if gradle version is 3.x then
classpath 'com.android.tools.build:gradle:3.1.0' in build.gradle then
distributionUrl=https://services.gradle.org/distributions/gradle-3.14.1-all.zip
in gradle-wrapper.properties.
check this it will works
if Android Studio Android Studio 3.0 below code work.
gradle-wrapper.properties add below line.
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
if Android Studio Android Studio 3.1.2 below code work.
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
if Android Studio 3.3.1 below code work.
1) gradle-wrapper.properties add below line.
distributionUrl=https://services.gradle.org/distributions/gradle-4.6-all.zip
2) build.gradle in project level add below
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
}
Android Gradle dependencies are not working in new update of Android
Studio
Most important thing if you are face a lot of problems :
It is applicable on plugin 7.1 or new update version
Please Try this:
Go To -> settings.gradle inside of repositories { } :
add two files as :
maven{ url("https://repo.gradle.org/gradle/libs-releases/") }
maven { url "https://jitpack.io" }
The complete structure in
settings.gradle
file as given below :
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven{ url("https://repo.gradle.org/gradle/libs-releases/") }
maven { url "https://jitpack.io" }
}
}
rootProject.name = "MyApp"
include ':app'
And last step, it is must be added into gradle.properties files.
android.useAndroidX=true
android.enableJetifier=true
I've just noticed Gradle has released version 2.12 and according to the release notes the scripts should compile up to 20% faster. I'd like to upgrade to that version in Android Studio.
I'm using v1.5.1 and in the settings I've selected the "Use default gradle wrapper" option, which means that instead of using a local gradle install for every project, a specific gradle version will be used for each project. The version used is the one defined in the build.gradle file. Example:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
Now if I change that to this:
classpath 'com.android.tools.build:gradle:2.12'
then Android Studio can't find that version and throws an error. Apparently AS tries to find the binaries in a local cache first (Android Studio/gradle/m2repository) and then it tries to download it from bintray:
https://jcenter.bintray.com/com/android/tools/build/gradle/2.12/gradle-2.12.jar
Browsing the published builds it looks like the last version available here is v2.1.0-alpha1.
Why is v2.12 not in bintray yet? Is it not compatible with Android Studio?
If it were compatible, is there a way to download it and use a local install in a per-project basis? (I don't want to break older projects already in version control)
com.android.tools.build:gradle is android's plugin for gradle. It is not the same as gradle distribution. See here for release/version information of gradle android plugin: https://maven.google.com/web/index.html?q=gradle#com.android.tools.build:gradle
To change the gradle version that the plugin uses, edit the file:
<Project>/gradle/wrapper/gradle-wrapper.properties
and change this line to the gradle verison you want:
distributionUrl=http\://services.gradle.org/distributions/gradle-2.12-all.zip
Then rebuild your project.
Do keep in mind that the android plugin version you're using may not have been tested with this brand new gradle version and could potential cause unexpected issues.
android gradle plugin to Gradle version compatibility as of Feb2020
Plugin version Required Gradle version
-- --
1.0.0 - 1.1.3 2.2.1 - 2.3
1.2.0 - 1.3.1 2.2.1 - 2.9
1.5.0 2.2.1 - 2.13
2.0.0 - 2.1.2 2.10 - 2.13
2.1.3 - 2.2.3 2.14.1+
2.3.0+ 3.3+
3.0.0+ 4.1+
3.1.0+ 4.4+
3.2.0 - 3.2.1 4.6+
3.3.0 - 3.3.2 4.10.1+
3.4.0 - 3.4.1 5.1.1+
3.5.0 - 3.5.3 6.0.1+
3.6.0+ 6.0.1+
For AS 2
The latest plugin is:
classpath 'com.android.tools.build:gradle:[INSERT LATEST HERE]'
For AS 3
You should update the repositories to include google(), you also need gradle > 4.1 for that and the latest is then here:
https://developer.android.com/studio/releases/gradle-plugin.html
At time of writing that was:
buildscript {
repositories {
// Gradle 4.1 and higher include support for Google's Maven repo using
// the google() method. And you need to include this repo to download
// Android plugin 3.0.0 or higher.
google()
...
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
}
}
What worked for me in addition to the above (changing the distibutionURL) was to keep my classpath as 2.0.0 in build.gradle (Modile:app):
classpath 'com.android.tools.build:gradle:2.0.0'
In File > Project Structure > Project: change 'Gradle version' to 2.12
In File > Settings > Build, Execution, Deployment > Build Tools > Gradle :
Under 'Project-level settings' section, there are 2 options:
Use default gradle wrapper (recommended)
Download gradle-2.12-all.zip from http://gradle.org/post-download-gradle/
then select 'Use local gradle distibution' and map 'Gradle home:" i.e. C:/Gradle/gradle-2.12
Note that option 2 will require you to download each gradle version update.
Try this: -
change this url according to latest version in gradle-wrapper.properties and then change gradle.
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip
Hope it helps
Thanks
You can't use the default gradle wrapper if you want to use the latest, you have to go it the settings, check "Use customizable gradle wrapper", then change in
Project/gradle/wrapper/gradle-wrapper.properties
the distributionUrl value
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip
I got the error when i importing existing project to android studio.below i attached a screenshots of error message..
We are using android studio version 1.2.2. and Our System is Windows 7 32 bit
Error:Gradle version 1.10 is required. Current version is 2.2.1.
Please Guide to us.
Check the version of gradle and gradle plugin used in your project.
In your build.gradle (this is the gradle plugin version) you can use:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
In gradle/wrapper/gradle-wrapper.properties (this is the gradle version)
distributionUrl=http\://services.gradle.org/distributions/gradle-2.4-all.zip
There is a relation between gradle-plugin and the gradle version, and they need to be compatible.
Check these links for a full version compatibility mapping table:
official link
my stackoverflow post
I just upgraded Android studio and now Android Studio complaints about Gradle, saying:
You are using Gradle version 1.8, which is not supported. Please use version 1.9.
So under Preferences > Compiler > Gradle, I changed the Gradle executable to /usr/local/Cellar/gradle/1.8/libexec. After rebuilding, Android Studio then complaints again, saying
Gradle version 1.8 is required. Current version is 1.9.
If using the gradle wrapper, try editing the distributionUrl in /Applications/Android Studio.app/bin/gradle/wrapper/gradle-wrapper.properties to gradle-1.9-all.zip.
I don't know anything about a Gradle wrapper, but in my gradle.build I've got these lines for the gradle version:
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
Does anybody know how I can fix this? I'm really stuck and quite desperate! All tips are welcome!
Switch to the gradle Android plugin version 0.7+
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
Then you should be able to build with gradle version 1.9.
Make sure all your build.gradle files in the project use gradle 1.9 as dependency
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
Also check your Gradle Wrapper properties file. Its available in your project structure. It must point to gradle 1.9. AFAIK you will get pop up this fix that automatically but just confirm
Update both the build.gradle dependency as mentioned by keyboardsurfer and pyus13 and the distribution url found in gradle-wrapper.properties under /gradle/wrapper/.
Example:
distributionUrl=http\://services.gradle.org/distributions/gradle-1.9-all.zip