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
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"
The latest version of gradle is 3.1 enter link description here
but Android Studio is only using 2.2?
enter link description here
This seems likes a huge discrepancy. My configuration:
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2'
classpath 'de.felixschulze.gradle:gradle-hockeyapp-plugin:3.2'
classpath 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
}
}
allprojects {
repositories {
jcenter()
}
}
When I try to find gradle 3.1, I get an error that it cannot find it. Same now with 2.2 > Could not find com.android.tools.build:gradle:2.2.
But gradle -v shows
gradle -v
------------------------------------------------------------
Gradle 2.2
how do I resolve this?
You are confusing Gradle with the Android gradle plugin, which generally matches the version of Android Studio. The latest version (at time of writing) is 2.2.2. It is generally set in your project's base build.gradle as you have shown above.
The Gradle wrapper is what you're looking for. You can change the wrapper's settings in your project's gradle/wrapper/gradle-wrapper.properties file.
Change
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-all.zip
Again, this is separate from the Android gradle plugin, which simply marries Gradle with Android Studio.
Find all distributions here
Here is the Gradle Version Compatibility for Android Studio
Gradle
refer to link
A problem occurred research project ': sample'.
Failed to apply plugin [id 'com.android.application']
Minimum supported Gradle version is 3.3. Current version is 3.2.1.
The current gradle configuration is also changed to 3.3. The project is running without problems, but can not use the command line (gradle and ./gradlew).
Refer to the online program:
1. Modify gradle-wrapper.properties, and Invalidate Caches / Restart ..., or do not work.
Later in the gradle forum to find a program: Thank you Henry
As new release with the fix not available yet, the former walk-around works fine.
Buildscript {
System.properties ['com.android.build.gradle.overrideVersionCheck'] = 'true'
...
}
. So mark what.
Correction statement : I later found that I installed the sdkman tool,
the tool installed 3.2.1 version, and this should be related (⊙ o ⊙)!
. At the beginning of the show gradle version, will show 3.2.1
version (I am still very depressed, change or show 3.2.1), I have
changed to the environment variable 3.3. I set the gradle environment
variable first, the following is set sdkman environment variable (this
order may also affect). So the final reason is still installed 3.2.1
version.
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
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.
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