Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tools.jar not found OS X

I have scoured stack overflow and have not found a solution to my problem. This is a bit long winded, but I have not found a solution in the past week, searching non-stop.

Problem: tools.jar not found when trying to compile Android source code, and also when trying to install Android Studio

Operating System: Mac OS X El Capitan 10.11 Computer: MacBook Pro Retina, late 2015. (new computer as of couple weeks ago)

Here are the two scenarios that seem to have the same problem.

Scenario 1: I am trying to compile Android Source code to create a custom ROM. I have followed the steps at http://source.android.com for OS X, specifically http://source.android.com/source/initializing.html in the section about MAC.

I have run all steps, leading up to building the System. The next step is

source build/envsetup.sh
lunch aosp_eng

This Error pops up @ lunch aosp_eng:

*** Error: could not find jdk tools.jar at /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/../lib/tools.jar, please check if your JDK was installed correctly.  Stop.

** Don't have a product spec for: 'aosp_arm'
** Do you have the right repo manifest?

Scenario 2: Download Android Studio to make app, but this error pops up,

'tools.jar' seems to be not in Studio classpath.
Please ensure JAVA_HOME points to JDK rather than JRE.

This is my .bash_profile:

export PATH=/usr/local/opt/mongodb/bin/:$PATH

# mount the android file image
function mountAndroid {
    hdiutil attach ~/android.dmg.sparseimage -mountpoint     /Volumes/android;
}

#unmount the android file image
function umountAndroid(){
   hdiutil detach /Volumes/android;
}

export USE_CCACHE=1
#export JAVA_HOME="$(/usr/libexec/java_home)"
export JAVA_HOME="$(/usr/libexec/java_home -v 1.7)"
#export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/"
#export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/"
#export JAVA_HOME=$(/usr/libexec/java_home)

First line is for Mongodb, the "mounts" is from the source.android.com step by step process. Use ccache from combination of android tutorial and using MacPorts to be able to use ccache. All the JAVA_HOME that have been commented out is me trying to find a solution online.

Currently, I have a few difference java versions installed

jdk1.7.0_71.jdk
jdk1.7.0_79.jdk
jdk1.8.0_65.jdk
jdk1.9.0jdk

JDK 1.9 is the beta version, but I needed it to install Netbeans Dev JDK 1.9 version since there is a current known bug with MacBook Pro Retina with Netbeans 1.8. Scrolling is laggy and the only current fix is Beta version JDK.

Depending on which $JAVA_HOME I use, this outputs:

me-mbp:~ Me$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/

me-mbp:~ Me$ javac -version
java 1.8.0_65

me-mbp:~ Me$ which java
/usr/bin/java

If I comment out all the $JAVA_HOME, it defaults to jdk1.9. Don't know why, but it does.

Any semblance of a solution came about when I copied tools.jar to Android Studio App folder (see below). It let me "install" Android Studio and run, but as soon as I tried to make a new app, it just sat there, and did nothing. Also, Studio had an error saying: Using jdk1.9, needs to change in settings (paraphrased).

cp /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/lib/tools.jar /Volumes/Macintosh\ HD/Applications/Android\ Studio.app/Contents/lib/

A solution to the problem would be a godsend. Much of my work is depending on this and I would love to be able from my new Laptop. At the moment, I am having to remote into an Ubuntu machine to do all my Android Source work. The Android Studio problem was just an extension of the problem (I Think). Thanks in advance.

like image 997
Singledigit Avatar asked Nov 04 '15 16:11

Singledigit


People also ask

Where can I find tools jar in JDK?

Please check that C:\Program Files\Java\jre1. 8.0_221 contains a valid JDK installation. #575.

How to find JDK path in Mac?

In macOS, the JDK installation path is /Library/Java/JavaVirtualMachines/jdk-10. jdk/Contents/Home . The root directory of the JDK software installation.

Can not determine path to Tools jar?

The problem is with version of JDK you are using. The Intellij version 2020.2 supports only upto JDK 14. So either you have to lower the JDK version to 14 or update the IntelliJ to a newer version like 2021.


1 Answers

Android need a separator env system variable named ANDROID_JAVA_HOME, So set env: export ANDROID_JAVA_HOME="your java home", solved my problem

like image 89
michael Avatar answered Oct 23 '22 01:10

michael