How to use the latest gradle version in Android Studio - android

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

Related

Upgrading Gradle Build Tools on older hotfix branches in VCS

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"

LibGdx doesn't working after updating Gradle (Android Studio 3.0)

I have recently updated android studio and gradle to the version 3.0.0 following instructions in this link https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html
After doing this libgdx desktop project doesn't work.
It give me this error
java.lang.NoClassDefFoundError: com/badlogic/gdx/ApplicationListener
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: com.badlogic.gdx.ApplicationListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main"
Here is build.gradle file
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
I only added google() to repositories and edit gradle version to 3.0.0
In gradle-wrapper.properties I added this line
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
Android Studio 3.0 using gradle-4.1 and com.android.tools.build:gradle:3.0.0
Gradle 4.1 is not supported yet in LibGDX, there is an issue for the same, which is now upgraded for Gradle 4.6
Currently html module using deprecated jetty plugin which is removed in Gradle 4.1 version.
However using Terminal you can run desktop module, I've not tested on windows but on Mac it's working fine.
./gradlew desktop:run
For now you can use lower version of Gradle and Andoid-gradle-plugin in Android Studio 3.0 and wait for issue to be fixed.
Downgrade Gradle version from 4.1 to 3.3
Find gradle folder inside your project, Open gradle-wrapper.properties and change distributionUrl for 3.3
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
Downgrade Android-gradle-plugin version from 3.0.0 to 2.3.3
Open root build.gradle file and find artifact in buildscript and
change version
classpath 'com.android.tools.build:gradle:2.3.3'
Comment/delete google() from repo list inside root build.gradle file
--------------------------------------------------------------------------------
EDIT : Update LibGDX project to Gradle 4.6 - AS USER
Upgrade Gradle to 4.6 :
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
Add Google's Maven repo in project repositories list as well as in buildScript repo list in root build.gradle file.
repositories {
//..
google()
jcenter() // Required for org.jetbrains.trove4j:trove4j library
}
Update Android Gradle Plugin :
classpath 'com.android.tools.build:gradle:3.1.3'
Known issues with the Android Gradle Plugin
Configuration on demand with Gradle 4.6 and above:
If you're using Android Gradle Plugin 3.0.x or 3.1.x with Gradle 4.6
and above, you should disable configuration on demand to avoid some
unpredictable build errors. (If you are using Android Gradle Plugin
3.2.0 or higher, you do not need to take any action to disable configuration on demand.)
Disable configuration on demand in your gradle.properties file as shown below:
org.gradle.configureondemand=false
To disable configuration on demand in the Android Studio settings, choose File > Settings (Android Studio > Preferences on Mac), select the Compiler category in the left pane, and clear the Configure on demand checkbox.
In Android Studio 3.2 Beta 1 and higher, the options for enabling configuration on demand have been removed.
Update Android buildToolsVersion to 27.0.3 and SdkVersion to 27
Remove instrumentTest.setRoot('tests') from sourceSets inside android build.gradle file
replace all compile with implementation inside root build.gradle file
New GWT Gradle Plugin added in html module, check latest build.gradle of html module.
Run your project with Run Configuration or On Terminal using gradle task.
If you're going to create new project use gdx-setup.jar of latest build.
I temporarily solve this by forcing plugin to use 2.3.3 and gradle wrapper properties file reverted to 3.3
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
and build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
comment out the google() from repositories and tell android studio 3.0 to stop reminding you to upgrade gradle plugin to 3.0.0 for your current project.
Edit: To the person above who plagiarised my answer, shame on you!
Edit configurations -> Desktop -> In before launch change "Build" to "Build project". (use the + and - buttons).
worked with windows , in terminal you can go to the project folder and run desktop module using command .
gradlew desktop:run

Latest version of gradle can't be found

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.

Fix Plugin Version and Sync Project

I have recently updated my Android Studio.
After updating it, When I am trying to import or open a project it gives me following error :
Gradle Sync Issue
Error:Error:Gradle 2.4 requires Android Gradle plugin 1.2.0 (or newer) but project is using version 1.1.0.
Please use Android Gradle plugin 1.2.0 or newer.
Fix plugin version and sync project
Is there any solution for this problem ?
In your build.gradle you should use a newer version of the gradle plugin.
Use classpath 'com.android.tools.build:gradle:1.3.1'instead of classpath 'com.android.tools.build:gradle:1.1.0'. Or at least 1.2.0, as the error points out.
change in your progect build.gradle file
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
As Android Studio was just officially updated to 1.3 (Gradle as well).
Please Change gradle version to 1.3.+ in build.gradle . It should now look like this:
dependencies {
classpath 'com.android.tools.build:gradle:1.3.+'
// in the individual module build.gradle files
}
I met this question,too. Modifying dependencies stuff is confuse me. From#Mykaelos answer, For Windows Android Studio, Go into File > Settings > "Build, Execution, Deployment" > "Build Tools" > Gradle and change it to "Use default gradle wrapper (recommended)", I tried it in early hours, and it works for me.

Gradle version 1.10 is required. Current version is 2.2.1. error(20,0) Gradle DSL method not found: 'buildTypes()'

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

Categories

Resources