android编译环境
一.安装JDK
1、下载jdk
JDK1.6:
JDK1.7
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
JDK1.8
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
2、对于JDK1.7和JDK1.8,下载解压jdk-7u79-linux-x64.tar.gz和jdk-8u20-linux-x64.gz,放置在/opt下,例如
sudo tar zxvf ./jdk-8u20-linux-x64.gz -C /opt
对于JDK1.6,下载jdk-6u45-linux-x64.bin,然后cp到安装路径/opt下,
sudo chmod 777 jdk-6u45-linux-x64.bin
sudo ./jdk-6u45-linux-x64.bin
3、配置环境变量
vim ~/.bashrc
按shit+g在文件末尾加入以下内容
export JAVA_HOME=/opt/jdk1.8.0_20
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
退出保存,并运行下面的命令使之生效
source ~/.bashrc
4、配置默认JDK 由于部分Linux已经自带了JDK,所以我们需要设置刚刚安装好的JDK来作为默认JDK,可以进行下面的配置。
sudo update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_20/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_20/bin/javac 300
如果提示找不到路径,请重启后重试。 5、测试 启动终端,输入以下命令
java -version
javac
6、个别Android版本需要不同的JDK,此时,在编译之前export编译所需的JDK版本
export JAVA_HOME=/opt/jdk1.6.0_45
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
二.安装 1.安装编译依赖的软件
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32z-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc lib32readline-gplv2-dev
其中ia32-libs不能正常安装,使用
sudo apt-get install libncurses5:i386
sudo apt-get install libc6:i386 libgcc1:i386 gcc-4.6-base:i386 libstdc++5:i386 libstdc++6:i386
解决mingw32 lib32readline-gplv2-dev
sudo gedit /etc/apt/sources.list //在sources.list末尾添加,保存 deb http://us.archive.ubuntu.com/ubuntu trusty main universe
libnativehelper/JniInvocation.cpp:165: error: unsupported reloc 43
libnativehelper/JniInvocation.cpp:165: error: unsupported reloc 43
libnativehelper/JniInvocation.cpp:165: error: unsupported reloc 43
libnativehelper/JniInvocation.cpp:165: error: unsupported reloc 43
It works to me: in file /art/build/Android.common_build.mk, find out:
# Host.
ART_HOST_CLANG := false
ifneq ($(WITHOUT_HOST_CLANG),true)
# By default, host builds use clang for better warnings.
ART_HOST_CLANG := true
endif
change to :
# Host.
ART_HOST_CLANG := false
ifeq ($(WITHOUT_HOST_CLANG),false)
# By default, host builds use clang for better warnings.
ART_HOST_CLANG := true
endif
If it still not works,try this in your android root path:
cp /usr/bin/ld.gold prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/x86_64-linux/bin/ld
android 6.0
cp /usr/bin/ld.gold prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld
降低 GCC 版本
sudo apt-get install gcc-4.6 g++-4.6 g++-4.6-multilib gcc-4.6-multilib
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 100
#sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 50
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 100
#sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50
sudo update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.6 100
#sudo update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-5 50
gcc -v
linux下载安装Beyond Compare 1.在Beyond Compare官网下载 Beyond Compare3安装包,bcompare-3.3.13.18981_i386.deb 2.安装
$ sudo dpkg -i bcompare-3.3.8.16340_i386.deb
$ sudo apt-get install libxft2
$ sudo apt-get -f install
$ bcompare
3.注册 试用期 到后
rm -rf ~/.beyondcompare
或者 输入注册码
HmB5oANygQOhaStTHNa+zOKgOeWHOkeAp6d1+QwIebz6z9kwYCm9-O0jF9F79zvzed9v5UVC4VrDkDMmTM8nB+
2.配置Cache 使用如下命令配置cache:
sudo apt-get install ccache
配置方法如下: 1>、在~/.bashrc中添加(或者/etc/profile文件中):
export USE_CCACHE=1
export CCACHE_DIR=/<path_of_your_choice>/.ccache
默认情况下cache(缓存)会保存在~/.ccache目录下,如果主目录位于NFS或其他非本地文件系统上, 设置cache目录位置:export CCACHE_DIR=
prebuilt/linux-x86/ccache/ccache -M 50G
以上命令需要在你所下载的代码的根目录下面执行 该设置会保存到CCACHE_DIR中,且该命令是长效的,不会因系统重启而失效。使用ccache第一次编译后能够明显提高make clean以后再次的编译速度。
3>.查看ccahe使用情况
$ watch -n1 -d prebuilts/misc/linux-x86/ccache/ccache -s
以上命令需要在你所下载的代码的根目录下面执行 备注:使用ccache之后,第一次编译会时间久一点,之后每次编译速度都会有提升
三.ubuntu下adb环境
1.设置adb环境变量 在/etc/profile中添加,然后source /etc/profile:
#set path for android sdk tools
export PATH=$PATH:/home/apu/tool/android-sdk-linux/tools/
export PATH=$PATH:/home/apu/tool/android-sdk-linux/platform-tools/
2.usb权限 先用lsusb命令查看usb id,看到ID是05c6和9091
sudo vim /etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", ATTR{idProduct}=="9091", MODE="0666", OWNER="apu"
然后添加权限
sudo chmod a+rx /etc/udev/rules.d/51-android.rules
重启udev,重启adb,重新插拔USB
sudo service udev restart
adb kill-server
adb shell
在ubuntu下,通过adb命令向手机安装软件的时候,出现error: insufficient permissions for device 。此时需要赋予超级用户权限。代码如下:
stone@stone-System-Product-Name:~/android/androidSDK/tools$ sudo -s
[sudo] password for stone:
root@stone-System-Product-Name:~/android/androidSDK/tools# ./adb kill-server
root@stone-System-Product-Name:~/android/androidSDK/tools# ./adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
HT957KF01136 device
而后可以执行
linux下载安装Beyond Compare 1.在Beyond Compare官网下载 Beyond Compare3安装包,bcompare-3.3.13.18981_i386.deb 2.安装
$ sudo dpkg -i bcompare-3.3.8.16340_i386.deb
$ sudo apt-get install libxft2
$ sudo apt-get -f install
$ bcompare
3.注册
试用期 到后rm -rf ~/.beyondcompare
或者
输入注册码
HmB5oANygQOhaStTHNa+zOKgOeWHOkeAp6d1+QwIebz6z9kwYCm9-O0jF9F79zvzed9v5UVC4VrDkDMmTM8nB+