Android Studio MalformedJsonException - java

Just today I was on Android Studio working on a project, when my computer suddenly crashed in the middle of an upload.
Ever since I rebooted it, the Gradle Console has been returning this same error:
com.google.common.util.concurrent.UncheckedExecutionException:
java.lang.RuntimeException:
com.google.gson.stream.MalformedJsonException: Use
JsonReader.setLenient(true) to accept malformed JSON at line 1 column
1
I cannot make any sense out of this error, and could not find anyone else with the same issue. They always tend to differ in weird ways, and none of them are the error I have. I have not edited any of the JSON files (because I don't know where they are located).

Clean your project using :
Go to Build -> Clean Project
Then Rebuild again using :
Go to Build -> Rebuild Project
I hope it might help you !

File -> Invalidate Caches/Restart
you can try this

Firebase android Projects,
If you are using Firebase in your Mobile app.
download the google-services.json file and put it inside the /app folder and run the project again.

Related

Flutter "You need Java 11 or higher to build your app with this version of Gradle." error

When i create a new project, and press run i get this error.
The fact is i do already have jdk verison of 15 and my previously created projects do open and run without any errors. Also, if i add org.gradle.java.home=C:/Program Files/Java/jdk-15.0.1 line to my gradle.properties file the app runs without error but this way just does not seems right way to do it.
I have tried to change the SDK version from the project structure like some other questions and answers but it did not worked either. As an additon to other problems i do not have the same project structure screen as they showed so.
I do not know what to do right now, i would be very grateful if you could help me.
You should delete .gradle folder under user name. Then again run your project.
change gradle to 4.1.0
and it will be run

R.layout.main Cannot Be Found / Cannot Resolve Symbol R

All of a sudden I am getting red underlinings under my references to elements e.g R.textboxID. I did some googling around and I found that the error occurs when Android Studio can’t generate your R.java file correctly.
My question is how does Android Studio just suddenly not know how to generate my R file correctly when it was generating it well all along? How can I fix this problem permanently?
Select Build > Clean Project from the Android Studio toolbar, wait a few moments, and then build your project by selecting Build > Rebuild Project.
If a single clean/rebuild cycle doesn’t work, then try repeating this process a few times, multiple clean/rebuild cycles in quick succession usually work.
This usually happens when some unexpected event, like an IDE error occurs and the project needs to be rebuilt. Just hit Build -> Rebuild Project.
Sometines this may occur after you modify your build.gradle file, and sometimes, if it only occurs within one of your classes, you might not be inflating it correctly.
Gradle sync succeded? Try one of the following:
Clean end rebuild your project
From Android studio menu: File->Invalidate cache/restart, then clean and rebuild project
If none of above helps, close Android studio and remove ~/.gradle directory. Then run Android Studio, open your project, wait for finish sync, then rebuild project
Also make sure your gradle configuration is correct and resource xml files syntax is correct.
Please check the import statements at the top of file some times there may be import com.android .R will be there so you should delete that statement and it will work fine

java.lang.ClassNotFoundException DexPathList . Causes?

Can anyone explain to me the cause of this error? I know what is dexpath and dex class in android and how to fix this error. but don't know what is the cause of this error popping up every now and then.
This error occurs when
I transfer my project from one pc/laptop to another pc/laptop.
Whenever I've updated my android Studio lets say from AS 2 to AS 3 canary or stable release.
Uninstall and reinstall the Android studio and try opeining the Project again.
How I'm Fixing it:
Just remove all the dependencies and everything related to DEX Class file from gradle and sync it and then revert back to gradle settings with all the DEX file and dependencies added and Sync again. VOILAAA ..
And this is really annoying. How I can avoid this issue for my other projects without going through all this gradle sync tweak.
I had the same issue with moving projects to different system. when you move your project folder just leave out the build folder and you'll not see the error next time.
The error says a lot more then just class not found exception in the log. The path of the files/ app-parts.apk gets invalid when you move your project to a different system.
Just don't copy or just rename the old build folder to something else and open your project in AS. Build->CLEAN , BUILD->REBUILD and everything will work.
Happy Coding..

Unexpected lock protocol found in lock file. Expected 3 found 0

In android studio I keep getting this error message when building.
I've tried
deleting the .gradle file multiple times and restarting the IDE but the error doesn't seem to stop.
I made sure that I've updated EVERYTHING there is in SDK's and other things it required.
I've tried several solution -
First Solution: Go to File -> Invalid Chaches/Restart...
Second Solution: First, Build -> Clean Project and the Build -> Rebuild Project
Third Solution: First close the project and remove from workspace of Android Studio, then Go to C:\Users\user.gradle then delete .gradle folder. After that Open the project again.
But none of them worked! Then i got a solution, which worked in my case, the solution is bellow -
In my case, the problem was in gradle version. Check your Gradle version File -> Project Structure(Ctrl+Alt+Shift+S) and Plugin version also.
Delete the XXX.Lock file, and rerun the project. You should be able to find the location of this .lock file in the error message
is solved mine by downloading the latest version the latest version of gradle distribution.
https://services.gradle.org/distributions/

android ant error: invalid resource directory name: ./bin/res\crunch

I'm using ant command line to build an android project with an external library. (For some reason, I can't make it into a jar to put in libs/)
After completing all the steps of android update and reference link for the project and the lib project, the error of "invalid resource directory name: ./bin/res\crunch" pops out when running "ant release". I know it is a common error but failed to solve it after doing intensive research and trying out all the solutions, including
1) project->clean
2) delete ../bin/res/crunch. (it will re-appear and create the trouble)
3) change android version or SDK version to higher one
Any suggestion? Thanks!
A cleaner solution is to clean before building:
ant clean
ant release
You don't really have to copy things from the 'crunch' directory to the 'res' directory, since these are generated as part of the build anyway.
It appears that the root cause of this problem is incompatibility between ADT v.22.2.1 and ANT.
Related threads:
https://plus.google.com/+AndroidDevelopers/posts/hNZNjqKLpny
https://code.google.com/p/android/issues/detail?id=60496
Finally I figured it out: copied everything from bin/res/crunch folder and pasted it in res and then deleted the crunch folder. If the library project is modified, the error will reappear. Redoing the procedure above will fix it again.

Categories