由于在windows下开发luncher比较麻烦,决定转到在linux下开发,自己编译源码。
以下是安装过程中遇到的问题,需要一一解决:
干脆把下面的环境都安装:
一个一个安装,如果已经安装了,ubuntu会自己提示已经安装
1、
Android can only be built by versions 3.81 and 3.82
删除高版本的make 4.0.8,编译安装低版本make 3.81
下载make 3.81源码
参考make下的README和INSTALL文件,安装make 3.81
2、 JDK发布方和版本问题
You are attempting to build with an unsupported JDK.
You use OpenJDK but only Sun/Oracle JDK is supported.
卸载OpenJDK apt-get remove openjdk*
安装Sun/Oracle JDK
http://blog.csdn.net/tecn14/article/details/24797545 方法
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html#jdk-6u45-oth-JPR 下载JDK6地址
下面开始安装jdk:
在把jdk安装在/usr/lib/jdk下面,
终端下进入你存放jdk-6u37-linux-x64.bin的/home/wr/software/
$sudo chmod 777 jdk-6u37-linux-x64.bin // 将文件赋于运行权限
$ sudo -s ./jdk-6u37-linux-x64.bin /usr/lib/jdk
解出来还是在/home/wr/software/目录下,不纠结于此,直接配置环境变量:
etc/environment :
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/wr/software/jdk1.6.0_45/bin"
CLASSPATH="/home/wr/software/jdk1.6.0_45/lib:."
JAVA_HOME="/home/wr/software/jdk1.6.0_45/"
3、 i686-linux-gcc问题
漏掉了gcc相关包
安装gcc-multilib
4、 libz.so
/home/wr/Android/android_kitkat/prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6/bin/../lib/gcc/i686-linux/4.6.x-google/../../../../i686-linux/bin/as: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
没有安装libz.so.1相关的工具包
安装apt-file : sudo apt-get install apt-file
然后apt-file update
apt-file search libz.so
:
lib32z1: /usr/lib32/libz.so.1
lib32z1: /usr/lib32/libz.so.1.2.8
lib32z1-dev: /usr/lib32/libz.so
libx32z1: /usr/libx32/libz.so.1
libx32z1: /usr/libx32/libz.so.1.2.8
libx32z1-dev: /usr/libx32/libz.so
zlib1g: /lib/x86_64-linux-gnu/libz.so.1
zlib1g: /lib/x86_64-linux-gnu/libz.so.1.2.8
zlib1g-dev: /usr/lib/x86_64-linux-gnu/libz.so
依次安装lib32z1 ib32z1-dev lsb-build-base3 zlib1g-dbg等等
5、
Yacc: aidl <= frameworks/base/tools/aidl/aidl_language_y.y
prebuilts/misc/linux-x86/bison/bison -d -o out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp frameworks/base/tools/aidl/aidl_language_y.y
make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp] 断开的管道
解决:
sudo apt-get install bison
6、
Lex: aidl <= frameworks/base/tools/aidl/aidl_language_l.l
/bin/bash: flex: 未找到命令
make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp] 错误 127
解决:
sudo apt-get install flex
7、
File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
make: *** [out/target/product/generic/obj/GYP/shared_intermediates/blink/CSSPropertyNames.cpp] 错误 1
确认并安装了以下环境:
git gnupg flex bison gperf build-essential zip curl libc6-dev x11proto-core-dev g++-multilib tofrodos python-markdown libxml2-utils xsltproc
确认漏装了:
gperf build-essential x11proto-core-dev g++-multilib tofrodos python-markdown libxml2-utils xsltproc
http://blog.chinaunix.net/uid-25737580-id-3150901.html
编译完成后,在source目录下会生成一个out文件夹,在out/target/product/generic/下是生成的system.img,ramdisk.img,userdata.img.
00
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.4
TARGET_PRODUCT=full
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a
TARGET_CPU_VARIANT=generic
HOST_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.16.0-28-generic-x86_64-with-Ubuntu-14.10-utopic
HOST_BUILD_TYPE=release
BUILD_ID=KRT16S
OUT_DIR=out
============================================
编译好后,进入模拟器
http://jingyan.baidu.com/article/86112f13549b44273797872c.html
source build/envsetup.sh
lunch
1
emulator
android----android4.2编译
编译环境的安装
1.安装先到官方网站下载一个jdk6的安装包
我的系统为ubuntu12.0464位,对应自己系统下载好了
2.配置jdk
编辑~/.bashrc 添加
export PATH=~/bin:$PATH
export JAVA_HOME=~/bin/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 ~/.bashrc 使之生效
3.按照官网指导
Installing required packages (Ubuntu 12.04)
Building on Ubuntu 12.04 is currently only experimentally supported and is not guaranteed to work on branches other than master.
<code style="line-height: 14px;"><span class="pln" style="color: rgb(0, 0, 0);">$ sudo apt</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="kwd" style="color: rgb(0, 0, 136);">get</span><span class="pln" style="color: rgb(0, 0, 0);"> install git gnupg flex bison gperf build</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">essential </span><span class="pun" style="color: rgb(102, 102, 0);">\</span><span class="pln" style="color: rgb(0, 0, 0);"> zip curl libc6</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">dev libncurses5</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">dev</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln" style="color: rgb(0, 0, 0);">i386 x11proto</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">core</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">dev </span><span class="pun" style="color: rgb(102, 102, 0);">\</span><span class="pln" style="color: rgb(0, 0, 0);"> libx11</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">dev</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln" style="color: rgb(0, 0, 0);">i386 libreadline6</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">dev</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln" style="color: rgb(0, 0, 0);">i386 libgl1</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">mesa</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">glx</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln" style="color: rgb(0, 0, 0);">i386 </span><span class="pun" style="color: rgb(102, 102, 0);">\</span><span class="pln" style="color: rgb(0, 0, 0);"> libgl1</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">mesa</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">dev g</span><span class="pun" style="color: rgb(102, 102, 0);">++-</span><span class="pln" style="color: rgb(0, 0, 0);">multilib mingw32 tofrodos </span><span class="pun" style="color: rgb(102, 102, 0);">\</span><span class="pln" style="color: rgb(0, 0, 0);"> python</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">markdown libxml2</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">utils xsltproc zlib1g</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">dev</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln" style="color: rgb(0, 0, 0);">i386 $ sudo ln </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">s </span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="pln" style="color: rgb(0, 0, 0);">usr</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="pln" style="color: rgb(0, 0, 0);">lib</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="pln" style="color: rgb(0, 0, 0);">i386</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">linux</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">gnu</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="pln" style="color: rgb(0, 0, 0);">mesa</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="pln" style="color: rgb(0, 0, 0);">libGL</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">so</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="pln" style="color: rgb(0, 0, 0);">usr</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="pln" style="color: rgb(0, 0, 0);">lib</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="pln" style="color: rgb(0, 0, 0);">i386</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">linux</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">gnu</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="pln" style="color: rgb(0, 0, 0);">libGL</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">so</span></code>
4.编译代码
进入源码根目录
编译初始化:
在终端中执行:
source build/envsetup.sh
执行后输出:
source build/envsetup.sh
including device/asus/grouper/vendorsetup.sh
including device/asus/tilapia/vendorsetup.sh
including device/generic/armv7-a-neon/vendorsetup.sh
including device/generic/armv7-a/vendorsetup.sh
including device/generic/mips/vendorsetup.sh
including device/generic/x86/vendorsetup.sh
including device/samsung/maguro/vendorsetup.sh
including device/samsung/manta/vendorsetup.sh
including device/samsung/toroplus/vendorsetup.sh
including device/samsung/toro/vendorsetup.sh
including device/ti/panda/vendorsetup.sh
including sdk/bash_completion/adb.bash
选择编译目标:
lunch full-eng
执行后会又以下信息提示:
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.2
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_OS_EXTRA=Linux-2.6.32-45-generic-x86_64-with-Ubuntu-10.04-lucid
HOST_BUILD_TYPE=release
BUILD_ID=JOP40C
OUT_DIR=out
============================================
编译代码:
在终端中执行:make -j4
-j4:表示用四个线程来编译:
我用虚拟机,配置为4g,交换空间为2g,编译了大约6个小时。
运行模拟器
在终端中执行:emulator
在 ~/.bashrc
添加环境变量:
export ANDROID_PRODUCT_OUT=~/code/android-4.2/out/target/product/generic
export ANDROID_SWT=~/code/android-4.2/out/host/linux-x86/framework/
备注:
重启系统后:
执行emulator,出现如下错误:
emulator: ERROR: You did not specify a virtual device name, and the system
directory could not be found.
If you are an Android SDK user, please use '@<name>' or '-avd <name>'
to start a given virtual device (see -help-avd for details).
Otherwise, follow the instructions in -help-disk-images to start the emulator
解决:
source build/envsetup.sh
lunch sdk-eng
然后再执行
emulator
可以启动模拟器