Android Studio Error - Unable to load class 'com.google.gson.JsonParseException' - android

I am getting below error in Android Studio.
I tried these things but it didn't work for me.
Deleted the .gradle folder and resync the project
Manually downloaded the gradle distribution & in settings changed gradle to use from specified location.
Unable to load class 'com.google.gson.JsonParseException'. 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.

Make sure your using suitable version of Gson in gradle file implementation 'com.google.code.gson:gson:<specific version>'

I highly recommend importing the library from your build.gradle instead of downloading it.
It might be a possibility that your Android Studio's gradle caches are corrupt. Fix for that is to got your .gradle folder in you Computer's home directory and navigate to caches folder and delete every thing inside it.

Related

Gradle build process is failing

My project was successfully building and all of a sudden I got the below error in Android studio.
Unable to find method 'org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal.getPublishableFiles()Lorg/gradle/api/file/FileCollection;'.
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 tried clearing the local dependency cache and rebuilding the project. But still the error persists.
I am using android studio v4.0 with build tools v29.0.2.
Is it because gradle can't download the dependency from maven repo?
Is it because there is an error in configuring maven in my 'respositories' list?
How can I get more information on this error?
Try to update the com.jfrog.artifactory version.
My resolution for this was to update the artifactory version like #disha4mourya suggested - add this block to your project's build.gradle, directly after your buildscript block:
plugins {
id "com.jfrog.artifactory" version "4.18.3"
}

Gradle project sync failed after update - Unable to find method 'com.google.common.collect.ImmutableSet.toImmutableSet()Ljava/util/stream/Collector;'

I recently opened up an old project, updated Android Studio to 3.1.3, and am now unable to run the project. This is the message I receive:
Unable to find method 'com.google.common.collect.ImmutableSet.toImmutableSet()Ljava/util/stream/Collector;'.
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.
This message is followed up by this one on the second attempt:
Could not initialize class com.android.build.gradle.internal.ide.ModelBuilder
Gradle Project sync failed
The gradle project sync keeps failing, I've tried all of these solutions below, including invalidating/restarting cache, deleting .gradle file, etc.
Unsuccessful solutions
I'm not an Android wiz, so if anyone can lead me in the right direction it would be greatly appreciated!
I suspect that this has to do with conflicts in Guava depending on the
Gradle version you use and the Guava version your dependencies use.
The function toImmutableList was added in Guava 21 (Guava 20).
I suggest you try downgrading the project's gradle version to 3.3 or so and try again.

Error importing a Gradle Android project in Android Studio

This is a follow-up question here. I was initially trying to just install the .apk executable given by the Android project, but now I am trying to build the project myself, which is located at: https://github.com/garlicPasta/dotViewer
It is essentially supposed to receive a 3D graphics file (.ply format) from the server and visualize it.
The project is using Gradle, but when I'm trying to import it in Android Studio, I see the following message:
Error:Unable to find method 'com.android.build.gradle.tasks.factory.AndroidJavaCompile.setDependencyCacheDir(Ljava/io/File;)V'.
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)</li><li>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)</li><li>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.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
I tried compiling it manually with gradle (installed gradle 2.10 to be compatible with the project). Can someone with more experience help me to import and run the project and find out what is missing for compiling?
BTW, there are two missing .java files which can be generated after compiling the .proto files.
I had the same Error after importing an Android-Project from Github.
I could fix it by copying the file PROJ_DIR/.idea/gradle.xml from an existing project.
I guess this is a problem gradle-2.14.1-all ,when I change the Gradle version to 3.3 ,then sync the project .This problem disappears。you can try it.

Facing an error while building. Gradle may be corrupt

I'm getting the following error:
Error:org.gradle.api.internal.changedetection.state.OutputFilesCollectionSnapshotter$OutputFilesSnapshot cannot be cast to org.gradle.api.internal.changedetection.state.DefaultFileCollectionSnapshotter$FileCollectionSnapshotImpl
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)</li><li>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)</li><li>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.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
Can anyone tell me how to solve it?
Try this solution
1.delete {project dir}/.gradle/1.9
2.Sync Project with Gradle File
**
OR
**
If it doesn't work then try for this solution:
Clone project to a new folder
Remove .gradle, .idea folders
Add as a new project (File > Open > [new folder])
Same Here... follow work for me
After giving error"Re-download dependencies etc..." click on android monitor at bottom end
Click on "Please configure android SDK"
Click on Project at Left Side Menu
Give another Build Version and Build Version Name
Copy ***
build.gradle code from another successful project and paste"replace"
all in this error'd gradle and click sync
Gradle will start built... Successfully but time consumed

Gradle error after studio update

I've recently upgraded from 1.2.2 to 1.3.2 and was introduced with the following error:
Error:Unable to load class 'org.gradle.api.publication.maven.internal.DefaultMavenFactory'.
Possible causes for this unexpected error include:You are using JDK version 'java version "1.7.0_79"'. Some versions of JDK 1.7 (e.g. 1.7.0_10) may cause class loading errors in Gradle.
Please update to a newer version (e.g. 1.7.0_67).
Open JDK Settings
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.
My project is using the SquiDB library if that matters, has anyone encountered similar error and could help me out how to fix it?
I don't know why but following has worked:
Open the Settings panel
Go to Build, Execution, Deployment > Build Tools > Gradle
On right in the form under the Project-level settings heading select Use default gradle wrapper (Recommended)
In my case I had selected Use local gradle distribution for some reason.
if you know the reason behind the issue and solution applied please add another answer with explanation and I will make it accepted.
if your gradle.properties file which is located at the root level of your project contains :
classpath 'com.github.dcendents:android-maven-plugin:1.2',
try to change to:
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
I solved the same problem in this way, and hope you will as well.

Categories

Resources