织梦CMS - 轻松建站从此开始!

罗索

当前位置: 主页>嵌入式开发>Android>

How to Compile Android on Ubuntu (12.04)

落鹤生 发布于 2012-11-29 09:12 点击:次 
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
TAG:

  1. Wrong Java Version
  2. Installing the Sun Java 6 JDK in Ubuntu 12.04
  3. error: “_FORTIFY_SOURCE” redefined [-Werror]
  4. external/mesa3d/src/glsl/linker.cpp:1394:49: error: expected primary-expression before ‘,’ token

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:

Wrong Java Version

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
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
# $(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 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:

1
2
3
4
5
6
7
8
9
10
11
$ 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
$ 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.

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
HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0

to

1
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

1
2
3
4
5
6
7
$ sudo apt-get install gcc-4.4 g++-4.4 g++-4.4-multilib
$ sudo unlink /usr/bin/gcc
$ sudo ln -s /usr/bin/gcc-4.4 /usr/bin/gcc
$ sudo unlink /usr/bin/g++
$ sudo ln -s /usr/bin/g++-4.4 /usr/bin/g++

To reverse the changes when you’re done with them, reverse the instructions:

1
2
3
4
5
$ sudo unlink /usr/bin/gcc
$ sudo ln -s /usr/bin/gcc-4.6 /usr/bin/gcc
 
$ sudo unlink /usr/bin/g++
$ sudo ln -s /usr/bin/g++-4.6 /usr/bin/g++

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:

Android Emulator Ubuntu 12.04 (vrix)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201211/16400.html]
本文出处:CSDN博客 作者:vrix 原文
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容