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
Related
Since I update android gradle I have issues in my ringtone app, problem is in copying files and permissions I guess (I noticed that in manifest android.permission.WRITE_SETTINGS is underlined with red color, and I guess there is the problem)
Same code works perfectly in my old projects and the only difference is in gradle, so I tried some tutorials on net on how to downgrade it, but I have failed.
I tried in gradle-wrapper.properties(Gradle Version) to change
distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip
to the version that worked for me before, but I got message that 4.4 is minimum
then i tried to downgrade in build.gradle(Project)
but only succeeded to downgrade it to
classpath 'com.android.tools.build:gradle:3.0.1'
but that didn't solved my problem, because the working version was 2.3.3
with distributionUrl=https://services.gradle.org/distributions/gradle-3.3-all.zip
and when I tried to sync with 2.3.3 i got error
Gradle DSL method not found: 'google()'
Possible causes:<ul><li>The project 'MyProject' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 3.1.4 and sync project</li><li>The project 'MyProject' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file</li><li>The build file may be missing a Gradle plugin.
Apply Gradle plugin</li>
Can somebody tell me the proper way and step by step solution to my problem
Below are the steps you may try but this is not a good way of solving the problem. You better focus on the main issue and try to solve it. Start from here or find other workarounds.
1-Remove google() from build.gradle and add maven instead:(for Gradle lower than 4.1)
buildscript {
repositories {
maven {
url 'https://maven.google.com'
}
jcenter()
}
}
2-Go to gradle-wrapper.properties and change gradle version to:
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
3-Change gradle plugin to(if you're using Android Studio 2.x.x):
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
4-Sync.
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
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 am trying to use gradle build. It gives me error saying that
Failed to apply plugin [id 'com.android.library']
Gradle version 2.2 is required. Current version is 2.10. If using the gradle wrapper, try editing the distributionUrl in /home/sanjeewa/workspace/Android/UVCCamera/gradle/wrapper/gradle-wrapper.properties to gradle-2.2-all.zip
But my gradle-wrapper.properties includes gradle-2.4-all.zip. I have changed it to gradle-2.2-all.zip
Still same problem.
When I run gradle -version in terminal Gradle 2.10 shows as version.
How to solve that error??
my build gradle file is
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Open gradle-wrapper.properties
Change this line:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
with
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
Go to build.gradle (Project: your_app_name)
Change this line
classpath 'com.android.tools.build:gradle:XXX'
to this
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
or
classpath 'com.android.tools.build:gradle:1.5.0'
Don't click Sync Now
From menu choose File -> Invalidate Caches/Restart...
Choose first option: Invalidate and Restart
Android Studio would restart. After this, it should work normally
Hope it help
Current work around is to overrideVersionCheck: In your build.gradle
buildscript {
System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'
...
}
Check this link for more Details
Just Change in build.gradle file
classpath 'com.android.tools.build:gradle:1.3.0'
To
classpath 'com.android.tools.build:gradle:2.0.0'
Now GoTo -> menu choose File -> Invalidate Caches/Restart...
Choose first option: Invalidate and Restart
Android Studio would restart.
After this, it should work normally.
Based on
https://developer.android.com/studio/releases/gradle-plugin.html ...
The following table lists which version of Gradle is required for each version of the Android plugin for Gradle.
For the best performance, you should use the latest possible version of both Gradle and the Android plugin.
So, the Plugin version with Required Gradle version should be match.
Here's what I did to fix this:
1) Create a new project
2) open the gradle-wrapper.properties file and copy the distributionUrl to your project e.g.:
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2-all.zip
3) open the build.gradle (Project) and copy the gradle dependency to your project e.g.:
classpath 'com.android.tools.build:gradle:2.3.0-beta1'
4) File --> Invalidate Caches / Restart (I think a re-sync may have sufficed, but didn't try it)
5) Delete that project you made (optional)
Look, this is a silly way to do things, but Android Studio is free so who am I to complain...
Use ./gradlew instead of gradle to resolve this issue.
The android studio and Gradle version looks like very bad managed. And there's tons of version in-capability issues. And the error message is mostly clueless. For this particular issue. The closest answer is from "Jitendra Singh". Change the version to:
classpath 'com.android.tools.build:gradle:2.0.0'
But in my case: Android studio 2.2 RC, I still get another error:
Could not find matching constructor for: com.android.build.gradle.internal.LibraryTaskManager(org.gradle.api.internal.project.DefaultProject_Decorated, com.android.builder.core.AndroidBuilder, android.databinding.tool.DataBindingBuilder, com.android.build.gradle.LibraryExtension_Decorated, com.android.build.gradle.internal.SdkHandler, com.android.build.gradle.internal.DependencyManager, org.gradle.tooling.provider.model.internal.DefaultToolingModelBuilderRegistry)
So I went to the maven central to find the latest com.android.tools.build:gradle version which is 2.1.3 for now. So after change to
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
}
}
Solved my problem eventually.
I Had similar issue. Every project has his own gradle folder, check if in your project root there's another gradle folder:
/my_projects_root_folder/project/gradle
/my_projects_root_folder/gradle
If so, in every folder you'll find /gradle/wrapper/gradle-wrapper.properties.
Check if in /my_projects_root_folder/gradle/gradle-wrapper.properties gradle version at least match /my_projects_root_folder/ project/ gradle/ gradle-wrapper.properties gradle version
Or just delete/rename your /my_projects_root_folder/gradle and restart android studio and let Gradle sync work and download required gradle.
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