部署android开发环境总结
Ubuntu 14.04.5 LTS \n \l
android-4.0.1_r1

source build/envsetup.sh
choosecombo
选择 release, full, eng .

总体过程:
sudo apt-get install git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx-lts-trusty:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod 777 repo
mkdir ~/android
cd ~/android/
git config --global user.name "frank nie"
git config --global user.email "[email protected]"
repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
repo sync

安装JDK
./jdk-6u45-linux-x64.bin
在 ~/.profile 文件中添加:
#jdk, jre
export JAVA_HOME=$HOME/Java/jdk1.6.0_45
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

source build/envsetup.sh
choosecombo
make -j4
lunch 3
mmm packages/apps/Settings/
lunch
emulator

编译("make -j4")过程总遇到了很多问题:


sudo apt-get install git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
问题:
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
libgl1-mesa-glx:i386 : Depends: libglapi-mesa:i386 (= 10.1.3-0ubuntu0.6)
Recommends: libgl1-mesa-dri:i386 (>= 7.2)
unity-control-center : Depends: libcheese-gtk23 (>= 3.4.0) but it is not going to be installed
Depends: libcheese7 (>= 3.0.1) but it is not going to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

解决办法:
fnie@ubuntu14:~$ uname -r
4.4.0-124-generic
fnie@ubuntu14:~$ sudo lsb_release -a
[sudo] password for fnie:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty

sudo apt-get install libgl1-mesa-glx-lts-trusty:i386
sudo apt-get install git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx-lts-trusty:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so


frameworks/base/include/utils/KeyedVector.h:193:31: error: ‘indexOfKey’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
ssize_t i = indexOfKey(key);
^
解决办法:
1) 在 development/tools/emulator/opengl/Android.mk
Add '-fpermissive' 到25行:
EMUGL_COMMON_CFLAGS := -DWITH_GLES2 -fpermissive
2) vi frameworks/base/libs/utils/Android.mk
Add '-fpermissive' to line 64:
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive
3) vi frameworks/base/tools/aapt/Android.mk
Add '-fpermissive' to line 31:
LOCAL_CFLAGS += -Wno-format-y2k -fpermissive


frameworks/base/libs/rs/rsFont.cpp:224:76: required from here
frameworks/base/include/utils/KeyedVector.h:193:31: error: ‘indexOfKey’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
ssize_t i = indexOfKey(key);
^
frameworks/base/include/utils/KeyedVector.h:193:31: note: declarations in dependent base ‘android::KeyedVector’ are not found by unqualified lookup
frameworks/base/include/utils/KeyedVector.h:193:31: note: use ‘this->indexOfKey’ instead
make: [out/host/linux-x86/obj/STATIC_LIBRARIES/libRS_intermediates/rsFont.o] Error 1
make:
Waiting for unfinished jobs....
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Fix:
vi frameworks/base/libs/rs/Android.mk
Add '-fpermissive' to line 183
LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter -Wno-unused-variable -fpermissive


Can't locate Switch.pm in @INC (you may need to install the Switch module) (@INC contains: /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at external/webkit/Source/WebCore/make-hash-tools.pl line 23.
BEGIN failed--compilation aborted at external/webkit/Source/WebCore/make-hash-tools.pl line 23.
make: [out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/Source/WebCore/html/DocTypeStrings.cpp] Error 2
make:
Waiting for unfinished jobs....
target Generated: libwebcore <= external/webkit/Source/WebCore/html/parser/HTMLEntityNames.in

解决办法:
sudo apt-get install libswitch-perl


external/srec/tools/thirdparty/OpenFst/fst/lib/cache.h:132:26: note: declarations in dependent base ‘fst::VectorFstBaseImpl > >’ are not found by unqualified lookup
external/srec/tools/thirdparty/OpenFst/fst/lib/cache.h:132:26: note: use ‘this->SetState’ instead
external/srec/tools/thirdparty/OpenFst/fst/lib/cache.h:136:61: error: ‘SetState’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
SetState(cache_first_stateid, cache_firststate);
^
external/srec/tools/thirdparty/OpenFst/fst/lib/cache.h:136:61: note: declarations in dependent base ‘fst::VectorFstBaseImpl > >’ are not found by unqualified lookup
external/srec/tools/thirdparty/OpenFst/fst/lib/cache.h:136:61: note: use ‘this->SetState’ instead
host C: libESR_Shared <= external/srec/shared/src/lstring.c
:0:0: warning: "_FORTIFY_SOURCE" redefined [enabled by default]
:0:0: note: this is the location of the previous definition
host C: libESR_Shared <= external/srec/shared/src/LStringImpl.c
:0:0: warning: "_FORTIFY_SOURCE" redefined [enabled by default]
:0:0: note: this is the location of the previous definition
host C: libESR_Shared <= external/srec/shared/src/SessionTypeImpl.c
:0:0: warning: "_FORTIFY_SOURCE" redefined [enabled by default]
:0:0: note: this is the location of the previous definition
host C: libESR_Portable <= external/srec/portable/src/ArrayList.c
:0:0: warning: "_FORTIFY_SOURCE" redefined [enabled by default]
:0:0: note: this is the location of the previous definition
make: [out/host/linux-x86/obj/EXECUTABLES/grxmlcompile_intermediates/grxmlcompile.o] Error 1
make:
Waiting for unfinished jobs....

解决办法:
cd external/srec
wget "https://github.com/CyanogenMod/android_external_srec/commit/4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff"
patch -p1 < 4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff
rm -f 4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff
cd ../..


  1. dalvik/vm/native/dalvik_system_Zygote.cpp: In function ‘int setrlimitsFromArray(ArrayObject)’:
    dalvik/vm/native/dalvik_system_Zygote.cpp:193:19: error: aggregate ‘setrlimitsFromArray(ArrayObject
    )::rlimit rlim’ has incomplete type and cannot be defined
    struct rlimit rlim;
    ^
    dalvik/vm/native/dalvik_system_Zygote.cpp:216:43: error: ‘setrlimit’ was not declared in this scope
    err = setrlimit(contents[0], &rlim);
    ^
    make: [out/host/linux-x86/obj/SHARED_LIBRARIES/libdvm_intermediates/native/dalvik_system_Zygote.o] Error 1
    make:
    Waiting for unfinished jobs....

解决办法: 添加头文件 #include 到以下文件 dalvik/vm/native/dalvik_system_Zygote.cpp


development/tools/emulator/opengl/host/tools/emugen/main.cpp:92:45: error: ‘optind’ was not declared in this scope
std::string baseName = std::string(argv[optind]);

解决办法: vi development/tools/emulator/opengl/host/tools/emugen/main.cpp
Add '#include ' to list of includes: #include


:0:0: warning: "_FORTIFY_SOURCE" redefined [enabled by default]
:0:0: note: this is the location of the previous definition
host C: mkyaffs2image <= external/yaffs2/yaffs2/yaffs_tagsvalidity.c
host Prebuilt: monkeyrunner (out/host/linux-x86/obj/EXECUTABLES/monkeyrunner_intermediates/monkeyrunner)
host C++: obbtool <= frameworks/base/tools/obbtool/Main.cpp
:0:0: warning: "_FORTIFY_SOURCE" redefined [enabled by default]
:0:0: note: this is the location of the previous definition
:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror]
:0:0: note: this is the location of the previous definition
In file included from external/yaffs2/yaffs2/yaffs_tagsvalidity.c:17:0:
external/yaffs2/yaffs2/yaffs_tagsvalidity.h:23:6: warning: redundant redeclaration of ‘yaffs_InitialiseTags’ [-Wredundant-decls]
void yaffs_InitialiseTags(yaffs_ExtendedTags tags);
^
In file included from external/yaffs2/yaffs2/yaffs_tagsvalidity.h:21:0,
from external/yaffs2/yaffs2/yaffs_tagsvalidity.c:17:
external/yaffs2/yaffs2/yaffs_guts.h:888:6: note: previous declaration of ‘yaffs_InitialiseTags’ was here
void yaffs_InitialiseTags(yaffs_ExtendedTags
tags);
^
host C: parseStringTest <= external/srec/tools/parseStringTest/parseStringTest.c
cc1plus: all warnings being treated as errors
make: [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] Error 1
make:
Waiting for unfinished jobs....
:0:0: warning: "_FORTIFY_SOURCE" redefined [enabled by default]
:0:0: note: this is the location of the previous definition

解决办法:
在 build/core/comb/HOST_linux_x86.mk 文件中找到下面这句:
HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
替换成为:
HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0


        ^

external/llvm/lib/ExecutionEngine/JIT/Intercept.cpp: In constructor ‘{anonymous}::StatSymbols::StatSymbols()’:
external/llvm/lib/ExecutionEngine/JIT/Intercept.cpp:69:67: error: ‘lseek64’ was not declared in this scope
sys::DynamicLibrary::AddSymbol("\x1lseek64", (void*)(intptr_t)lseek64);
^
make: [out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMJIT_intermediates/Intercept.o] Error 1
make:
Waiting for unfinished jobs....

解决方案:

在external/llvm/lib/ExecutionEngine/JIT/Intercept.cpp中添加头文件
#define _LARGEFILE64_SOURCE
#include
#include
#include
#include
#include
#include
#include
#include


In file included from :0:0:
./system/core/include/arch/linux-x86/AndroidConfig.h:164:0: note: this is the location of the previous definition
#define _LARGEFILE_SOURCE 1
^
host C: mke2fs_host <= external/e2fsprogs/misc/default_profile.c
host C++: opannotate <= external/oprofile/pp/common_option.cpp
host C++: opannotate <= external/oprofile/pp/opannotate.cpp
host C++: opannotate <= external/oprofile/pp/opannotate_options.cpp
host C++: liboprofile_pp <= external/oprofile/libpp/arrange_profiles.cpp
In file included from external/oprofile/libpp/arrange_profiles.cpp:24:0:
external/oprofile/libpp/format_output.h:94:22: error: reference ‘counts’ cannot be declared ‘mutable’ [-fpermissive]
mutable counts_t & counts;
^
host C++: liboprofile_pp <= external/oprofile/libpp/callgraph_container.cpp
make: [out/host/linux-x86/obj/STATIC_LIBRARIES/liboprofile_pp_intermediates/arrange_profiles.o] Error 1
make:
Waiting for unfinished jobs....

解决办法: vi external/oprofile/libpp/format_output.h
Remove 'mutable' from 'mutable counts_t & counts;' on line 94:


/usr/bin/ld: out/host/linux-x86/obj/EXECUTABLES/emulator_renderer_intermediates/main.o: undefined reference to symbol 'XInitThreads'
//usr/lib/i386-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: [out/host/linux-x86/obj/EXECUTABLES/emulator_renderer_intermediates/emulator_renderer] Error 1
make:
Waiting for unfinished jobs....
true

解决办法:
修改 development/tools/emulator/opengl/host/renderer/Android.mk 文件
vi development/tools/emulator/opengl/host/renderer/Android.mk

添加一行:LOCAL_LDLIBS += -lX11



Question:
/usr/bin/ld: cannot find -lz
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt] Error 1

Answer:

sudo apt-get install lib32z1-dev
sudo apt-get install zlib1g-dev
sudo apt-get install lib64z1-dev


external/llvm/include/llvm/ADT/PointerUnion.h:59:39: error: comparison between ‘enum llvm::PointerLikeTypeTraits>::’ and ‘enum llvm::PointerLikeTypeTraits>::’ [-Werror=enum-compare]
In file included from external/llvm/include/llvm/Operator.h:19:0,
from external/llvm/include/llvm/Analysis/ScalarEvolution.h:27,
from external/llvm/include/llvm/LinkAllPasses.h:26,
from frameworks/compile/slang/slang.cpp:55:
external/llvm/include/llvm/Constants.h: In static member function ‘static llvm::Constant llvm::ConstantExpr::getGetElementPtr(llvm::Constant, llvm::Constant const, unsigned int, bool)’:
external/llvm/include/llvm/Constants.h:793:41: error: cast from type ‘llvm::Constant const’ to type ‘llvm::Value’ casts away qualifiers [-Werror=cast-qual]
return getGetElementPtr(C, (Value
)IdxList, NumIdx, InBounds);
^
cc1plus: all warnings being treated as errors
make: [out/host/linux-x86/obj/STATIC_LIBRARIES/libslang_intermediates/slang_backend.o] Error 1
make:
Waiting for unfinished jobs....
cc1plus: all warnings being treated as errors
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libslang_intermediates/slang.o] Error 1

Fix:
vi frameworks/compile/slang/Android.mk
Remove '-Werror' from line 22:
local_cflags_for_slang := -Wno-sign-promo -Wall -Wno-unused-parameter


In file included from external/gtest/src/../include/gtest/gtest-param-test.h:158:0,
from external/gtest/src/../include/gtest/gtest.h:69,
from external/gtest/src/../src/gtest.cc:34,
from external/gtest/src/gtest-all.cc:36:
external/gtest/src/../include/gtest/internal/gtest-param-util-generated.h: In instantiation of ‘testing::internal::ValueArray2::operator testing::internal::ParamGenerator() const [with T = bool; T1 = bool; T2 = bool]’:
external/gtest/src/../include/gtest/gtest-param-test.h:1185:28: required from here
external/gtest/src/../include/gtest/internal/gtest-param-util-generated.h:77:26: error: ‘ValuesIn’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
return ValuesIn(array);
^
In file included from external/gtest/src/../include/gtest/gtest.h:69:0,
from external/gtest/src/../src/gtest.cc:34,
from external/gtest/src/gtest-all.cc:36:
external/gtest/src/../include/gtest/gtest-param-test.h:287:58: note: ‘template testing::internal::ParamGenerator testing::ValuesIn(const Container&)’ declared here, later in the translation unit
internal::ParamGenerator ValuesIn(
^
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libgtest_host_intermediates/gtest-all.o] Error 1

Two fixes required:
1)
vi external/gtest/src/Android.mk

Add '-fpermissive' to lines 52 and 70 (both lines contain same info)
LOCAL_CFLAGS += -O0 -fpermissive

2)
vi external/gtest/include/gtest/internal/gtest-param-util.h

Add '#include ' to list of includes as shown:
#include
#include
#include


/home/fnie/android/external/llvm/lib/Support/Threading.cpp:96: undefined reference to pthread_create'
/home/fnie/android/external/llvm/lib/Support/Threading.cpp:100: undefined reference to
pthread_join'
/home/fnie/android/external/llvm/lib/Support/Threading.cpp:91: undefined reference to pthread_attr_setstacksize'
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o): In function
llvm::sys::MutexImpl::MutexImpl(bool)':
/home/fnie/android/external/llvm/lib/Support/Mutex.cpp:69: undefined reference to pthread_mutexattr_init'
/home/fnie/android/external/llvm/lib/Support/Mutex.cpp:75: undefined reference to
pthread_mutexattr_settype'
/home/fnie/android/external/llvm/lib/Support/Mutex.cpp:80: undefined reference to pthread_mutexattr_setpshared'
/home/fnie/android/external/llvm/lib/Support/Mutex.cpp:89: undefined reference to
pthread_mutexattr_destroy'
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o): In function llvm::sys::MutexImpl::tryacquire()':
/home/fnie/android/external/llvm/lib/Support/Mutex.cpp:143: undefined reference to
pthread_mutex_trylock'
collect2: error: ld returned 1 exit status
make: [out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader] Error 1
make:
Waiting for unfinished jobs....
true
elapsed seconds: 209
wrote generated Main_*.java files to out/host/linux-x86/obj/EXECUTABLES/vm-tests_intermediates/main_files

Fix:

vi external/llvm/llvm-host-build.mk
LOCAL_LDLIBS := -lpthread -ldl


终于编译成功:
Done!
Install: out/target/product/generic/system/app/Phone.odex
Install: out/target/product/generic/system/app/Phone.apk
'out/target/common/obj/APPS/Settings_intermediates//classes.dex' as 'classes.dex'...
Processing target/product/generic/obj/APPS/Settings_intermediates/package.apk
Done!
Install: out/target/product/generic/system/app/Settings.odex
Install: out/target/product/generic/system/app/Settings.apk
Finding NOTICE files: out/target/product/generic/obj/NOTICE_FILES/hash-timestamp
Combining NOTICE files: out/target/product/generic/obj/NOTICE.html
Installed file list: out/target/product/generic/installed-files.txt
Target system fs image: out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.img
Install system fs image: out/target/product/generic/system.img


fnie@ubuntu14:~/android$ emulaotr
emulaotr: command not found

fnie@ubuntu14:~/android$ source build/envsetup.sh
including device/samsung/maguro/vendorsetup.sh
including device/samsung/tuna/vendorsetup.sh
including device/ti/panda/vendorsetup.sh
including sdk/bash_completion/adb.bash

fnie@ubuntu14:~/android$ lunch 3


PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.0.1
TARGET_PRODUCT=vbox_x86
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=x86
TARGET_ARCH_VARIANT=x86
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=ITL41D


fnie@ubuntu14:~/android$ mmm packages/apps/Settings/


PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.0.1
TARGET_PRODUCT=vbox_x86
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=x86
TARGET_ARCH_VARIANT=x86
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=ITL41D


make: Entering directory /home/fnie/android'
target Package: Settings (out/target/product/vbox_x86/obj/APPS/Settings_intermediates/package.apk)
'out/target/common/obj/APPS/Settings_intermediates//classes.dex' as 'classes.dex'...
Notice file: packages/apps/Settings/NOTICE -- out/target/product/vbox_x86/obj/NOTICE_FILES/src//system/app/Settings.apk.txt
Install: out/target/product/vbox_x86/system/app/Settings.apk
Copying: out/target/common/obj/APPS/SettingsTests_intermediates/classes-jarjar.jar
Copying: out/target/common/obj/APPS/SettingsTests_intermediates/emma_out/lib/classes-jarjar.jar
Copying: out/target/common/obj/APPS/SettingsTests_intermediates/classes.jar
Copying: out/target/common/obj/APPS/SettingsTests_intermediates/noproguard.classes.jar
target Dex: SettingsTests
Copying: out/target/common/obj/APPS/SettingsTests_intermediates/noproguard.classes.dex
target Package: SettingsTests (out/target/product/vbox_x86/obj/APPS/SettingsTests_intermediates/package.apk)
'out/target/common/obj/APPS/SettingsTests_intermediates//classes.dex' as 'classes.dex'...
Install: out/target/product/vbox_x86/data/app/SettingsTests.apk
make: Leaving directory
/home/fnie/android'

fnie@ubuntu14:~/android$ lunch

You're building on Linux

Lunch menu... pick a combo:

  1. full-eng
  2. full_x86-eng
  3. vbox_x86-eng
  4. full_maguro-userdebug
  5. full_tuna-userdebug
  6. full_panda-eng

Which would you like? [full-eng] 1


PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.0.1
TARGET_PRODUCT=full
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=ITL41D


fnie@ubuntu14:~/android$ emulator
emulator: WARNING: system partition size adjusted to match image file (163 MB > 66 MB)