ArchLinux 编译Anroid5 lollipop 错误解决

错误1,python工具出错

错误情况如下:

============================================
File "build/tools/findleaves.py", line 95
    print r
        ^
SyntaxError: Missing parentheses in call to 'print'
File "build/tools/findleaves.py", line 95
    print r
        ^
SyntaxError: Missing parentheses in call to 'print'
File "build/tools/diff_package_overlays.py", line 88
    print r
        ^
SyntaxError: Missing parentheses in call to 'print'
No private recovery resources for TARGET_DEVICE nanopi3
make: *** 没有规则可制作目标“out/target/common/obj/PACKAGING/public_api.txt”,由“out/target/common/obj/PACKAGING/checkpublicapi-last-timestamp” 需求。 停止。

#### make failed to build some targets (6 seconds) ####

File "build/tools/merge-event-log-tags.py", line 51
    except getopt.GetoptError, err:
                            ^
SyntaxError: invalid syntax
Import includes file: out/host/linux-x86/obj32/STATIC_LIBRARIES/libaapt_intermediates/import_includes
make: *** [build/core/Makefile:399:out/target/common/obj/all-event-log-tags.txt] 错误 1

解决方法, 将出错的py解释器全部更换为python2,或者将python2 链接到本地目录的mybin下面,然后加这个路径到PATH变量里面。

#!/usr/bin/env python
---->  #!/usr/bin/env python2

or,

mkdir mybin;   ln -s /usr/bin/python2 mybin/python; export PATH=${DIR}/mybin:${PATH}

错误2 java版本不正确

安卓5要求的java版本为1.7,而我的archlinux安装了8,报如下错误:

Checking build tools versions...
************************************************************
You are attempting to build with the incorrect version
of java.

Your version is: openjdk version "1.8.0_77" OpenJDK Runtime Environment (build 1.8.0_77-b03) OpenJDK 64-Bit Server VM (build 25.77-b03, mixed mode).
The required version is: "1.7.x"

Please follow the machine setup instructions at
    https://source.android.com/source/initializing.html
************************************************************
build/core/main.mk:167: *** stop。 停止。

#### make failed to build some targets (01:02 (mm:ss)) ####

解决方法如下,设置java为java7,并将java bin文件在PATH变量里面提前与系统的java。

[dbh@playpenguin buildAndroid]$ cat env_openjdk7.sh
#!/bin/sh

# java options.
JAVA_HOME=/usr/lib/jvm/java-7-openjdk
unset _JAVA_OPTIONS
export PATH=${JAVA_HOME}/bin:${PATH}

如果是需要设置为java6,则如下:

[dbh@playpenguin AndroidDevel]$ cat env_all_java6.sh
#!/bin/sh

# java options.
JAVA_HOME=/usr/lib/jvm/java-6-jdk
unset _JAVA_OPTIONS
export PATH=${JAVA_HOME}/bin:${PATH}