Unable to build android due to incorrect java - android

I have ubuntu 14.04 and I am trying to build android for BBB. I got BBB android and visited this site to get the correct java.
I took android source from this site
http://bbbandroid.sourceforge.net/build.html
then followed steps for java from this site,
https://source.android.com/source/initializing#for-ubuntu-14-04
I did as the site said.
then make -j4 gave this build error,
============================================
Checking build tools versions...
************************************************************
You are attempting to build with an unsupported JDK.
You use OpenJDK but only Sun/Oracle JDK is supported.
Please follow the machine setup instructions at
https://source.android.com/source/download.html
************************************************************
build/core/main.mk:152: *** stop. Stop.
Then I did this
**java -version**
openjdk version "1.8.0_45-internal"
OpenJDK Runtime Environment (build 1.8.0_45-internal-b14)
OpenJDK 64-Bit Server VM (build 25.45-b02, mixed mode)
**sudo update-alternatives --config java**
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 auto mode
1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode
* 3 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
Press enter to keep the current choice[*], or type selection number: 3
**sudo update-alternatives --config javac**
There are 2 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 auto mode
1 /usr/lib/jvm/java-6-openjdk-amd64/bin/javac 1061 manual mode
* 2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode
Press enter to keep the current choice[*], or type selection number: 2
again I checked the java -version
openjdk version "1.8.0_45-internal"
OpenJDK Runtime Environment (build 1.8.0_45-internal-b14)
OpenJDK 64-Bit Server VM (build 25.45-b02, mixed mode)
Its still same as previously.
What is the problem here?
What exactly is supported by google's android, oracle jdk, sun jdk or open jdk?

You need to get the Sun/Oracle JDK, and you are currently using the OpenJDK.
Sun/Oracle JDK is the JDK supported. (Sun is owned by Oracle)
The makefile output answered your question. It must be checking and enforcing the use of Sun/Oracle JDK.
You use OpenJDK but only Sun/Oracle JDK is supported.
Please follow the machine setup instructions at
https://source.android.com/source/download.html
You need to install the Sun/Oracle JDK and then run
sudo update-alternatives --config java
Pick the newly installed version.

I thought I solve this error by reboot computer, make again and the error is gone by unknown reason. But now I just found myself very ridiculous when I try to start the emulator.
Need to re-source to make emulator run with correct environment, see here
xb#dnxb:~/Downloads/android_src/hole$ . build/envsetup.sh
xb#dnxb:~/Downloads/android_src/hole$ lunch aosp_bullhead-userdebug
Now run the emulator:
xb#dnxb:~/Downloads/android_src/hole$ emulator -sysdir out/target/product/generic/ -system out/target/product/generic/system.img -ramdisk out/target/product/generic/ramdisk.img -data out/target/product/generic/userdata.img -kernel prebuilts/qemu-kernel/arm/kernel-qemu-armv7 -memory 2048
emulator: ERROR: Can't access ANDROID_PRODUCT_OUT as '/home/xiaobai/Downloads/android_src/hole/out/target/product/bullhead'
You need to build the Android system before launching the emulator
xb#dnxb:~/Downloads/android_src/hole$
I just realized I only has /home/xiaobai/Downloads/android_src/hole/out/target/product/generic/, no such bullhead (Nexus 5X).
Now I know the reason why I success last time after reboot, this is because of it build with default generic lunch menu aosp_arm-eng, since I didn't redo the steps . build/envsetup.sh and lunch aosp_bullhead-userdebug before rerun make.
And I can see my /etc/environment has this JAVA_HOME set, so sudo update-alternatives --config java never work since /usr/lib/jvm/jdk1.8.0_131/ is Oracle/Sun, not Open JDK (my case is difference with OP, whether requires one of Oracle/Sun or OpenJDK depends on lunch menu):
$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$PATH"
JAVA_HOME="/usr/lib/jvm/jdk1.8.0_131/"
Modify the /etc/environment to openjdk path (In Ubuntu, it can be download with sudo apt-get install openjdk-8-jdk, then use dpkg -L openjdk-8-jdk to locate the path ), open a new tab shell session, redo the . build/envsetup.sh, lunch aosp_bullhead-userdebug, and make, now it works without jdk error.

Related

"Android target: avdmanager: Command failed with exit code 1" when running Meteor Android

I'm using Ubuntu 18.04.
I installed java 8, android studio and all dependencies listed here. When I run
meteor run android-device
I get the following error:
Your system does not yet seem to fulfill all requirements to build apps for Android.
Please follow the installation instructions in the mobile guide:
http://guide.meteor.com/mobile.html#installing-prerequisites
Status of the individual requirements:
✓ Java JDK
✓ Android SDK
✗ Android target: avdmanager: Command failed with exit code 1
✓ Gradle
java -version output:
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.18.04.1-b03)
OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)
javac -version output:
javac 1.8.0_212
I have tried both using AVD or a physical android phone but I get same error.
Another error I get by running AVD standalone is that AVD starts but the virtual phone screen remains black, never starts.
Provide a way to set $JAVA_HOME path.
On macOS 10.5
paste below code in your bash_profile (if you use bash)
#JAVA
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH
export CLASS_PATH=$JAVA_HOME/lib
Make config work
source ~/.bash_profile
Check variable
echo $JAVA_HOME
If you find there has some out message, good luck.
You have to set sdk path. Run below commands in your project console. Change ANDROID_HOME to your sdk path
export ANDROID_HOME="/home/Android/Sdk"
export PATH="${PATH}:${ANDROID_HOME}tools/:${ANDROID_HOME}platform-tools/"
After setting up the sdk path run below command to start your application in android emulator
meteor run android
JAVA_HOME path was wrongly set. I found this out by executing avdmanager from terminal (Android/SDK/tools/bin/avdmanager) and the error was more explicit there.

Android CyanogenMod source compilation error

I've successfully downloaded the CyanogenMod 10 source tree by syncing the latest repo. I've also installed the Java JDK properly and already set a ANDROID_JAVA_HOME variable but still getting those errors while executing this command "make -j4 otatools"
/bin/bash: prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/arm-linux-androideabi-gcc: Permission denied
/bin/bash: prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/arm-linux-androideabi-gcc: Permission denied
/bin/bash: prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/arm-linux-androideabi-gcc: Permission denied
/bin/bash: build/core/find-jdk-tools-jar.sh: Permission denied
build/core/config.mk:348: *** Error: could not find jdk tools.jar, please install JDK6, which you can download from java.sun.com. Stop.
I used these steps to register the downloaded version of Java as an alternative, and switching it to be used as the default
update-alternatives --install /usr/bin/java java /opt/jdk1.7.0_60/bin/java 1
update-alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_60/bin/javac 1
update-alternatives --set java /opt/jdk1.7.0_60/bin/java
update-alternatives --set javac /opt/jdk1.7.0_60/bin/javac
Output for java -version
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
Output for ANDROID_JAVA_HOME
echo $ANDROID_JAVA_HOME
/opt/jdk1.7.0_60/bin/
My Machine configuration is Debian Wheezy 64 bit with 4GB RAM
Errrrrrrrm, correct me if I'm wrong but looking at your update-alternatives, you are actually setting your Java version to JDK 7
First make sure you have actually Java 6 installed, then try running:
sudo update-alternatives --config java
You should see something like this:
Selection Pad Prioriteit Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 auto mode
1 /usr/lib/jvm/java-6-oracle/jre/bin/java 1 manual mode
Now type in the version you would like to use, for me that is : 1
type enter and then run java -version
Tell me if it worked!
EDIT: Whoops didn't even notice that this is a thread from 5 months ago...
Sorry for that!
Still Other people who have your problem could find my answer usefull though

Error to run Android Studio

I have installed Android Studio and I followed all steps described here
But when I start studio.sh I got an error with this message:
'tools.jar' is not in Android Studio classpath. Please ensure JAVA_HOME points to JDK rather than JRE
Can anyone here help me with this?
Check if your Java JDK is installed correctly
dpkg --list | grep -i jdk
If not, install JDK
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update && sudo apt-get install oracle-java8-installer
After the installation you have to enable the jdk
update-alternatives --display java
Check if Ubuntu uses Java JDK 8
java -version
If all went right the answer should be something like this:
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
Check what compiler is used
javac -version
It should show something like this
javac 1.8.0_91
Finally, add JAVA_HOME to the environment variable
Edit /etc/environment and add JAVA_HOME=/usr/lib/jvm/java-8-oracle to the end of the file
sudo nano /etc/environment
Append to the end of the file
JAVA_HOME=/usr/lib/jvm/java-8-oracle
You will then have to reboot, you can do this from the terminal with:
sudo reboot
In case you want to remove the JDK
sudo apt-get remove oracle-java8-installer
sudo apt-get install default-jdk
That's all in ubuntu 11
This is caused by having JAVA JRE installed as opposed to JAVA JDK.
The solution is simple:
sudo apt-get install openjdk-7-jdk
http://www.maxmakedesign.co.uk/development/2013/android-studio-tools-jar-classpath/
The error is self explanatory, you need to set your environment variable to JDK path instead of JRE here is it
JDK_HOME: C:\Program Files\Java\jdk1.7.0_07
check the path for linux
and here is possible duplicate Android Studio not working
Widows 7 64 bit.
JAVA_HOME point to my JRE (NOT JDK) directory
Coping of tools.jar from JDK\lib directory to ANDROIDSTUDIO\lib directory solve the problem
in OpenSuSE 13.1 and some 13.2 versions you also need to:
install java-1_7_0-openjdk-devel package
change the JAVA_HOME path when starting the studio:
For x86:
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0/ sh studio.sh
For x64:
JAVA_HOME=/usr/lib64/jvm/java-1.7.0-openjdk-1.7.0/ sh studio.sh
I had the same problem on a new installed Linux Mint 16. To fix this you just need to type command
sudo apt-get install openjdk-7-jdk
And that's it. You even do not need to add repositiries or creating JAVA_HOME in your environment.
On ubuntu I have tried all the methods that are described here but none worked.
What I did in the end was to:
download JDK from oracle, extract the archive
edit android-studio/bin/studio.sh and add at the top
export JAVA_HOME=/path/to/jdk
save the file and cd android-studio/bin and launch Android Studio: ./studio.sh
For me, running Fedora 22 with Gnome 16.2, this solution helped me.
In short, you should install the java-1.8.0-openjdk-devel, the development files of the JDK.
Open the Terminal and search for the latest version of the JDK development package:
$ dnf search jdk-devel
Last metadata expiration check performed 12:44:51 ago on Mon Aug 3 22:20:24 2015.
============================ N/S Matched: jdk-devel ============================
java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.8.0-openjdk-devel-debug.x86_64 : OpenJDK Development Environment with
: full debug on
$ sudo dnf install java-1.8.0-openjdk-devel
First check if the Java JDK is installed correctly:
dpkg --list | grep -i jdk
If not, install the JDK:
Download the latest version of the JDK from Oracle: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Extract it to the appropriate location in your machine. Get the extract location:
vi ~/.bashrc or vi ~./ bash_profile
JAVA_HOME=/home/user/installs/jdk1.7.0_40
PATH=$JAVA_HOME/bin
source ~/.bashrc or source ~/.bash_profile
After the installation you can check it:
java -version
which java
If all things are correct then the right the answer should be something like this:
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)
Append the following statement to studio.sh the file in android-studio/bin directory:
JAVA_HOME=/home/user/installs/jdk1.7.0_40
Finally start your Android Studio with the following command:
./studio.sh
The problem is a bug on Fedora 20. The bug is very odd: if I have Google Talk plugin installed then Eclipse crashes (https://bugs.eclipse.org/bugs/show_bug.cgi?id=334466). It's crazy for me. I thought that was Java version and with Java 6 my eclipse was still crashing. To solve this I should use gnome/GTK instead KDE. Now it works "well" (in gnome environment). Thanks for all answers.
I was facing similar problem on Windows 7 x64 professional edition. Please note following steps to fix this problem.
tools.jar is missing from required path if you are using jdk1.7 x64 bit version.
Please install x86 version of jdk1.7
Set JDK_HOME="C:\Program Files (x86)\Java\jdk1.7.0_67" and update path environment variable as path="C:\Program Files (x86)\Java\jdk1.7.0_67\bin"
Note: Linux put the proper path.
Launch 32 bit application from /android-studio\bin folder.
I tested and verified these steps on windows 7 with 32 bit jdk1.7
It's probably because you don't have jdk installed in your machine. I had exact same problem in first run. Open a terminal (CTRL+ALT+T) and type: sudo apt-get install openjdk-7-jdk
When done setup Java environment variable. Steps as follows:
sudo gedit /etc/environment
Either in the beginning or end of the file write: JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386 (location may vary depending on the installation of your Java)
export JAVA_HOME
save and exit editor.
Load the path variable again using the terminal: . /etc/environment
Couple of helpful links for further clarifications:
How to install JDK on Ubuntu (Linux)?
How to set JAVA_HOME for OpenJDK?
Hope this helps.
On Windows 7 just run the studio.bat file in your android-studio/bin folder with right click as an administrator. Now you get ask to import previous studio settings. Ignore this and on the next dialog you can specify the path to your jdk directory.
That's all.
Marcel
I ran into this issue when I was referencing
[drive]:\Program Files\Java\jdk1.8.0_65
in my JAVA_HOME environment var instead of the Android Studio recommended
[drive]:\Program Files\Java\jdk1.7.0_79.
I am using the x64 version of the JDK on Windows 10 Pro.
From the Android Studio installation instructions.
Before you set up Android Studio, be sure you have installed JDK 6 or higher (the JRE alone is not sufficient)—JDK 7 is required when developing for Android 5.0 and higher. To check if you have JDK installed (and which version), open a terminal and type javac -version. If the JDK is not available or the version is lower than version 6, download the Java SE Development Kit 7
http://developer.android.com/sdk/installing/index.html?pkg=studio
You have 2 things you must check:
verify that /etc/environment file has the correct JAVA_HOME and PATH values referring to your Java installation directory.
verify that you have the correct Java version (maybe you are using a distribution of Linux which need a server version of Java) you may need this version like my case JRE for server.
On my Linux Mint 17.3 install, I found these instructions incredibly helpful.
The problem seems to boil down to the system's default Java being OpenJDK and Android Studio preferring Oracle's JDK. I actually did not perform the OpenJDK removal steps given in the tutorial, but only downloaded the Oracle JDK and set it as my system's default. Android Studio worked right away.
In case the linked page ever goes away, the steps I took were
Download Oracle JDK. Mine was version 1.7.0_79.
tar -zxvf jdk-7u79-linux-x64.tar.gz
sudo mkdir -p /opt/java
sudo mv jdk1.7.0_79 /opt/java
sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/jdk1.7.0_79/bin/java" 1
sudo update-alternatives --set java /opt/java/jdk1.7.0_25/bin/java
and
java -version
confirms the system is using Oracle's JDK, giving output like
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

Compile Android source on Ubuntu 12.04 cannot continue because of bad JDK version

I've been trying all day to compile the Android source code on my Ubuntu 12.04 64bit OS.
For some reason, I'm stuck on the phase of having the Sun/Oracle JDK 1.6 version installed. I've been trying many commands (and the official link of course) and I end up either having nothing, having JDK 1.7 or OpenJDK, or not having the jdk-tools.
What are the exact steps to successfully compile the code (or part of it) using JDK? I'm stuck at the phase of "make j4" on this link.
installing the proper java version(1.6) for android do the below
1) Installing JDK
Since Sun JDK is no longer in Ubuntu’s main package repository, we have to manually install it in ubuntu 12.04 from oracle website
Please go the below link and download the JDK
http://www.oracle.com/technetwork/java/javase/downloads/jdk6-downloads-1637591.html
Follow the below steps to install the java and configuring it for the usage
$ chmod +x jdk-6u33-linux-x64.bin
$ sudo ./jdk-6u33-linux-x64.bin
$ sudo mv jdk1.6.0_33 /usr/lib/jvm/
$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_33/bin/java 1
$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_33/bin/javac 1
$ sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.6.0_33/bin/javaws 1
$ sudo update-alternatives --config java
$ sudo update-alternatives --config javac
$ sudo update-alternatives --config javaws
To verify the isntallation is proper do the belwo steps. It should now show that the Sun JDK is running instead of IcedTea
$ java -version
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03, mixed mode)
For compiling android on ubuntu 12.04 and installing the proper java version
visit http://www.embeddedcircle.com/android-compilation-in-ubuntu-12-04-lts-precise-for-pandaboard/
thanks
dino
In Ubuntu, when you download the jdk (32-bit version if it is for android programming, and in my opinion better the tar.gz than the .rpm one) it is important to 'install' and also to export using the commands you can see in the page of Oracle if I'm not wrong. You also need to go to your editor (Eclipse, Netbeans or which one?) and add the new Java platform to make sure you are using the version of the JDK you want to.To export means that you can compile the project when you want to.If not,you have to go to the java directory and inside the /bin folder do the command (probably with sudo at the beginning) to compile your project.
P.S.: You can find how to export here
I got this same problem. Some people reporting even JDK SE will see errors.
Another work-around is modifying two lines of source code, see here:
https://github.com/CyanogenMod/android_external_guava/commit/c8b97210aa31c9b80b5fd136d8617ebe4e731e09

How to build android project with openjdk on Ubuntu?

I found this Is Sun Java really necessary for using Android SDK on Ubuntu 10.10? I prefer OpenJDK but I can't build android project on Ubuntu. When I try:
$ ant debug
I got:
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar
...
BUILD FAILED
/home/kuba/projects/Android/android-sdk-linux/tools/ant/build.xml:651: The following error occurred while executing this line:
/home/kuba/projects/Android/android-sdk-linux/tools/ant/build.xml:672: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-6-openjdk/jre"
I have java version:
$ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.13) (6b20-1.9.13-0ubuntu1~10.10.1)
OpenJDK Client VM (build 19.0-b09, mixed mode, sharing)
Make sure you have the openjdk JDK installed. By default you probably only have the JRE installed. If you open Synaptic, search for openjdk and then you'll see both the JDK and the JRE. Select the JDK package and install. I think the actual packagename is openjdk-6-jdk.
or use the commandline
# sudo apt-get install openjdk-6-jdk
Android's official webpage reccomends the use of the official JDK from Sun/Oracle that you can download at http://www.oracle.com/technetwork/java/javase/downloads/index.html , the use of OpenJDK is unsupported and highly unrecommended.
You don't need to install the official JDK in your system, if this is what you are worring about, just download the *.bin version of the JDK of your choice ( i suggest the 1.6 version ), unpack everything by executing the *.bin in a terminal, and just modify 2 environment variable like this:
PATH , add the path to the jdk executables path_to_jdk/bin/ to your PATH
JAVA_HOME , set JAVA_HOME to the generic path of your jdk, NOT the bin or lib path, just as before without bin, only path_to_jdk/
you can modify this variables by editing the /etc/bash.bashrc or your local .bashrc, I suggest to edit the one under /etc
you also want to remove your actual OpenJDK from your system.
I've fixed same error (in Debian/Ubuntu) by installing gcj-jdk.
Before installing this package i had java-7-openjdk, but no tools.jar inside its directory.
After installing gcj-jdk I've located tools.jar and made a symlink to it inside directory where ant wants it to be.

Categories

Resources