SEAndroid 的編譯
SEAndroid(Security-Enhanced Android)把原本用於 Linux 的 MAC 強制存取控制套件 SELinux 移植到 Android 平台上,用來強化系統對 App 的存取管控,做出類似沙箱的執行隔離效果,確保每個 App 各自獨立運作,藉此阻擋惡意 App 對系統或其他應用程式的攻擊。
它的核心理念是:即使 root 權限被奪走,也要盡量阻止應用層的惡意行為。
git clone https://bitbucket.org/seandroid/manifests.git mkdir seandroid cd seandroid repo init -u https://android.googlesource.com/platform/manifest repo sync cp ../manifests/local_manifest.xml .repo repo sync
如果本機已有 Android 系統源碼,可以直接對應版本切換分支:
Base Version SE Branch android-4.2.1_r1 seandroid-4.2 android-4.1.2_r1 seandroid-4.1.2 android-4.1.1_r6.1 seandroid-4.1.1 android-4.0.4_r2.1 seandroid-4.0.4
git clone -b seandroid-4.0.4 https://bitbucket.org/seandroid/manifests.git mkdir Android_src cd Android_src cp ../manifests/local_manifest.xml .repo/ repo sync
先編一個虛擬機版本,內核需要具備 SELinux 支援,這裡暫時沿用預設設定:
export PREFIX=/path/to/your/aospclone cd $PREFIX/kernel/goldfish make ARCH=arm goldfish_armv7_defconfig make ARCH=arm CROSS_COMPILE=$PREFIX/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-
以下整理編譯 Android 4.0.4 時常見的錯誤與解法,內容彙整自社群討論。Google group 有專門的 Android Building 社團,有興趣可以加入。
Error: frameworks/base/include/utils/KeyedVector.h:193:31: note: declarations in dependent base ‘android::KeyedVector<android::String8, android::sp<AaptDir> >’ are not found by unqualified lookup make: *** [out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/AptAssets.o] Error 1 Fix: vi frameworks/base/tools/aapt/Android.mk # 第 31 行加上 -fpermissive LOCAL_CFLAGS += -Wno-format-y2k -fpermissive
Error: 'indexOfKey' was not declared in this scope ... [-fpermissive] make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/AssetManager.o] Error 1 Fix: vi frameworks/base/libs/utils/Android.mk # 第 64 行加上 -fpermissive LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive
Error: external/srec/tools/thirdparty/OpenFst/fst/lib/cache.h:136:11: note: use ‘this->SetState’ instead make: *** [out/host/linux-x86/obj/EXECUTABLES/grxmlcompile_intermediates/grxmlcompile.o] Error 1 Fix: cd external/srec wget "https://github.com/CyanogenMod/android_external_srec/commit/4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff" patch -p1 < 4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff rm -f 4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff cd ../..
Error: development/tools/emulator/opengl/host/tools/emugen/main.cpp:79:9: error: ‘optind’ was not declared in this scope make: *** [out/host/linux-x86/obj/EXECUTABLES/emugen_intermediates/main.o] Error 1 Fix: vi development/tools/emulator/opengl/host/tools/emugen/main.cpp # 在 include 區加入 #include <getopt.h>
Error: external/oprofile/libpp/format_output.h:94:22: error: reference ‘counts’ cannot be declared ‘mutable’ [-fpermissive] make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/liboprofile_pp_intermediates/arrange_profiles.o] Error 1 Fix: vi external/oprofile/libpp/format_output.h # 第 94 行移除 mutable counts_t & counts;
Error: frameworks/base/include/utils/KeyedVector.h:193:31: error: ‘indexOfKey’ was not declared in this scope make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libOpenglCodecCommon_intermediates/GLSharedGroup.o] Error 1 Fix: vi development/tools/emulator/opengl/Android.mk # 第 25 行加上 -fpermissive EMUGL_COMMON_CFLAGS := -DWITH_GLES2 -fpermissive
Error: /usr/bin/ld: note: 'XInitThreads' is defined in DSO /lib/libX11.so.6 so try adding it to the linker command line make: *** [out/host/linux-x86/obj/EXECUTABLES/emulator_renderer_intermediates/emulator_renderer] Error 1 Fix: vi development/tools/emulator/opengl/host/renderer/Android.mk # 第 6 行後新增 LOCAL_SRC_FILES := main.cpp LOCAL_CFLAGS += -O0 -g LOCAL_LDLIBS += -lX11
Error: external/llvm/include/llvm/ADT/PointerUnion.h:56:10: error: enumeral mismatch in conditional expression [-Werror] make: *** [out/host/linux-x86/obj/EXECUTABLES/llvm-rs-cc_intermediates/slang_rs.o] Error 1 Fix: vi frameworks/compile/slang/Android.mk # 第 22 行移除 -Werror local_cflags_for_slang := -Wno-sign-promo -Wall -Wno-unused-parameter
Error: frameworks/base/libs/rs/rsFont.cpp:224:76 ... 'indexOfKey' was not declared in this scope make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libRS_intermediates/rsFont.o] Error 1 Fix: vi frameworks/base/libs/rs/Android.mk # 第 183 行加上 -fpermissive LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter -Wno-unused-variable -fpermissive
Error: external/mesa3d/src/glsl/linker.cpp:1734:59: error: ‘offsetof’ was not declared in this scope make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libMesa_intermediates/src/glsl/linker.o] Error 1 Fix: vi external/mesa3d/src/glsl/linker.cpp # include 區加入 #include <climits> #include <stddef.h> #include <pixelflinger2/pixelflinger2_interface.h>
Error: external/gtest/include/gtest/gtest-param-test.h:287:58: note: ... declared here, later in the translation unit make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libgtest_host_intermediates/gtest-all.o] Error 1 Two fixes required: 1) vi external/gtest/src/Android.mk # 第 52 與 70 行都加上 -fpermissive LOCAL_CFLAGS += -O0 -fpermissive 2) vi external/gtest/include/gtest/internal/gtest-param-util.h # include 區加入 #include <vector> #include <cstddef> #include <gtest/internal/gtest-port.h>
連結 test-librsloader 時出現大量未定義引用,例如 ‘dladdr’、‘pthread_create’、‘pthread_mutexattr_init’、‘pthread_mutex_trylock’ 等,最後 collect2 回傳 1。
Fix: $ vi external/llvm/llvm-host-build.mk LOCAL_LDLIBS := -lpthread -ldl
用剛編出來、含 SELinux 支援的內核啟動模擬器:
emulator -show-kernel -kernel kernel/goldfish/arch/arm/boot/zImage