I ran into a few errors when I tried to compile Android on my Ubuntu 12.04 64-bit laptop. Here are my notes on fixing them and compiling successfully:
“You are attempting to build with an unsupported version of java.”
Java 7 update: I ran into this problem recently while trying to build Android/Cyanogenmod on Arch Linux. brunch game me the following error:
|
1 2 3 4 5 6 7 8 9 |
Checking build tools versions... ************************************************************ You are attempting to build with an unsupported version of java. Your version is: java version "1.7.0_17". The correct version is: Java SE 1.6 or 1.7. |
To fix this, I changed line 129 from
|
1 2 3 |
ifeq ($(strip $(java_version)),) |
to
|
1 2 3 |
ifneq ($(strip $(java_version)),) |
and everything worked. It’s a bit of a hack, but as long as you have a usable version of Java SE, everything will work.
For Java 6 (original instructions): I have the Java 6 OpenJDK, version 1.6.0_24. This meets the android Java requirement for 1.6.0, but I found (later in the build process) that Android really needs to be built by Sun’s Java SDK. In the meantime, the _24 suffix doesn’t check out in Android’s makefile, which produces the error
You are attempting to build with the incorrect version of java
before exiting:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Checking build tools versions... ************************************************************ You are attempting to build with the incorrect version of java. Your version is: java version "1.6.0_24". The correct version is: Java SE 1.6. Please follow the machine setup instructions at http://source.android.com/source/download.html ************************************************************ build/core/main.mk:131: *** stop. Stop. |
Commenting out the $(error stop) statement from build/core/main.mk on line 131 will allow compilation to proceed:
|
131 132 133 134 |
# $(error stop) endif |
make will display the error message, but continue compiling. However, compiling with OpenJDK will probably create problems later in the build process (in out/target/common/obj/APPS/CtsVerifier_intermediates/classes-full-debug.jar). To fix the problems, Sun’s Java SDK will need to be installed.
Installing the Sun Java 6 JDK in Ubuntu 12.04
To fix the Android make error 41
|
1 2 3 |
make: *** [out/target/common/obj/APPS/CtsVerifier_intermediates/classes-full-debug.jar] Error 41 |
get the most recent Sun JDK from here. Once you’ve downloaded it, install it and run update-alternatives so your system uses the Sun JDK (instructions below are for my 64-bit system. Your number may also be different):
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$ chmod +x jdk-6u33-linux-x64.bin $ sudo ./jdk-6u33-linux-x64.bin $ sudo mv jdk1.6.0_32 /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 that the installation was successful, check Java’s version. It should now show that the Sun JDK is running instead of IcedTea:
|
1 2 3 4 5 6 |
$ 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) |
To revert the changes after Android has been compiled, run update-alternatives to switch back to OpenJDK.
Kernel source found, but no configuration was defined (Cyanogenmod)
This happened when I tried to build Cyanogenmod, a while after I successfully built Android using the AOSP code. This fix wasn’t necessary when I built an AOSP goldfish kernel setup.
|
1 2 3 4 5 6 7 8 9 |
No private recovery resources for TARGET_DEVICE generic build/core/tasks/kernel.mk:82: ********************************************************** build/core/tasks/kernel.mk:83: * Kernel source found, but no configuration was defined * build/core/tasks/kernel.mk:84: * Please add the TARGET_KERNEL_CONFIG variable to your * build/core/tasks/kernel.mk:85: * BoardConfig.mk file * build/core/tasks/kernel.mk:86: ********************************************************** make: *** No rule to make target `bacon'. Stop. |
To fix this, I added TARGET_KERNEL_CONFIG to the end of build/target/board/generic/BoardConfig.mk like so:
|
1 2 3 |
TARGET_KERNEL_CONFIG := cyanogenmod_goldfish_defconfig |
error: “_FORTIFY_SOURCE” redefined [-Werror]
This is a well-known error caused by the redefinition of _FORTIFY_SOURCE in build/core/combo/HOST_linux-x86.mk. It doesn’t happen on all systems. In fact, the error didn’t appear for most people in Ubuntu 11.04, but it started showing up after 11.10.
The error can be fixed by changing the HOST_GLOBAL_CFLAGS on line 56 from
|
1 2 3 |
HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0 |
to
|
1 2 3 |
HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 |
Undefining and redefining the _FORTIFY_SOURCE macro somehow fixes the issue. The “_FORTIFY_SOURCE redefined” error was initially discovered by a CyanogenMod developer.
external/mesa3d/src/glsl/linker.cpp:1394:49: error: expected primary-expression before ‘,’ token
I was compiling Android with gcc/g++ 4.6. This error can be solved by downgrading to gcc/g++4.4 systemwide, or just installing gcc/gcc++ 4.4 and specifying them while making.
|
1 2 3 |
$ sudo apt-get install gcc-4.4 g++-4.4 g++-4.4-multilib |
Then, override make’s default variables with
|
1 2 3 4 |
$ source build/envsetup.sh $ lunch CC=gcc-4.4 CXX=g++-4.4 make -j8 |
or
|
1 2 3 |
$ make CC=gcc-4.4 CXX=g++-4.4 -j4 |
If your system is like mine, Android should have compiled successfully. You can test the build by running the
emulator
command, which is automatically added to your path after compilation.
The result:
Incoming search terms:
the correct version is: java se 1 6
your version is: java version 1 6 0_24 the correct version is: java se 1 6
You are attempting to build with the incorrect version of java
build android ubuntu 12 04
ubuntu 12 04 android
java se 1 6 ubuntu
ubuntu 12 04 android build
Your version is: java version 1 6 0_24
your version is java version 1 6 0_24 the correct version is java se 1 6
the correct version is java se 1 6

Great post! Thanks a lot for putting this on your blog!
Thank you very much for the post mate. I tried to do this for ever. No other method worked thanks a lot!
Thanks for the post dude.
it helped me a lot.
Thank you very much. It’s very helpful.
A less intrusive way to use gcc-4.4 is to add the following to /etc/environment:
CC=gcc-4.4
CXX=g++-4.4
An alternative to that is during the
makeprocess, you can do:source build/envsetup.sh; lunch
CC=gcc-4.4 CXX=g++-4.4 make -j8
this will override the default variables for make
a more less intrusive way to uso gcc-4.4: compile with
make CC=gcc-4.4 CXX=g++-4.4 -j4
Pingback: U-boot, Linux Kernel, and Android Patches for Freescale i.MX6 HDMI TV Dongles