版權聲明:您好,轉載請留下本人部落格的位址,謝謝 https://blog.csdn.net/hongbochen1223/article/details/47708233
由于目前的項目需要修改android的核心源碼,是以我需要從android源碼的編譯開始學習.
下面看一下我的編譯環境.
我使用的Ubuntu系統的版本是14.04,64位.
gcc版本:4.8.8
編譯過程我是看着google開發者官網,以及結合别人的部落格進行編譯的.編譯的過程會遇到很多問題,在這裡,我就把我遇到的問題總結一些,以便以後用到的時候容易檢視,也友善别人編譯android的時候遇到相同的問題,便于檢視.
問題一:java版本問題
這個問題描述的是我目前使用的java版本是”1.7”,而正确的版本是java se 1.6,是以我們需要更換java.
解決辦法:
1:使用指令(因為我使用的是openjdk)
sudo apt-get remove openjdk-7-jre openjdk-7-jdk openjdk-7-jre-headless
2:如果你使用的是JDK,為了以後還會使用,先講全局變量中的export語句使用’#’注釋掉即可.
3:安裝Java SE 1.6
4:從官網下載下傳并且解壓之後,配置環境變量即可
問題二:編譯問題
解決方法:
1:找到android源代碼/frameworks/base/tools/aapt/Android.mk檔案,編輯
找到第31行的LOCAL_CFLAGS,後面添加-fpermissive
2:找到android源代碼frameworks/base/libs/utils/Android.mk檔案,編輯
找到第64行的LOCAL_CFLAGS,後面添加-fpermissive
問題三:
cd external/srec
wget "https://github.com/CyanogenMod/android_external_srec/commit/4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff"
patch -p1 < 4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff
rm -f 4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff
cd ../..
問題四:
這個問題僅僅需要将dalvik/vm/native/dalvik_system_Zygote.cpp中添加一句”#include
#include <getopt.h>
問題六:
解決辦法:
在檔案development/tools/emulator/opengl/Android.mk中的第25行後面添加 -fpermissive
錯誤七:
在檔案/development/tools/emulator/opengl/host/renderer/Android.mk檔案中的LOCAL_CFLAGS += -O0 -g的下一行添加"LOCAL_LDLIBS += -lX11"
LOCAL_PATH:=$(call my-dir)
# host renderer process ###########################
$(call emugl-begin-host-executable,emulator_renderer)
$(call emugl-import,libOpenglRender)
LOCAL_SRC_FILES := main.cpp
LOCAL_CFLAGS += -O0 -g
LOCAL_LDLIBS += -lX11
#ifeq ($(HOST_OS),windows)
#LOCAL_LDLIBS += -lws2_32
#endif
$(call emugl-end-module)
錯誤八:
将檔案build/core/combo/HOST_linux-x86.mk中的
HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
替換為
HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
錯誤八:
将檔案中frameworks/compile/slang/Android.mk第22行中的-werror移除
錯誤九:
在檔案external/llvm/lib/ExecutionEngine/JIT/Intercept.cpp中添加頭檔案
#define _LARGEFILE64_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
錯誤十:
安裝perl switch庫
sudo apt-get install libswitch-perl
錯誤十一:
external/oprofile/libpp/format_output.h:94:22: 錯誤: reference ‘counts’ cannot be declared ‘muta
external/oprofile/libpp/format_output.h:94:22: 錯誤: reference ‘counts’ cannot be declared ‘muta…
針對這種情況,需要修改external/oprofile/libpp/format_output.h:94行
mutable counts_t & counts為
counts_t & counts
錯誤十二:
修改檔案external/llvm/llvm-host-build.mk
中添加 LOCAL_LDLIBS := -lpthread -ldl
錯誤十三:
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);
将檔案/external/gtest/src/Android.mk中所有的”LOCAL_CFLAGS += -O0”修改為”LOCAL_CFLAGS += -O0 -fpermissive”
錯誤十四:
make: *
[out/host/linux-x86/obj/STATIC_LIBRARIES/libgtest_host_intermediates/gtest-all.o] Error 1
解決方法:
gedit external/gtest/include/gtest/internal/gtest-param-util.h 添加:
#include <cstddef>