Android Studio Gradle Error at Compile Time - android

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

Related

Could not determine the class-path for interface com.android.builder.model.AndroidProject

When I import an Eclipse project into Android Studio, I got this problem:
Gradle 'XNote' project refresh failed
Error:Could not determine the class-path for interface com.android.builder.model.AndroidProject.
Anyone knows why it happened? Thanks!
Just now i am facing the same problem.
1.Check classpath in build.gradle file.
change to
classpath 'com.android.tools.build:gradle:2.3.0'
then go to gradle-wrapper.properties, and change distributionUrl
distributionUrl=http://services.gradle.org/distributions/gradle-3.3-all.zip
and then rebuild the project. its help for me...
I think this will definitely helps you.
I have solved this problem.
Google doesn't update ADT any more, so when Eclipse export a project to gradle, it use an old gradle plugin version that Android Studio doesn't support.
First, you should check the version of gradle plugin that you have installed.
Open Android Studio's installation directory,then open the directory \gradle\m2repository\com\android\tools\build\gradle\, you will see all version you have installed.
Then open Android Studio, open tab 'Project -> Gradle Scripts', Edit file build.gradle, change the gradle plugin to newest version you have installed, such as 2.3.0:
[OPTIONAL] This step is not necessary, but if you do not do this, you may see this problem:
A problem occurred evaluating root project 'XXX'.
> org/gradle/initialization/BuildCompletionListener
Check the newest version of gradle you have installed at C:\Users\YOUR USER NAME\.gradle\wrapper\dists.
Then open tab 'Project -> Gradle Scripts', edit file gradle-wrapper.properties, modify the gradle version(attention: gradle, NOT gradle plugin) to the newest at the last line.
Finally, click Build - Clean Project, done!
If it still warning "Gradle project sync failed...", just click Try Again!
AT THE END, SOMEBODY HELP ME TO TRANSLATE MY ANSWER TO REAL ENGLISH THAT NO grammatical mistakes!!!
Just Update two things:-
1) Update your Build.gradle to
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
2) Update Gradle-wrapper.properties: (Change Android mode > Project mode then Extend Gradle and open Gradle-wrapper.properties)
Replace distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip
By
distributionUrl=http://services.gradle.org/distributions/gradle-3.3-all.zip
This always resolves the issue. may it usefull for you
I got it working after upgrading build tools to version 25.0.0 in build.gradle:
buildToolsVersion '25.0.0'
And change project to use newest gradle version 3.3 with default gradle wrapper (File -> Settings -> Gradle)
In my case I removed folder .idea from the project and then restarting the studio automatically manages to all the required folder and gradle work.
First, delete your .gradle folder in the home directory then restart Android Studio.
Palanivelraghul was right. A Studio has to download the old version. Then it presented 3 different options after it was complete.
Choose the top option ~"Sync with 3.0.1".
Event Log:
Gradle sync started > Project setup started > Gradle sync finished > Executing tasks:
[:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar] > Gradle build finished.

Android Build issue while creating a new project

I have been struggling with this gradle for the last one week. None of the earlier questions on gradle issue could solve my problem.
Things I did :
Download the latest gradle. I did it by changing the path at distribution URL in gradle-wrappper properties.
(It will download the latest one say 2.14. but, When I create a new project, It will be set to 2.10 and then back to same dirt)
Should I download the gradle for every project I create ? ... Help me fix this.
Thanks in advance :)
This is the error when I create a new project
Use the latest version of gradle with in build.gradle.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
Don't confuse gradle and the android plugin for gradle.
1) You can define the gradle distribution used by a project in the file
gradle/wrapper/gradle-wrapper.properties
For example:
distributionUrl=http\://services.gradle.org/distributions/gradle-2.14-all.zip
Each project can use a different version. You will find the distributions file inside \user\.gradle\wrapper\dists folder.
2) Gradle is a build tool, but it requires specific plugin to work.
Android Tool Team is releasing the Android plugin for Gradle.
You can define the plugin inside the build.gradle file in the project.
For example:
classpath 'com.android.tools.build:gradle:2.1.3'
Each project (or module) can use a different version.
Also go to File > Settings > Builds,Execution,Deployment > Build Tools > Gradle
and set Use default gradle wrapper

Android Studio: Re-download dependencies and sync project

I downloaded an open source game "ChaseWhisplyProject" source code from Github.
I imported the project in my Android Studio (Version 1.5.1).
It shows following error message:
Error:Failed to open zip file.
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
Re-download dependencies and sync project (requires network)
I changed all the dependency versions to latest one bu still it is showing the same message.
It has two modules under the main project 1) BaseGameUtils & 2)ChaseWhisply.
The above modules are not shown in bold letters (I think it should be shown in bold letters like module "app").
Following are the gradle files.
1) Root Gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
allprojects {
repositories {
jcenter()
}
}
2) BaseGameUtils Module Gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
dependencies {
compile 'com.android.support:support-v4:23.1.1'
compile 'com.google.android.gms:play-services:8.4.0'
}
3) ChaseWhisply Module Gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
apply plugin: 'com.android.application'
dependencies {
compile 'com.android.support:gridlayout-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.nineoldandroids:library:2.4.0'
compile project(':BaseGameUtils')
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
lintOptions {
// TODO fix and remove !
disable 'MissingTranslation', 'DuplicateIds', 'ExtraTranslation'
}
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 22
versionName "0.3.6"
}
}
4) Settings.gradle
include ':ChaseWhisply', ':BaseGameUtils'
What is wrong over here? Please help.
While importing a libGDX project I got the same message from Android Studio 2.2.
Went to File->Project Structure then selected Project and set
Gradle version
and
Android Plugin Version
to values identical to another project I had recently created with Android Studio 2.2 and updated SDK. Could then sync gradle. Did Build->Build Clean with no issues. Then did Run->Clean and Rerun and project ran fine.
Hope this helps.
It basically means that the gradle zip file in the cache folder is corrupted, if you don't want to change the version like the up-voted answer then you must delete the folder for your gradle version you're using for this project from the below path.
Then just retry the sync and android studio will download it again
C:\Users\ [user here] \.gradle\wrapper\dists
ex: if you're using 3.3 for this project you'd be deleting the folder
C:\Users\[user here]\.gradle\wrapper\dists\gradle-3.3-all
I was also facing the same issue. The solution worked for me was go to "gradle\wrapper\dists" and deleted the folder "grade-4.10.1-all" folder and downloaded the same version after that i pasted the extracted folder in same address.After that I again synchronized the android studio. I worked for me.
I face the same problem and I search for it and found a best solution and i works for me:
Manually download Gradle 3.3 binary (direct link: https://services.gradle.org/distributions/gradle-3.3-bin.zip)
Open your android studio root directory, and extract the zip to the gradle folder (for example: program files/android-studio/gradle/gradle-3.3)
Open Android Studio, go to File->Settings-> (Build, Exectution, Deployment) >Gradle and set "Gradle home" to point your new gradle-3.3 folder.
Apply and sync.
May be incompatible with Gradle and maven version
delete project dir/gradle/wrapper
put a right version gradle into it
run again
change the gradle-wraper-properties distributionUrl to your local downloaded gradle such as
distributionUrl=https://services.gradle.org/distributions/gradle-3.3-all.zip
I solved this issue by this following steps
1.C:\Users\System name.gradle\wrapper\
2.Inside wrapper folder u will find grale file with some version, You just have to delete it
3.Come/Go to android studio and Go to File->Sync project with Gradle Files.
4.Android studio automatically download the require gradle file.
5.And now go for coding
The close android studio then goes to the directory and you will find this type of folder. I saw in my pc. after deleted then clean project and sync. its works fine.
you just delete from this directory
C:\Users\ [user here] .gradle\wrapper\dists
if you use 3.3 version in android studio. you can see like this
C:\Users[user here].gradle\wrapper\dists\gradle-3.3-all
Well, It's a bit late, but usually happens when something went wrong in Android Studio's initial launch (eg. system crash, connection loss or whatever). We can call it bad programming or lazy QA.
To fix this close Android Studio and delete everything from the following directory. Don't worry files will be downloaded on next launch.
For Windows: C:\Users\your-username.gradle\wrapper\dists
For Linux: ~/.gradle/wrapper/dists
For mac: ~/.gradle/wrapper/dists
You can also Gradle manually to fix this issue, But it's better to let Android studio does this work. .
Clean Project is a way to go. After you clean project, make sure you rebuild it. Usually it solves the gradle issues for me.
In my case I was running IntelliJ IDEA as non root user.
If you want to use the new features, you should not revert it to the old version, just delete the directory ~/.gradle recursively, then restart Android Studio.
Update your gradle version and update with required version of gradle and syn your project.
https://services.gradle.org/
First of all, open your gradle-wrapper.properties file from the project then note down the version of the Gradle.
It could be like this:
distributional=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
So, here my Gradle version is 6.5. It could be different in your case.
After this, open file explorer and open your project folder. There you will be having the Gradle folder open it, inside it the version will be mentioned of your previous Gradle.
Now you will have to download the Gradle file according to the wrapper.properties(for example nothing but 6.5 version).
You can download it from here
Extract it
paste it to the Gradle folder
open your project > file > settings > Build, Execution, Deployment > Gradle, then select the newly downloaded Gradle file in the Gradle user home.
Then run your project.
This worked for me - go to https://gradle.org/releases/ and download latest stable version (binary-only works fine). extract and insert into C:\Users\OWNER\.gradle\wrapper\dists folder.
Open Android Studio settings > Build, Execution, Deployment > Gradle, use gradle from: specific location.
The following steps solved my problem :
1.C:\Users\System name.gradle\wrapper\
2.Inside wrapper folder u will find grale file with some version, You just have to delete it
3.Come/Go to android studio and Go to File->Sync project with Gradle Files.
4.Android studio automatically download the require gradle file.
5.And now go for coding

Gradle - Could not create an instance of Tooling API implementation

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

Android 1.5 Gradle Sync never completes

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

Categories

Resources