ant build : unable to locate tools.jar. Expected find it in C:\Program Files\Java\jre7\lib\tools.jar

Rikki Tikki Tavi picture Rikki Tikki Tavi · Feb 24, 2014 · Viewed 52k times · Source

I know that this question is popular, but no one of solutions can help me. I used this, this, this and this solutions, but no one help me.

I want to implement uiautomator Tests and need to build my build.xml with ant, but get this strange error.

I use Windows 8.1

My JAVA_HOME system variable set to c:\programs files\java\jdk1.7.0_51 and to c:\programs files(x86)\java\jdk1.7.0_51

My PATH system variable set also to %JAVA_HOME%/bin, my %ANT_HOME% is set to c:\apache-ant.

But when I execute ant build in the android app derictory I get the

unable to locate tools.jar. Expected find it in C:\Program Files\Java\jre7\lib\tools.jar
BUILD FAILED
Perhaps JAVA_HOME does not point to the JDK

But my JAVA_HOME points to right JDK ! I confused with this. I also rebuild my build several times, I've got the same.

Will be glad if somebody help me.

Answer

Smriti picture Smriti · Feb 24, 2014

I too had this problem and solved it by setting variables like this :

[1] ANT_HOME - C:\apache-ant-1.9.3

[2] JAVA_HOME - C:\Program Files\Java\jdk1.7.0_21

[3] PATH - D:\Android_Development\android_sdk\platform-tools\;%ANT_HOME%\bin;%JAVA_HOME%\bin;D:\Android_Development\android_sdk\tools

Note : Set all these in System variables not in user variables.

This solved my problem.

Hope it helps.