RK3128编译记录

RK3128 Android 编译

  这是RK3128 Android平台编译记录,使用环境如下: 1.Ubuntu16.04 LTS 2.gcc (使用gcc6.5,更高级版本python2.7.14编译存在问题)   对于python2.7.14有问题的可以再单独安装

1.开发环境以及依赖选项

在进行rom编译前,首先需要保证依赖选项就绪。

1)环境安装依赖项

sudo apt-get install git-core gnupg flex bison gperf libsdl1.2-dev \
libesd0-dev libwxgtk2.8-dev squashfs-tools build-essential zip curl \
libncurses5-dev zlib1g-dev pngcrush schedtool libxml2 libxml2-utils \
xsltproc lzop libc6-dev schedtool g++-multilib lib32z1-dev lib32ncurses5-dev \
lib32readline-gplv2-dev gcc-multilib libswitch-perl \
libssl1.0.0 libssl-dev

但是实际安装中,因为存在:libwxgtk2.8-dev lib32readline-gplv2-dev 已经没有了 所以请使用:

sudo apt-get install git-core gnupg flex bison gperf libsdl1.2-dev \
libesd0-dev squashfs-tools build-essential zip curl \
libncurses5-dev zlib1g-dev pngcrush schedtool libxml2 libxml2-utils \
xsltproc lzop libc6-dev schedtool g++-multilib lib32z1-dev lib32ncurses5-dev \
gcc-multilib libswitch-perl \
libssl1.0.0 libssl-dev

增加:libwxgtk2.8-dev

sudo add-apt-repository ppa:nilarimogard/webupd8 
sudo apt-get update
sudo apt-get install libwxgtk2.8-dev

增加:lib32readline-gplv2-dev

sudo apt-get install  lib32readline6-dev

增加:libbz-dev checkpolicy

sudo apt-get install libbz2-dev
sudo apt-get install checkpolicy

2)软件安装依赖项

系统编译需要java环境,可以使用open-jdk7,如果系统中已经有jdk版本,但是 不是1.7版本(源码里面自带了1.7版本),直接加上一个全局变量,使得编译的时候 使用自带的jdk。

export ANDROID_SET_JAVA_HOME=true

如果系统是14.04,安装源里面带有open-jdk源码路径,但是16.04没有了。 ubuntu 14.04

sudo apt-get install openjdk-7-jre 或者sudo apt-get install openjdk-7-jdk

ubuntu 16.04

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-7-jdk

注意java存在多个版本的情况 配置

sudo update-alternatives --config java
sudo update-alternatives --config javac

2.编译中遇到的错误

1)error: unsupported reloc 43

这个问题是由于从Ubuntu14.04环境换成了16.04,具体原因是使用clang编译 art是遇到的问题,为什么使用clang而不使用原来的gcc,这里可以采取两种方法,解决。 来源参考:https://github.com/gmacario/easy-jenkins/issues/88

libnativehelper/JniConstants.cpp:129: error: unsupported reloc 43
libnativehelper/JniConstants.cpp:130: error: unsupported reloc 43
libnativehelper/JniConstants.cpp:131: error: unsupported reloc 43
libnativehelper/JniConstants.cpp:132: error: unsupported reloc 43
libnativehelper/JniConstants.cpp:133: error: unsupported reloc 43
libnativehelper/JniConstants.cpp:134: error: unsupported reloc 43
libnativehelper/JniConstants.cpp:135: error: unsupported reloc 43
libnativehelper/JniConstants.cpp:136: error: unsupported reloc 43
libnativehelper/JniConstants.cpp:137: error: unsupported reloc 43
libnativehelper/JniConstants.cpp:138: error: unsupported reloc 43
libnativehelper/JniConstants.cpp:139: error: unsupported reloc 43
libnativehelper/JniConstants.cpp:140: error: unsupported reloc 43
libnativehelper/toStringArray.cpp:21: error: unsupported reloc 43
libnativehelper/toStringArray.cpp:21: error: unsupported reloc 43
libnativehelper/JniInvocation.cpp:40: error: unsupported reloc 43
libnativehelper/JniInvocation.cpp:45: 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
libnativehelper/JniInvocation.cpp:165: error: unsupported reloc 43
clang: error: linker command failed with exit code 1 (use -v to see invocation)
build/core/host_shared_library_internal.mk:44: recipe for target 'out/host/linux-x86/obj32/lib/libnativehelper.so' failed
make: *** [out/host/linux-x86/obj32/lib/libnativehelper.so] Error 1
make: *** Waiting for unfinished jobs....
make: *** wait: No child processes.  Stop.

解决方法一:修改mk文件,source_android代表,源码路径【这会修改Android源码】 1.修改mk文件

cd  <source_android>/art/build/
vim Android.common_build.mk    //修改第119行
修改前
# Host.
ART_HOST_CLANG := false
ifneq ($(WITHOUT_HOST_CLANG),true)
# By default, host builds use clang for better warnings.
ART_HOST_CLANG := true
endif
修改后
# Host.
ART_HOST_CLANG := false
ifneq ($(WITHOUT_HOST_CLANG),false)
# By default, host builds use clang for better warnings.
ART_HOST_CLANG := true
endif

2.cp文件

cp /usr/bin/ld.gold   <source_android>/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/x86_64-linux/bin/ld

3.更新一下

修改过上述代码后,最好执行一次make update-api,在make

解决方法二:通过环境变量禁用clang

export WITHOUT_HOST_CLANG=false

2)public_api.txt:20: error 5: Added public field android.Manifest.permission.BACKUP

DroidDoc took 87 sec. to write docs to out/target/common/docs/api-stubs
DroidDoc took 84 sec. to write docs to out/target/common/docs/system-api-stubs
target Dex: TeleService
target Dex: Telecom
target Dex: TelephonyProvider
Checking API: checkpublicapi-last
Checking API: checkpublicapi-current
Checking API: checksystemapi-last
Checking API: checksystemapi-current
frameworks/base/api/current.txt:20: error 10: Removed field android.Manifest.permission.BACKUP
frameworks/base/api/current.txt:82: error 10: Removed field android.Manifest.permission.INVOKE_CARRIER_SETUP
frameworks/base/api/current.txt:106: error 10: Removed field android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE
frameworks/base/api/current.txt:116: error 10: Removed field android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST

******************************
You have tried to change the API from what has been previously approved.

To make these errors go away, you have two choices:
   1) You can add "@hide" javadoc comments to the methods, etc. listed in the
      errors above.

   2) You can update current.txt by executing the following command:
         make update-api

      To submit the revised current.txt to the main Android repository,
      you will need approval.
******************************
build/core/tasks/apicheck.mk:62: recipe for target 'out/target/common/obj/PACKAGING/checkpublicapi-current-timestamp' failed
make: *** [out/target/common/obj/PACKAGING/checkpublicapi-current-timestamp] Error 38
make: *** Waiting for unfinished jobs....

这种情况,需要修改一下system/core/libutils/String8.cpp 参考:https://android.googlesource.com/platform/system/core/+/dd060f01f68ee0e633e9cae24c4e565cda2032bd%5E%21

diff --git a/libutils/String8.cpp b/libutils/String8.cpp
index 9092cbc..3323b82 100644
--- a/libutils/String8.cpp
+++ b/libutils/String8.cpp
@@ -424,7 +424,7 @@
             next = len;
         }

-        memcpy(buf + tail, buf + index + skip, next - index - skip);
+        memmove(buf + tail, buf + index + skip, next - index - skip);
         tail += next - index - skip;
         index = next;
     }

或者

sed -i '427s/memcpy/memmove/' ./system/core/libutils/String8.cpp

3.编译完成

再解决好所有出现的问题后,编译完成,出现:

#### make completed successfully (26:32 (mm:ss)) ####

TARGET_PRODUCT=rk312x
TARGET_HARDWARE=rk30board
IMG_TARGET=all , ota = withoutkernel
system filesysystem is ext4
'kernel/arch/arm/boot/zImage' -> '/android-workspace/android/out/target/product/rk312x/kernel'
create boot.img without kernel... done.
create recovery.img with kernel and with out resource... done.
create misc.img.... done.
create system.img... done.
create loader...done.
create uboot.img...done.
create resource.img...done.
create kernel.img...done.
create parameter...done.
firefly make images finish!