Android studio error After run the project - android

I am getting following error while trying to run my app from android studio
Execution failed for task ':app:compileDebugJava'. Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.
After searching on internet, I found some solution like this
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_45/
so i gave this command in terminal from android studio dirctory but its not workout it show the same error again.

Updating my Gradle build version did the trick for me.
Old:
classpath 'com.android.tools.build:gradle:1.0.0'
New:
classpath 'com.android.tools.build:gradle:2.2.3'
Edit: Since this answer is still being used frequently, note that Gradle 2.2.3 can probably be substituted with any newer version of Gradle. This version just happened to be the version I was using when I originally answered the question.

In your android-studio
find it in File->Other Settings->Default Project Structure->SDKs. Then i changed JDK home path.

To fix this error in Andriod Studio 2.3.1 I had to go to File > Project Structure or Ctrl+Alt+Shift+S then go to SDK Location which was already open for me and then uncheck "Use embedded JDK" and point to where my installed version was.

To fix this error in Andriod Studio 2.3.1 I had to go to File > Project Structure or Ctrl+Alt+Shift+S then go to SDK Location which was already open for me and then uncheck "Use embedded JDK" and point to where my installed version was.
*
The mentioned post really solved my problem after long searching.
*

In the android studio
Window -> preferences -> Java -> Installed JREs and select your JDK home path
or else please follow the link to set JAVA_HOME in linux machines

In your android-studio find it in File->Other Settings->Default Project Structure->SDKs.
Then Check with JDK LOCATION select Installed JDK Location and APPLY IT.

I have this problem a lot when I try to open older projects for the first time. It seems that I just need to update the classpath under build.gradle:
In my case the old version was:
classpath 'com.android.tools.build:gradle:1.3.0'
and I updated to:
classpath 'com.android.tools.build:gradle:2.3.2'
Sync the gradle and it should compile.

Related

Android Studio 2.2: Gradle 'MyApplication4' project refresh failed

I'm using Android Studio 2.2 on Windows 8 (32-bit). I've tried every solution given over the Stack Over Flow or other forums on the internet but all in vein. Error details are given below:
Gradle 'MyApplication4' project refresh failed
Error:CreateProcess error=216, This version of %1 is not compatible with the version of Windows that you're running. Check your computer's system information and then contact the software publisher
I'm mentioning again that I've tried every solution i.e. jdk location, gradle plugins refresh, uninstalling and reinstalling the Android Studio, etc. So, please help me out with any other solution.
Please check your gradle version.
Try to add the dependency below:
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
}

Gradle error: Write access is allowed from event dispatch thread only in Android Studio

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)".

Android Studio 2.2 preview1 errors

So i'm trying to use Android Studio 2.2 preview-1 in Ubuntu 14.04 LTS.
I'm using gradle-2.10 and gradle-plugin 2.2.0-alpha1 along with openJDK-8.
compileSdkVersion 23
buildToolsVersion "23.0.3"
First the studio.sh didn't run and i found the solution to change #!/bin/sh to #!/bin/bash. Voila --it starts properly.
But in build.gradle files, warning is shown--
'dependencies' cannot be applied to '(groovy.lang.Closure)'
and its not finding imported class from library project(includes a jar only).
Please someone help me out.
The only fix that I found for this is, every time I open a project, I go to Settings>Build, Execution, Deployment>Gradle, change to "use local gradle distribution", click apply then click "use default gradle wrapper" and ok.
This should fix, but its quite annoying to do this everytime.
It Looks like a problem of version 2.10 of the wrapper version on gradle.
After reading around people's workaround like
"invalidate cache and restart"
delete .gradle file in the project and re-open it
etc etc
I just try for fun to install a standalone version of gradle since I'd always used only the wrapper version that cames with android studio.
And with it there is any error and any warning.
For anyone who wanna try (I'm a mac's user):
install gradle (by homebrew is fine and pretty easy) brew install gradle
tell to AS to use that one instead the wrapper version preference -> build, Execution, Deveployment -> Gradle -> use local gradle distribution
if you install it by homebrew like me the correct path will be: /usr/local/Cellar/gradle/x.yy/libexec
where x.yy it suppose to be 2.11 (that is the last version provide by brew even if the lastest version released is 2.13)
I've realised just now that the steps above doens't fix the definitly. Each time you re-open the project the problem came again and again.
It's annoying but changing betwen use of "wrapper"/"regular gradle" take the warning away.
But this means also that isn't a problem o the gradle as I'd assumed at the beginning.
...let's wait a permanent fix ^^
This issue is fixed in Android Studio 2.2 preview 2 (download from this page).
Disabled a couple of Groovy inspections that reported incorrect errors in build.gradle files
From the changelog.

Android Studio 4.0 stuck refreshing, can't run project

I just upgraded my Android Studio from 3.7 to 4.0. After upgrading, I changed the gradle dependency to 0.7.+ as indicated in the release notes.
Now, the IDE is stuck with a background task that says it is "Refreshing" my project.
I cannot run the project or do anything as those gets queued behind this task.
Note: it did a maven central update of about 100 MB before which completed successfully.
This is how I resolved it
Step 1: Modify build.gradle
Open the build.gradle in your module (not the top-level build.gradle file)
Change the following (or something similar
classpath 'com.android.tools.build:gradle:0.7.+'
to
classpath 'com.android.tools.build:gradle:0.6.+'
Save.
Step 2: Restart Android Studio
Step 3: Fix build.gradle
Android Studio will nag you about Gradle version. Let it fix it. (You might have to manually change it to 0.7.+).
Click on Sync Project with Gradle Files then gradle will download the dependencies and it's fixed.
I had the same issue. I just updated my android studio to 2.0 on ubuntu 14.04. This issue arose for one of the project and it was solved through a [answer][1] here which seems unrelated to this problem !!
If you are using Android Studio 2.0 Beta, this issue might appear (more likely if you are working on NTFS filesystem) and it seems like the "Instant Run" is the culprit. Search for "Instant Run" in settings and uncheck the box
Posting here to an old question - maybe somebody else might me stuck on this aswell.
I fixed it too.
change project level build.gradle classpath from 0.7 to 0.6
restart the android studio
import module and notice me to upgrade build.gradle version and change 0.6 to 0.7 manually and downloading maven resource successfully.

Gradle version 1.6 is required. Current version is 1.8-20130730220035+0000

Just updated Android-Studio to version 0.2.7 an now I get the error message from the title:
In the log window there is link to the grade setup:
No matter which option I use the error message stays the same.
I deleted my ~/.gradle directory and projects **/.gradle directories.
It seems that nothing helps.
Nitpick: compile on the command-line using \opt\gradle\1.6\bin\gradle.bat build works fine.
Go to Preferences > Project Settings > Gradle and choose "Use gradle wrapper" instead of the bundled option
Open your gradle-wrapper.properties and change the distributionUrl to use 1.7 if it is not already (mine was 1.6), i.e. distributionUrl=http\://services.gradle.org/distributions/gradle-1.7-bin.zip
I managed to fix my project through some combination of invalidating Android Studio cache, deleting .idea and .gradle directories and .iml files, restarting Studio, and reimporting the project:
on Mac OSX using Homebrew, brew install gradle then pick local gradle distribution and point to /usr/local/Cellar/gradle/1.7/libexec for gradle home:
You do not want to manage gradle at a system level, it is better handled per project. Android Studio projects already setup gradle wrapper handling when creating new projects but if you have an older one you can add the same file that Android Studio does. Think of this as an gradle bootstrap file that will download the correct gradle version per project. You can also read up on Gradle Wrapper and generate a shell script called gradlew that will provide gradle-free bootstrapping.
In gradle/wrapper/gradle-wrapper.properties in your project directory make sure you have:
#
#Tue Oct 08 13:40:54 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
Then when you go into Gradle you can set it to use the gradle wrapper. This is the default when creating new projects in Android Studio.
There are at least three approaches to migration or adding Gradle properly and using the new project structure Google and Android Studio has introduced.
Create a new project and copy over the code
Export from Eclipse to Gradle (deprecated)
Import code into Android Studio (recommended)
Try to manually get everything in order by creating the correct gradle files and reorganizing the project.
For now I'm copying the files over to a new project until the tools get a bit better.
We have two computers, one of which gave that same message after upgrading to Android Studio 0.2.7. We noticed that the computer which could still build had Gradle installed independently of Android Studio.
Installing Gradle 1.6 downloaded from the Gradle web site fixed this issue on the computer that wouldn't build.
My fix was basically what Abe did but I wanted to give a bit more explanation:
Download gradle 1.6 from the gradle website
Extract somewhere on your pc/mac
Open up android studio, go to Preferences -> Gradle (left panel) -> and chooose Local gradle distribution.
Point Gradle home to the location where you extracted gradle.
This fixed the issue for me. Using the gradle wrapper and the bundled gradle distribution both failed
In my case, i updated gradle to the latest version (1.8) and then changed the gradle.build files (for my project and for the libraries i was using) like these:
dependencies {
classpath 'com.android.tools.build:gradle:0.6.1+'
}
The Synchronize files and Refresh/Invalidate cache. This seems to solve the problem. I think that Gradle in order to determine the minimum required version just reads the above value.
Here's what I did to get my project working:
Installed Gradle 1.7 on my OS (OS X users can use brew for this)
Added this to my local.properties file: sdk.dir=/Applications/Android\ Studio.app/sdk
Created gradle wrappers with gradle wrapper command.
Chose "Use gradle wrapper (recommended)" option in Android Studio.

Categories

Resources