I recently upgraded to Android Studio 1.5. However, after update, Gradle gets stuck at "Refreshing [project] Gradle Project" and never stops.
Previous version of Android Studio worked just fine.
How do I solve this?
I am on an Ubuntu 15.10 64bit machine.
Edit:
So far, I have tried deleting Android Studio from /opt and downloading the latest version. Didnt help.
I also tried removing the ~/.AndroidStudio1.5 directory. To no avail.
This is in my "Event Log"
Gradle sync started
NullPointerException: null
In your Android Project change gradle-wrapper.properties file, which is in *project/gradle/wrapper:
From:
distributionUrl=https://services.gradle.org/distributions/gradle-2.4-all.zip
To:
distributionUrl=https://services.gradle.org/distributions/gradle-2.8-all.zip
And also change the project build.gradle like below:
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
In your build.gradle for the project, update your classpath to gradle 1.5.0
Example:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
allprojects {
repositories {
jcenter()
}
}
go to Preferences > Build, Execution > Build Tools > Gradle and change the Gradle Home path. I had to change mine because it had the wrong value, it was /Applications/Android Studio.app/Contents/gradle/gradle-2.4 and I changed it to /Applications/Android Studio.app/Contents/gradle/gradle-2.8
I had the same problem. My JAVA_HOME wasn't set to the right directory. Ehsun Mehranvaris answer is more like a hack, than a solution. I tried to built the android project per terminal with ./gradlew and it told me JAVA_HOME wasn't set correctly.
To get the path of your java enter in terminal:
readlink -f $(which java)
Set your JAVA_HOME like this in terminal:
export JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre
After that, I switched to the android project directory in the terminal and did run this command:
./gradlew
This will build your project and in my case it downloaded the latest gradle 2.8 package. Android Studio might download the package itself, if you set the JAVA_HOME correctly. Didn't try that.
Now you can use the default gradle wrapper from Android Studio and don't need to edit any property file manually. You find that at Preferences > Build, Execution > Build Tools > Gradle
Related
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'm trying to import a project from GitHub and build/run it on Android Studio. I am getting the following error:
"Error:Could not create an instance of Tooling API implementation
using the specified Gradle distribution
'https://services.gradle.org/distributions/gradle-2.4-all.zip'."
I have tried the following:
Invalidate Cache and Restart
Changing the distributionURL in gradle-wrapper/properties to 2.5 etc.
Deleting build.gradle and restarting
These are ideas I got from several other posts on stackoverflow so I cannot explain why I tried these. (I'm very fairly new to Android Studio).
My build.gradle file looks like this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
} }
allprojects {
repositories {
jcenter()
} }
task clean(type: Delete) {
delete rootProject.buildDir }
I was facing a similar issue, updating the Gradle version in distributionUrl solved it.
distributionUrl field is present under this directory:
project-root-directory/gradle/wrapper/gradle-wrapper.properties
Please, change
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
with
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
Then change
classpath 'com.android.tools.build:gradle:1.5.1'
with
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
It should work.
For me I think it is permission issue. From Eclipse I have also faced the same issue. On my gradle installation path (i.e. /opt/gradle) I have make it chmod as 777. So that other tool can access the same. Run the following 2 commands -
cd /opt
sudo chmod 777 -R gradle
Java versions > 9 and Gradle versions >= 5.0.0 has some code breaking changes. Here is to go around them using Eclipse. It should be similar in AndroidStudio.
Install the latest version of gradle from its distribution site
("https://services.gradle.org/distributions/") and
unzip the it on your PC.
When importing the gradle project in eclipse select the option "local installation
directory" and point to the folder where you unzip gradle.
(Bonus) if it is a LibGDX project, you need to also change the following in the Desktop
build file due to code breaking changes between gradle versions <5.0.0 and >=5.0.0.
Change "sourceSets.main.output.classesDir" to "sourceSets.main.output.classesDirs".
This is working for me and I am using LibGDX with Java 11 and Gradle 5.2.1 on Windows 10 while running Eclipse 2018-12.
Try deleting the folder gradle-2.4-all in ~/.gradle/wrapper/dists
I have an Android App in Android Studio. When I build project with Gradle File,it gives me one error at compile time.
Error Report:
Error:org.gradle.api.internal.changedetection.state.DefaultFileCollectionSnapshotter$FileCollectionSnapshotImpl cannot be cast to
org.gradle.api.internal.changedetection.state.OutputFilesCollectionSnapshotter$OutputFilesSnapshot
Please Give me solution about this error.
1.delete {project dir}/.gradle/{gradle distribution version dir}
{gradle distribution version dir} is whatever the gradle distribution version you use (ref: https://developer.android.com/studio/releases/gradle-plugin.html#revisions). For example, it can be "1.9" or "2.10" or some other version number.
2.Sync Project with Gradle File
This is what worked for me:
Android Studio -> File -> Invalidate Caches and Restart
Stoping the gradle daemon worked for me.
go to terminal and run ./gradlew --stop
Rebuild the project.
For me, I have tried to:
(Doesn't Work):
invalidate caches.
stop third-party plugins.
remove gradle repository.
remove {project dir}/.gradle/2.*(which are not current gradle version)
(Work):
Finally, the answer is like #MAC113's,
delete {project dir}/.gradle/2.10 (2.10 is my current gradle version)
None of those solutions working for me. I ended up by:
Clone my project to a new folder
Remove .gradle, .idea folders
Add as a new project (File > Open > [new folder])
It works! It's a weird issue that I've ever met.
Easy solution! Just fixed on my side. It was a project exported from Unity Studio.
After exporting from Unity, the gradle was like com.android.tools.build:gradle:2.1.0
I then changed it to com.android.tools.build:gradle:2.2.0 and it worked.
Also never forget to change the repositories from mavencenteral to jcenter().
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
If you using GreenDao You should update it to the lastest version
classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0' // add plugin
implementation 'org.greenrobot:greendao:3.3.0'
Deleting .gradle folder works for me
Gradle updates and error now, I can't import my project.
Error log:
Could not execute build using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.9-rc-3-bin.zip'.
Build file '/home/luiz/Dropbox/projetos/droido-beta/droido.torpedos/build.gradle' line: 9
A problem occurred evaluating project ':droido.torpedos'.
A problem occurred evaluating project ':droido.torpedos'.
Gradle version 1.8 is required. Current version is 1.9-rc-3. If using the gradle wrapper, try editing the distributionUrl in /home/luiz/gradle/wrapper/gradle-wrapper.properties to gradle-1.8-all.zip
How solve this?
I had this issue with android studio 0.4.2, I changed the android tools in build.gradle from 0.6+ to 0.7+
original line in build.gradle:
classpath 'com.android.tools.build:gradle:0.6.+'
Changed to:
classpath 'com.android.tools.build:gradle:0.7.+'
Then I just ran Tools->Android->Sync Project with Gradle Files and everything worked.
Gradle 1.9 is not yet supported by the build tools.
Consider using Gradle Wrapper which will download it's own version of gradle that your project is built from.
See (http://www.gradle.org/docs/current/userguide/gradle_wrapper.html)
Add the wrapper task and set it to 1.8
then run gradle wrapper
You might have to re-import your project to AS and when you do, tell it to use the wrapper.
Hope that helps.
I had this problem using Ubuntu (Linux Mint) this week and I couldn't get the wrapper working. My final solution was to:
Download and unzip Gradle 1.8 from http://www.gradle.org/downloads
Remove the .gradle directory from your user directory (/home//.gradle) (I'm not sure if this is actually necessary)
Re-import the project to Android Studio, and in the import options, specify "local gradle distribution" - point to the newly installed/unzipped Gradle 1.8
And fingers crossed your error disappears.
You have to remove directory $USER_HOME.gradle\wrapper\dists\gradle-1.9-rc-3-bin using command. In Windows:
cd .gradle\wrapper\dists
rmdir /s gradle-1.9-rc-3-bin
There is a new Android Studio update: https://sites.google.com/a/android.com/tools/recent/androidstudio030released
The link says:
The improved performance is made possible by changes in Gradle 1.8 and
Android Gradle plugin version 0.6.+
So I changed my dependencies like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
But I don't know where I can change the Gradle 1.6 to 1.8 ...
And when I compile the app I've got this error:
Gradle: A problem occurred evaluating project.
Gradle version 1.8 is required. Current version is 1.6
Where can I change the version ?
Thanks in advance :)
I am not sure if this will help you but here is what fixed it for me:
Open up this file in your project:
<Project>/gradle/wrapper/gradle-wrapper.properties
Edit the distributionUrl line and set it too:
distributionUrl=https\://services.gradle.org/distributions/gradle-1.8-all.zip
Rebuild your project.
Update: You might want to use gradle-2.8-all.zip now.
I had same problem. Try to remove directory 'gradle' in project directory and then rebuild project. It helped me.
The Android Studio ask you for download and install the Gradle version 1.8 for you.
Also the Android Gradle plugin version 0.6.2 has an issue and not works properly.
As said on the official page use the version 0.6.3:
dependencies {
classpath 'com.android.tools.build:gradle:0.6.3'
}
More info:
http://tools.android.com/knownissues
You should use the following in your build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
Edit:
Nowadays 0.9.+ is the most up-to-date gradle plugin.
The Android Gradle 0.6.2 plugin that was published on Maven Central. Edit your build.gradle file and instead of depending on "0.6.+", depend on "0.6.1".
All other solutions are incomplete and non-working. Here's a step-by-step that worked for me.
I updated the gradle plugin in build.gradle to 0.7.+
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
But when using the gradle plugin 0.7.+, Android Studio needs Gradle 1.8. So, you have to update Gradle from 1.7 to 1.8.
This was done by going to
Tools -> Android -> Sync Project with Gradle Files
It forces Android Studio to give out Error message you see on http://tools.android.com/recent
In the error message you have to click the part "Fix Gradle wrapper and re-import project". I restarted, not sure if this make a difference.
So far everything seems to work. I can create new projects and it build fast, without errors, but the gradle has still 0.5+.
Looks like, I had to change it manually for every new projects. This is what I thought, because I didn't get any error or information from this installation to fix it. (Mac).
Than I went to my Windows installation, which had still Android Studio version 0.2.13 and
tried the same procedure, I used with the updated version, changed the build,gradle and used Synch Project with Gradle Files. This gave me a total different information:
Gradle version 1.8 is required. Current version is 1.7. If using the gradle wrapper, try editing the distributionUrl in
C:\Documents and Settings\Owner\Start Menu\Programs\Android Studio\gradle\wrapper\gradle-wrapper.properties to gradle-1.8-all.zip
Turned out, I have a gradle-wrapper.properties file in every project (in gradle/) but I don't have any gradle-wrapper.properties file at the location Android Studio gave me.
When you open the gradle-wrapper.properties file from your project, it will properly look like this:
#Sun Oct 20 03:35:31 CEST 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.7-bin.zip
To change the gradle-1.7-bin.zip into gradle-1.8-rc-1-bin is possible but not the solution I was looking for.
Check out if Andoid Studio already downloaded the gradle plugin 1.8
Directory of C:\Documents and Settings\Owner.gradle\wrapper\dists
2013-10-13 06:24 <DIR> .
2013-10-13 06:24 <DIR> ..
2013-10-04 18:17 <DIR> gradle-1.6-bin
2013-10-13 06:24 <DIR> gradle-1.7-all
2013-10-04 12:23 <DIR> gradle-1.7-bin
2013-10-04 18:26 <DIR> gradle-1.8-rc-1-bin
0 File(s) 0 bytes
6 Dir(s) 81 945 972 736 bytes free
Now I create a new gradle-wrapper.properties file in
*C:\Documents and Settings\Owner\Start Menu\Programs\Android Studio\gradle\wrapper*
#Tue Oct 20 06:35:40 CEST 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-all.zip
This did the Trick. Now, after updating to 0.3, every new project gets a build.gradle with
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
and a gradle-wrapper.properties file in gradle/ with
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip
Credits
I took several steps including: downloaded the gradle-1.8-all.zip file and placed it in a new directory off of my user home directory (Windows-7) and named the directory "gradle-1.8". For good measure, I also unzipped the download in this new directory. I also added a user environmental variable "GRADLE_HOME" with a pathway to this new directory.
I manually edited the "build.gradle" file in the project's top-level directory and entered:
dependencies {
classpath 'com.android.tools.build:gradle:0.6.3'
}
When Android Studio opened the existing project and I did a build or tried to run it, I got the subject error. The final solution, as mentioned by others, was a several step process:
I removed both the "gradle" and the ".gradle" directories.
I rebuilt the project which recreated the ".gradle" directory but not the "gradle" directory. Then, I closed the project and used "File/Import Project" to load the project again. And, I used the "Use customizable gradle wrapper" as suggested.
This worked. The "gradle" directory was created again in the project's top-level directory. The project builds clean and runs. It would be nice to have step-by-step upgrade instructions for these updates.
Old question but just in case someone runs into the same issue I had with upgrading.
If you have setup gradle for offline mode, it doesn't update the wrapper properly. Turning off offline mode (Preferences->Gradle->Offline work) then clean/rebuild pulled in the new gradle version. This assumes that gradle-wrapper.properties file has been updated.
Similar Issue :
Just updated android studio :p
Help -> Check for Update...
This is a late response, but in case anybody's run into a problem of the gradle version in their ionic project being overwritten by an older one by AS, just remove the android platform from your ionic project and then re-add it. Evidently, installing Gradle is part of that command, so you'll overwrite the overwrite, and get the version you need to run ionic build android from within your Ionic project's root directory.
Although, WARNING: Removing the Android platform, and then re-installing it, might wipe the splashscreens and icons that you'd had in your resources folder. And by "might," I mean that it's happened every time that I've done it (which makes sense, since the resources folder is inside of the android folder that you're removing/re-intalling). Perhaps a more eloquent command line input could reinstall the android platform while leaving the resources folder alone, but, in any case, make sure to copy the directory with your custom splashscreens and icons to a new one before running the re-install.
You can download the latest Gradle file from This link
You can then add it to your File -> Settings -> Build, Execution, Deployment -> Gradle path and the sync the project