After updating Android Studio to version 2.2 (on Windows 10) and somehow next morning I received such error when gradle built on any project:
Write access is allowed from event dispatch thread only
Despite that gradlew -build command worked and completed successfully.
I tried typical Android dev's of WTF repairing set: clean build, invalidate caches, removing build folders, removing .gradle folder, tried different gradle settings, even reinstalling Android Studio and nothing helped.
I've created this question only to share my experience with community, because I wasted two hours on it.
So the problem was concluded in that Android Studio conflicted with my installed JDK version, so it was resolved when I checked JDK location (File → Project Structure → SDK Location), ticked 'Use embedded JDK' checkbox and set JDK location to 'path to Android Studio'\Android Studio\jre
Problem was occurred when android studio conflict with installed jdk
version, Go to the (File -> Project Structure -> SDK Location), check
'Use embedded JDK' checkbox and set jdk location to 'path to android
studio'\Android Studio\jre :) Simple
that didn't work for me, i ran a 'gradle clean build' command, i figured out that there's a conflict in a line in the gradle, deleted it and sync project (as in this pic)
My issue was that I had removed the SDK I was using while clearing up hard drive space.
To fix this, first check what SDKs you have installed, or install one in Tools > SDK Manager.
You can then change the compileSdkVersion and targetSdkVersion in app build.gradle to your installed sdk version.
Otherwise you can just reinstall what ever sdk you were using.
In Android Studio 3.2.1 go to File -> Project Structure -> SDK Location and check in the check box "Use embedded JDK (recommended)".
I just download the newest Android Studio from the developer site.
After installation I installed Android Studio, then I created new project and after project build completed, I opened my MainActivity.java file to find this error. Please refer to screenshot below:
I also downloaded Android SDK component which is built-in already in Android Studio.
Start Android Studio and invalidate cache File--> Invalidate Cache and Restart.
Rebuild your project. Try clean build. That should do. Faced a similar problem.
Tools -> Android -> Sync Project with Gradle Files
Build -> Rebuild
Incorrect installation of JDK also might cause problems. Please tell what the error is in detail.
You can try this for JDK Installation:-
On some Windows systems, the launcher script does not find where the JDK is installed. If you encounter this problem, you need to set an environment variable indicating the correct location.
Select Start menu > Computer > System Properties > Advanced System Properties. Then open Advanced tab > Environment Variables and add a new system variable JAVA_HOME that points to your JDK folder, for example C:\Program Files\Java\jdk1.8.0_77.
Goto File -> Project Structure on left hand side click on SDK Location there you can find Android SDK Location and JDK Location. So, now locate your JDK path by browsing your JDK installation path. Click OK, Now goto Build -> Rebulid your project.
It's better to check whether the JDK path set in Environment variable by typing java -version in commmand prompt. If it is not set, set the path as DvD said in his post.
Hope this works for you.
I tried some solutions but none of them helped.
I can't compile anything because of gradle's error:
Error:C:\Program Files\Android\Android Studio\gradle\gradle-2.8\native\jna\win32-amd64\jnidispatch.dll (System can't find this path)
In Settings I tried to check "Use default gradle wrapper (recommended)" but it comes back to "Use local gradle distribution" with path C:\Program Files\Android\Android Studio\gradle\gradle-2.8
I downloaded gradle 2.8 from the official site but there's no "native" directory.
I updated everything with SDK and restart Studio but it also didn't help.
Android Studio 1.5.1, it's the same with all projects, even the new ones.
How can I fix this?
I got the same problem when switch to another computer. It's because project is keeping the reference to another computer paths.
For fix it i did:
I deleted the .idea folder from the project, like the highlight from image bellow.
Then you have to remove the project from android studio and open it again.
I am very new in Android Studio. I have a problem with gradle.
it says,
Error:Invalid Gradle JDK configuration found.
Platform SDK does not point to valid `JDK` `(C:/Program Files/Java/jdk1.8.0_20)`.
Consult IDE log for more details (Help | Show Log)
then what should I do to solve that?
I got this issue in Android studio 4.2 canary, and I had to delete those generated files:
.idea/gradle.xml
.idea/workspace.xml
then clicking try again to sync the project.
Under Android Studio, select File > Project Structure > JDK location.
Specify the JDK to the folder of your currently installed JDK. And specify the SDK location as well.
Simple solution:
Go to build.gradle and at the top there will be a message JDK missing
Click on it and use JDK from the list (or download one if you don't have)
Sync project
I got this issue in Android Studio 4.2.2, and the solution is very simple, just delete
.idea/gradle.xml
.idea/workspace.xml
and click on
File -> Invalidate Caches/ Restart
If you want / need to, update your JDK installation to the version that you want to use.
Next, find the version for your current JDK installation by running javac -version or java -version. Check that it is what you expect.
Next, find the JDK installation directory:
It should be on your %PATH%.
By default it will be a subdirectory of "C:\Program Files\Java"' for example: "C:\Program Files\Java\jdk1.8.0_45"
Next, start Android Studio, and go to the "File->Project Structure->JDK Location" preference page.
The file path given by the preference should be the path to the JDK installation director that you identified above. If it isn't then update it.
Notes:
Use the full pathname of the installation directory; e.g. "C:\Program Files\Java\jdk1.8.0_45".
Use a pathname, not a URL.
This Problem occurs when you open your Android Project in Another Computer.
To Solve this,
DELETE your .gradle and .idea folder from your project.
Invalidate Cache and Restart Android studio
After Restart, SYNC Again to automatically create new .gradle and .idea folders
Just delete .idea and .gradle folders from your project path on your computer and sync again.
This issue happens if you change the workspace or manually copy files to the new repo workspace. i fixed it by deleting below files,
.idea/gradle.xml
.idea/workspace.xml
Finally click on File-> invalidate cache and restart
For Android studio Canary Build Arctic Fox 2020.3.1 this seems like a bug or hard dependency with Jdk 11.
I already had jdk defined, but I was still getting this error. Got resolved after installing jdk 11 and providing path to it in the jdk location here
File > Project Structure > JDK location
I have solve this problem my App name "Addvoicetomusic2";
go to app dir-
C:\Users\amram\AndroidStudioProjects\Addvoicetomusic2
then remove .gradle and .idea file
*then connect to internet
restart android studio project
successfully solve
Solution for Android 4.2.2
Terminal commands:
rm .idea/gradle.xml
rm .idea/workspace.xml
Finally click on File-> invalidate cache and restart
The simple and easy way is
Go To Your build.gradle(Module:app)
At the top right corner you will find notification JDK is missing or download missing JDK
Clik on that notification and download JDK and Sync Project.
SIMPLE SOLUTION
-go to build.gradle and at Top there missing JDK right side configuration or download options to click and install JDK and have a already JDK then select it. Otherwise download better option.
Thanks click sync now or try again.
For macOS:
install JDK from Oracle site
Go to the folder:
cd /Library/Java/JavaVirtualMachines
Here you will see JDK installed.
Set folder in the Android Studio, something like this:
/Library/Java/JavaVirtualMachines/jdk-16.0.1.jdk
I don't why it's not possible to automate such tasks after all this years.
amra ram's solution worked for me, more or less. I had an old .idea directory with a weird configuration. Deleting it, closing Android Studio, and opening the project again forced it to reinstall and sync Gradle.
Go to build.gradle and at the top there will be a message JDK missing
Click on it and use JDK from the list (or download one if you don't have)
Sync project
When I encountered this same problem, I solved it by specifying the path to the portable (non installed) JDK8.
Same error i got when I install android studio on my pc . at the time of installation I have installed android sdk and android studio in different path so In project structure I have set my new sdk path .
Still I got message of invalid jdk ...then I knew location of jdk ,again in project structure I have set my jdk path.It works.
For me the problem appeared after updating IntelliJ to version 2020.2.1.
Just solved it by going to Project Structure -> SDK. There I only had the Java jdk. I've added IntelliJ IDEA Platform Plugin SDK and that seems to have solved the problem. gradle loads just fine.
First you have to delete the folders - .idea and .gradle from the source directory.
Select File > Project Structure > JDK location. Specify the JDK to the folder of your currently installed JDK. Ensure that you have installed the JDK version greater than 1.8. Also specify the SDK location.
Select File -> Invalidate Caches/Restart click Invalidate and Restart
if other answers not work try this
For Android Studio Arctic Fox | 2020.3.1 Canary 15
File -> Invalidate Caches/Restart
click Invalidate and Restart
it works for me
Just clean and rebuild project worked for me.
I had to update to the latest Android build, Android Studio Arctic Fox | 2020.3.1. to be specified to make the project compile.
Go to Android studio settings or preferences and select jdk as shown in image and try syncing project
Just deleted the entire .idea folder from your project and it will work.
If you're working with Android Studio 4.2.2, and you got a zip of somebody's source code, it may often contain the .idea folder. Unfortunately, the .idea folder may contain gradle SDK configuration, etc., that are only valid for the computer of the person who sent you the source code.
Solution:
Ideally, the sender should have deleted the .idea folder before sending to you, but you can still fix it by ..
Delete .idea/gradle.xml and .idea/workspace.xml.
Then do the gradle sync again and the error will go away, and it should be fine.
For me I just did File -> Invalidate Caches... -> Invalidate And Restart(leave the checkboxes above as default)
It will take some time but it worked fine .
I'm just trying out Android Studio. I imported a project from Eclipse, but every time I try
to run it I get this error:
"Cannot run program
"Library/JavaVirtualMachines?jdk1.7.0_10.jdk/Contents/Home/bin/java"
(in directory
"/Users/myname/Library/Caches/AndroidStudioPreview/compile-server"):
error=2, No such file or directory.
I just installed the latest JDK using the JDK 7 Update 21 dmg. Is it installing the jdk in a place where Android Studio won't find it? The dmg didn't have any options for where to install the jdk other than "Install for all users of this computer," which I did.
When I was using Eclipse I had no problems with running my programs.
Furthermore, the Project Structure option was no longer available after I updated earlier today. Instead I just get the message, We will provide a UI to configure project settings later. Until then, please manually edit your build.gradle file(s.)"
I'm not sure what to do to get my programs running again. Do I need to locate the jdk files and move them? Could I tell Android Studio where the files are actually installed?
The solution was easier than I thought: just go to File/Other Settings/Default Project Structure and click SDKs. There the JDK home path can be changed.
Yes changing the JDK path will work. If that doesn't fix your problem, as it didn't for me at first, uninstall your JDK and redownload and install it. Once I reinstalled mine, it worked flawlessly.