Friday, June 15, 2012

Compile Android 4.0 on Ubuntu 11.10

1、基础环境配置
sudo apt-get install ant ant-optional bison build-essential ca-certificates-java curl flex fusesmb g++-4.4-multilib g++-multilib gcc-4.4-multilib gcc-multilib git-core git-gui gitk gnuit gnupg gperf ia32-libs lib32ncurses5-dev libreadline-gplv2-dev lib32readline-gplv2-dev lib32z1 lib32z1-dev libc6-dev-i386 libesd0-dev libmotif4 libncurses5-dev  libsasl2-modules-gssapi-mit libsdl1.2-dev libx11-dev meld menu tsocks valgrind vim x11proto-core-dev zip zlib1g-dev

2、编译错误
1)
错误日志1
host C++: libutils <= frameworks/base/libs/utils/RefBase.cpp
frameworks/base/libs/utils/RefBase.cpp: In member function ‘void android::RefBase::weakref_type::trackMe(bool, bool)’:
frameworks/base/libs/utils/RefBase.cpp:483:67: error: passing ‘const android::RefBase::weakref_impl’ as ‘this’ argument of ‘void android::RefBase::weakref_impl::trackMe(bool, bool)’ discards qualifiers [-fpermissive]
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/RefBase.o] 错误 1

错误日志2
In file included from external/oprofile/libpp/arrange_profiles.cpp:24:0:
external/oprofile/libpp/format_output.h:94:22: 错误: reference ‘counts’ cannot be declared ‘mutable’ [-fpermissive]
错误日志3
In file included from external/oprofile/pp/opreport.cpp:32:0: external/oprofile/libpp/format_output.h:94:22: 错误: reference ‘counts’ cannot be declared ‘mutable’ [-fpermissive] In file included from external/oprofile/libpp/xml_utils.h:15:0,                  from external/oprofile/pp/opreport_options.cpp:26: external/oprofile/libpp/format_output.h:94:22: 错误: reference ‘counts’ cannot be declared ‘mutable’ [-fpermissive] 

解决方法:
修改 gedit frameworks/base/libs/utils/Android.mk
将:
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)
改为:
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive

修改文件
external/oprofile/libpp/Android.mk
external/oprofile/pp/Android.mk
将
LOCAL_CFLAGS := $(common_host_cflags)
改为
LOCAL_CFLAGS := $(common_host_cflags) -fpermissive

或者修改build/core/combo/HOST_linux-x86.mk
给HOST_GLOBAL_CFLAGS加上 -fpermissive

2)链接错误
错误日志1
system/core/libcutils/threads.c:27: undefined reference to ‘pthread_getspecific'
out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_set':
system/core/libcutils/threads.c:36: undefined reference to ’pthread_key_create'
system/core/libcutils/threads.c:44: undefined reference to ‘pthread_setspecific'
collect2: ld 返回 1
make: *** [out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt] 错误 1
错误日志2
out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_get':
system/core/libcutils/threads.c:27: undefined reference to `pthread_getspecific'
out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_set':
system/core/libcutils/threads.c:36: undefined reference to `pthread_key_create'
system/core/libcutils/threads.c:44: undefined reference to `pthread_setspecific'
collect2: true
Generating libraries.cc
python out/host/linux-x86/obj/EXECUTABLES/mksnapshot_intermediates/js2c.py out/host/linux-x86/obj/EXECUTABLES/mksnapshot_intermediates/libraries.cc out/host/linux-x86/obj/EXECUTABLES/mksnapshot_intermediates/libraries-empty.cc CORE external/v8/src/runtime.js external/v8/src/v8natives.js external/v8/src/array.js external/v8/src/string.js external/v8/src/uri.js external/v8/src/math.js external/v8/src/messages.js external/v8/src/apinatives.js external/v8/src/date.js external/v8/src/regexp.js external/v8/src/json.js external/v8/src/mirror-debugger.js external/v8/src/debug-debugger.js external/v8/src/macros.py
ld 返回 1
make: *** [out/host/linux-x86/obj/EXECUTABLES/localize_intermediates/localize] 错误 1
make: *** 正在等待未完成的任务....
解决方法:
修改make文件
frameworks/base/tools/aapt/Android.mk
frameworks/base/tools/localize/Android.mk
将这几句
ifeq ($(HOST_OS),linux)
LOCAL_LDLIBS += -lrt
endif
改为
ifeq ($(HOST_OS),linux)
LOCAL_LDLIBS += -lrt -lpthread
endif
3)
错误日志
<命令行>:0:0: 错误: “_FORTIFY_SOURCE”重定义 [-Werror]
解决方法
修改build/core/combo/HOST_linux-x86.mk
将
HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
改为
HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0

android 4.0编译错误


1、
************************************************************
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
************************************************************
解决方法:
安装java 1.6
在envsetup.sh
最后加入设置环境变量export JAVA_HOME=/usr/local/arm/jdk1.6.0_31
不
2.
错误2
(ir_dereference_variable*)’ [-Woverloaded-virtual]
external/mesa3d/src/glsl/linker.cpp: In function ‘void
assign_varying_locations(gl_shader_program*, gl_shader*, gl_shader*)’:
external/mesa3d/src/glsl/linker.cpp:1394:49: error: expected primary-
expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1394:50: error: ‘varyings’ was not
declared in this scope
external/mesa3d/src/glsl/linker.cpp:1394:58: error: ‘offsetof’ was not
declared in this scope
external/mesa3d/src/glsl/linker.cpp:1395:48: error: expected primary-
expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1412:47: error: expected primary-
expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1412:48: error: ‘position’ was not
declared in this scope
external/mesa3d/src/glsl/linker.cpp:1414:47: error: expected primary-
expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1414:48: error: ‘pointSize’ was
not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1424:47: error: expected primary-
expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1424:48: error: ‘position’ was not
declared in this scope
external/mesa3d/src/glsl/linker.cpp:1428:47: error: expected primary-
expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1428:48: error:
‘frontFacingPointCoord’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1431:47: error: expected primary-
expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1431:48: error:
‘frontFacingPointCoord’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp: In function ‘void
link_shaders(const gl_context*, gl_shader_program*)’:
external/mesa3d/src/glsl/linker.cpp:1734:49: error: expected primary-
expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1734:50: error: ‘fragColor’ was
not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1734:59: error: ‘offsetof’ was not
declared in this scope
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/
libMesa_intermediates/src/glsl/linker.o] Error 1

解决方法:
把 "#include <stddef.h>" 添加到 linker.cpp 文件头部。

3.
external/oprofile/libpp/format_output.h:94:22: error: reference a€?countsa€? cannot be declared a€?mutablea€? [-fpermissive]
In file included from external/oprofile/libpp/arrange_profiles.cpp:24:0:
external/oprofile/libpp/format_output.h:94:22: error: reference a€?countsa€? cannot be declared a€?mutablea€? [-fpermissive]
In file included from external/oprofile/libpp/format_output.cpp:26:0:
external/oprofile/libpp/format_output.h:94:22: error: reference a€?countsa€? cannot be declared a€?mutablea€? [-fpermissive]
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/liboprofile_pp_intermediates/op_header.o] Error 1
make: *** Waiting for unfinished jobs....
In file included from external/oprofile/libpp/xml_utils.h:15:0,
                 from external/oprofile/libpp/xml_utils.cpp:14:
external/oprofile/libpp/format_output.h:94:22: error: reference a€?countsa€? cannot be declared a€?mutablea€? [-fpermissive]
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/liboprofile_pp_intermediates/xml_utils.o] Error 1
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/liboprofile_pp_intermediates/arrange_profiles.o] Error 1
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/liboprofile_pp_intermediates/format_output.o] Error 1
解决方法:
需要修改external/oprofile/libpp/format_output.h:94行
mutable counts_t & counts为
counts_t & counts

 4.
 frameworks/compile/slang/slang_rs_export_foreach.cpp:249:23: error: variable a€?ParamNamea€? set but not used [-Werror=unused-but-set-variable
 解决方法:

 Fix/Workaround:
frameworks/compile/slang/Android.mk
-local_cflags_for_slang := -Wno-sign-promo -Wall -Wno-unused-parameter -Werror
+local_cflags_for_slang := -Wno-sign-promo -Wall -Wno-unused-parameter
5.
external/gtest/src/../include/gtest/internal/gtest-param-util.h:122:11: error: a€?ptrdiff_ta€? does not name a typ
解决方法:
$vi external/gtest/src/../include/gtest/internal/gtest-param-util.h
+#include <cstddef>

[Solved]external/mesa3d/src/glsl/linker.cpp:1394:49: error: expected primary-expression before ‘,’ token


在编译android4.0.3的时候,出现了如下错误,导致编译不能正常进行:
frameworks/base/tools/obbtool/Main.cpp <comand line>:0:0: error: “_FORTIFY_SOURCE”redefined [-Werror]
external/mesa3d/src/glsl/linker.cpp:1394:49: error: expected primary-expression before ‘,’ token
这是因为使用的编译器版本过高,
gcc  ----> 4.6
g++------>4.6
所以我们需要使用地版本的4.4来解决这个问题:
sudo apt-get install gcc-4.4 g++-4.4 g++-4.4-multilib
然后切换回4.4就好了。

[Solved]error: "_FORTIFY_SOURCE" redefined [-Werror]


<command-line>:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror]
 <built-in>:0:0: note: this is the location of the previous definition
 cc1plus: all warnings being treated as errors
make: *** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] Error 1
此处编译错误是由于ubuntu 11.10采用了GCC4.6.1导致的。
解决方法:
修改源码目录下/build/core/combo/HOST_linux-x86.mk文件:
将以下语句
HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
修改为
HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0

Solutions to Android Compiling Errors


首先,我们先安装一些常用的工具
curl: 
sudo  apt-get  install  curl
git: sudo  apt-get  install  git
g++: sudo  apt-get  install  g++

然后,make遇到缺什么就安装什么

/usr/bin/ld: cannot find -lz
host Executable: aapt (out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt)
/usr/bin/ld: cannot find -lz
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt] Error 1
解决方法: sudo apt-get install zlib1g-dev    sudo apt-get install lib64z1-dev
/bin/bash: bison: command not found
Yacc: aidl <= frameworks/base/tools/aidl/aidl_language_y.y
bison -d  -o out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp frameworks/base/tools/aidl/aidl_language_y.y
/bin/bash: bison: command not found
make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp] Error 127
解决方法:sudo apt-get install bison

/bin/bash: flex: command not found
out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp: In function ‘int yyparse()’:
out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp:1827: warning: deprecated conversion from string constant to ‘char*’
out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp:1970: warning: deprecated conversion from string constant to ‘char*’
Lex: aidl <= frameworks/base/tools/aidl/aidl_language_l.l
/bin/bash: flex: command not found
make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp] Error 127
解决方法: sudo apt-get install flex

/usr/bin/ld: cannot find -lncurses
host Executable: adb (out/host/linux-x86/obj/EXECUTABLES/adb_intermediates/adb)
/usr/bin/ld: cannot find -lncurses
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/adb_intermediates/adb] Error 1
解决方法:sudo apt-get install libncurses5-dev

fatal error: GL/glx.h: No such file or directory
development/tools/emulator/opengl/host/libs/Translator/GLcommon/GLDispatch.cpp:22: fatal error: GL/glx.h: No such file or directory
compilation terminated.
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libGLcommon_intermediates/GLDispatch.o] Error 1
解决方法:sudo apt-get install libgl1-mesa-dev

sh: gperf: not found
target Generated: libwebcore <= external/webkit/Source/JavaScriptCore/create_regex_tables
Generating CSSPropertyNames.h <= CSSPropertyNames.in
sh: gperf: not found
calling gperf failed: 32512 at ./makeprop.pl line 140.
make: *** [out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/Source/WebCore/css/CSSPropertyNames.h] Error 25
make: *** Deleting file `out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/Source/WebCore/css/CSSPropertyNames.h'
解决方法:sudo apt-get install gperf

Tuesday, June 12, 2012

[Solved]fatal: HTTP request failed

Problem: when trying to initiate a repository using repo, getting an error of "fatal: HTTP request failed ", even though you do exactly the same as the instructions.

Reason: Google's fault !!!

Solution: Close your current terminal, re-open it and try the same command again. It works!!!

[Solved]Package sun-java6-jdk is not available, but is referred to by another package.

Problem: Package sun-java6-jdk is not available, but is referred to by another package.

Reason: The sun-java6-jdk is no longer in ubuntu's main repository, or in canonical-archive repository, (which you are suggested on Android website.)

Solution: Use ppa

Command:

                   sudo add-apt-repository ppa:ferramroberto/java
                   sudo apt-get update
                   sudo apt-get install sun-java6-jdk

Switch between different versions of jdk
                   sudo update-alternatives --config java

Then choose the one you'd like.

Enjoy!