准备工作 源码下载 Android-5.1.1源码 链接:http://pan.baidu.com/s/1bQ8aBk 密码:mc6l
系统 推荐环境 Ubuntu14.04,本文使用Ubuntu16.04( 64位)
安装环境 参考官网,同时需要注意以下几点
Open-JDK-7(不要用 Oracle JDK,卸载安装参考此处)1 2 3 sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-get update sudo apt-get install openjdk-7 -jdk
gcc-4.7 (千万别用Ubuntu16.04自带的gcc,安装参考此处)1 2 3 4 5 6 7 8 sudo apt-get install -y gcc-4.7 sudo apt-get install -y g++-4.7 //建立软链接 cd /usr/binsudo rm -r gcc sudo ln -sf gcc-4.7 gcc sudo rm -r g++ sudo ln -sf g++-4.7 g++
程序库1 2 3 4 sudo apt-get install git-core gnupg flex bison gperf build-essential \ zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 \ lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache \ libgl1-mesa-dev libxml2-utils xsltproc unzip
使用缓存(可选)1 2 export USE_CCACHE=1 prebuilts/misc/linux-x86/ccache/ccache -M 50G
开始编译 参考官网,编译前,建议把后面的错误看一下,然后把该装的库都装上,能省不少麻烦。准备工作一定要做足,不然后面编译到一半就会出问题。通常情况下没有一次就能成功编译,遇到问题直接把错误贴到Google上,一般都能找到答案。
1 2 3 4 5 $ make clobber $ source build/envsetup.sh $ lunch aosp_arm-eng $ make -j8 $ emulator
输入完make -j8 后就是漫长的等待,等编译完成后,输入emulator能正常启动Android模拟器,那么恭喜你,编译成功了!
build成功的截图:
make sdk成功截图
启动模拟器截图
注: 编译完后输入
1 2 3 $ source ./build/envsetup.sh $ lunch sdk-eng $ make sdk
遇到的错误 错误1 prebuilts/misc/linux-x86/bison/bison: 没有那个文件或目录 编译Android-5.1.1时出现bison找不到,但ls可以看的到。 解决方法: ubuntu 64位系统运行32位程序的问题,需要安装运行32位程序的兼容库
1 2 sudo apt-get install lib32ncurses5 sudo apt-get install lib32stdc++6
错误2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 frameworks/base/tools/aidl/aidl_language_l.l:55: warning, 无法匹配规则 build/core/binary.mk:539: recipe for target 'out/host/linux-x86/obj32/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp' failed make: *** [out/host/linux-x86/obj32/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp] 断开的管道 make: *** 正在等待未完成的任务.... frameworks/base/tools/aidl/aidl_language_l.l:55: warning, 无法匹配规则 flex-2.5.39:严重内部错误,exec of /usr/bin/m4 failed build/core/binary.mk:576: recipe for target 'out/host/linux-x86/obj32/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp' failed make: *** [out/host/linux-x86/obj32/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp] 断开的管道 make: *** Deleting file 'out/host/linux-x86/obj32/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp' frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:8: warning: tag "sysui_statusbar_touch" (36000) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:8 frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:9: warning: tag "sysui_heads_up_status" (36001) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:9 frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:10: warning: tag "sysui_fullscreen_notification" (36002) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:10 frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:11: warning: tag "sysui_heads_up_escalation" (36003) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:11 frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:19: warning: tag "sysui_status_bar_state" (36004) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:19 frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:24: warning: tag "sysui_panelbar_touch" (36010) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:24 frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:29: warning: tag "sysui_notificationpanel_touch" (36020) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:29 frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:38: warning: tag "sysui_lockscreen_gesture" (36021) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:38 frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:43: warning: tag "sysui_quickpanel_touch" (36030) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:43 frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:48: warning: tag "sysui_panelholder_touch" (36040) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:48 frameworks/base/packages/SystemUI/tests/src/com/android/systemui/EventLogTags.logtags:53: warning: tag "sysui_searchpanel_touch" (36050) duplicated in frameworks/base/packages/SystemUI/src/com/android/systemui/EventLogTags.logtags:53 注: 某些输入文件使用或覆盖了已过时的 API。 注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。 注: 某些输入文件使用了未经检查或不安全的操作。 注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
解决方法:
1 sudo apt-get install flex bison
错误3 1 2 3 4 5 Export includes file: external/chromium_org/GypAndroid.linux-arm.mk -- out/target/product/generic/obj/STATIC_LIBRARIES/third_party_WebKit_Source_platform_blink_arm_neon_gyp_intermediates/export_includes /bin/bash: gperf: 未找到命令 external/chromium_org/third_party/WebKit/Source/platform/make_platform_generated.target.linux-arm.mk:47: recipe for target 'out/target/product/generic/obj/GYP/shared_intermediates/blink/platform/ColorData.cpp' failed make: *** [out/target/product/generic/obj/GYP/shared_intermediates/blink/platform/ColorData.cpp] Error 127 make: *** 正在等待未完成的任务....
解决方法:
1 sudo apt-get install gperf
错误4 1 2 3 4 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
解决方法:
1 2 3 4 5 6 修改 build/core/clang/HOST_x86_common.mk,找到 CLANG_CONFIG_x86_LINUX_HOST_EXTRA_ASFLAGS ,在 --sysroot=$($(clang_2nd_arch_prefix)HOST_TOOLCHAIN_FOR_CLANG)/sysroot \ 下面添加一行: -B$($(clang_2nd_arch_prefix)HOST_TOOLCHAIN_FOR_CLANG)/x86_64-linux/bin \
参考这里
错误5 error while loading shared libraries: libz.so.1 解决方法,参考这里:
1 2 sudo apt-get install libc6-i386 lib32stdc++6 lib32gcc1 lib32ncurses5 sudo apt-get install lib32z1
错误6 1 2 build/core/binary.mk:620: recipe for target 'out/host/linux-x86/obj32/EXECUTABLES/dex2oat_intermediates/dex2oat.o' failed make: *** [out/host/linux-x86/obj32/EXECUTABLES/dex2oat_intermediates/dex2oat.o] Error 1
gcc 版本问题,解决方法:把gcc版本改成4.7即可。参考这里 :
错误7 1 2 3 4 5 6 Copy xml: out/target/product/generic/system/etc/apns-conf.xml Copy: out/target/product/generic/system/media/audio/alarms/Alarm_Beep_01.ogg Copy: out/target/product/generic/system/media/audio/alarms/Alarm_Beep_02.ogg /bin/bash: xmllint: 未找到命令 make: *** [out/target/product/generic/system/etc/apns-conf.xml] 错误 127 make: *** 正在等待未完成的任务....
解决方法:
1 sudo apt-get install libxml2-utils
错误8 1 2 3 4 5 6 7 8 9 10 11 12 rosalloc_space_base_test (out/target/product/generic/obj/EXECUTABLES/rosalloc_space_base_test_intermediates/LINKED/rosalloc_space_base_test) /home/jason/Desktop/new/android-5.1.1_r1/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: out/target/product/generic/obj/EXECUTABLES/rosalloc_space_base_test_intermediates/runtime/gc/space/rosalloc_space_base_test.o: file is empty collect2: error: ld returned 1 exit status build/core/executable_internal.mk:69: recipe for target 'out/target/product/generic/obj/EXECUTABLES/rosalloc_space_base_test_intermediates/LINKED/rosalloc_space_base_test' failed make: *** [out/target/product/generic/obj/EXECUTABLES/rosalloc_space_base_test_intermediates/LINKED/rosalloc_space_base_test] Error 1 make: *** 正在等待未完成的任务.... target Executable: rosalloc_space_static_test (out/target/product/generic/obj/EXECUTABLES/rosalloc_space_static_test_intermediates/LINKED/rosalloc_space_static_test) target Executable: rosalloc_space_random_test (out/target/product/generic/obj/EXECUTABLES/rosalloc_space_random_test_intermediates/LINKED/rosalloc_space_random_test) Preparing output jar [/home/jason/Desktop/new/android-5.1.1_r1/out/target/common/obj/APPS/SystemUI_intermediates/proguard.classes.jar] Copying resources from program jar [/home/jason/Desktop/new/android-5.1.1_r1/out/target/common/obj/APPS/SystemUI_intermediates/classes.jar] DroidDoc took 113 sec. to write docs to out/target/common/docs/system-api-stubs DroidDoc took 127 sec. to write docs to out/target/common/docs/api-stubs
解决方法,参考这里
原因 I got the same problem today and I resolved it by deleting the cache folder(rm -rf ~/.ccache) and deleting the files *.o that were empty. This problem may occur if your PC shutdown in the middle of a build.
错误9 1 2 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
解决方法:
1 2 make update-api make -j8
错误10 1 target SharedLib: libwebviewchromium (out/target/product/generic/obj/SHARED_LIBRARIES/libwebviewchromium_intermediates/LINKED/libwebviewchromium.so)
解决方法,参考这里
1 2 3 4 5 6 # dd if=/dev/zero of=/opt/other/swapfile bs=1024 count=512K # mkswap /opt/other/swapfile # swapon /opt/other/swapfile # swapon -s # sudo gedit /etc/fstab /opt/other/swapfile file 524280 0 -1
错误11 1 2 3 4 5 6 7 8 9 10 development/build/sdk.atree:47: couldn't locate source file: bin/sqlite3 development/build/sdk.atree:49: couldn't locate source file: bin/etc1tool development/build/sdk.atree:82: couldn't locate source file: bin/split-select development/build/sdk.atree:87: couldn't locate source file: bin/bcc_compat development/build/sdk.atree:174: couldn't locate source file: framework/layoutlib.jar development/build/sdk.atree:175: couldn't locate source file: framework/icu4j.jar development/build/sdk.atree:499: couldn't locate source file: framework/layoutlib-tests.jar development/build/sdk.atree:500: couldn't locate source file: system/app/EmulatorSmokeTests/EmulatorSmokeTests.apk build/core/Makefile:1711: recipe for target 'out/host/linux-x86/sdk/full/android-sdk_eng.root_linux-x86.zip' failed make: *** [out/host/linux-x86/sdk/full/android-sdk_eng.root_linux-x86.zip] Error 44
解决方法:把development/build/sdk.atree文件包含以下文本的行前加上#
1 2 3 4 5 6 7 8 bin/sqlite3 bin/etc1tool bin/split-select bin/bcc_compat framework/layoutlib.jar framework/icu4j.jar framework/layoutlib-tests.jar system/app/EmulatorSmokeTests/EmulatorSmokeTests.apk
错误12
1 prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8//x86_64-linux/bin/ld: error: out/host/linux-x86/obj/SHARED_LIBRARIES/libart_intermediates/arch/x86_64/quick_entrypoints_x86_64.o: unsupported reloc 42 against global symbol art::Runtime::instance_
解决方法,参考这里:
1 2 3 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源码可能会遇到各种各样的问题,一定要有耐心,遇到问题Google之。
编译Android 4.4 有了前面的基础,编译Android-4.4也不是什么难事了。下面记录有可能遇到的错误:
1 2 /bin/bash: jar: command not found make: *** [out/host/common/obj/JAVA_LIBRARIES/antlr-runtime_intermediates/javalib.jar] Error 127
解决方法,参考这里:http://xiaoluozhi.blog.163.com/blog/static/4233482720146293381665/
错误1
jar、javadoc或者javah命令找不到 1 2 3 4 /bin/bash: jar: command not found make: *** [out/host/common/obj/JAVA_LIBRARIES/antlr-runtime_intermediates/javalib.jar] Error 127 或者 /bin/bash: javah: command not found
可以执行以下命令:1 2 3 4 cd /usr/bin ln -s -f /usr/lib/jvm/jdk1.6.0_45/bin/javah ln -s -f /usr/lib/jvm/jdk1.6.0_45/bin/javadoc ln -s -f /usr/lib/jvm/jdk1.6.0_45/bin/jar
[out/target/common/docs/api-stubs-timestamp] Error 45
执行以下命令: make clean make
错误2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Traceback (most recent call last): File "../../base/android/jni_generator/jni_generator.py", line 1103, in <module> sys.exit(main(sys.argv)) File "../../base/android/jni_generator/jni_generator.py", line 1099, in main GenerateJNIHeader(input_file, output_file, options) File "../../base/android/jni_generator/jni_generator.py", line 1012, in GenerateJNIHeader jni_from_javap = JNIFromJavaP.CreateFromClass(input_file, options) File "../../base/android/jni_generator/jni_generator.py", line 520, in CreateFromClass stderr=subprocess.PIPE) File "/usr/lib/python2.7/subprocess.py", line 711, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1340, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory make: *** [out/target/product/generic/obj/GYP/shared_intermediates/ui/gl/jni/Surface_jni.h] Error 1
原因:没有配置javap
错误3 1 2 3 No command 'emulator' found, did you mean: Command 'qemulator' from package 'qemulator' (universe) emulator: command not found
编译成功后,模拟器启动失败
解决方法:到源码根目录下执行
1 2 source build/envsetup.sh lunch aosp_arm-eng
lunch的目标和build的目标要一致,最后输入
1 2 emulator -partition-size 1024 & partition-size
指定虚拟机内存, 去掉也可以
截图 Android4.4编译成功
Android4.4启动模拟器
编译4.4参考资料
编译Android 6.0 方法是一样的,不过为了编译顺利,可能需要做下面两件事
设置swap区1 2 3 4 5 6 sudo dd if=/dev/zero of=/opt/swap1 bs=1024 count=1024000 sudo mkswap /opt/swap1 sudo swapon /opt/swap1 sudo vi /etc/fstab 打开/etc/fstab,在最后一行增加如下内容 /opt/swap1 swap swap defaults 0 0
bug fix,参考这里1 2 3 4 5 6 7 8 9 10 11 12 13 14 in file /art/build/Android.common_build.mk, find out:emphasized text # 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
Ubuntu使用笔记 删除Amazon apt-get remove unity-webapps-common
删除office sudo apt-get remove --purge libreoffice
删除jdk https://my.oschina.net/lxrm/blog/110638
AS查看Android全部源码 检查out/host/Linux-x86/framework/目录下是否有idegen.jar 如果idegen.jar不存在,根目录下执行执行
mmm development/tools/idegen/
把这个文件copy到out/host/linux-x86/framework/目录下,在根目录下执行
development/tools/idegen/idegen.sh 过了几分钟之后跟目录下应该会有android.ipr和android.iml两个文件,此时用Android Studio导入ipr即可。
参考这里:http://blog.csdn.net/sinat_22657459/article/details/51227602
备份Ubuntu 操作环境为Ubuntu14.04 LTS,近日在Ubuntu上搭建了Git服务器及很多其他配置,想将已安装好的系统转换为ISO文件,这样可以实现备份具体步骤如下:
首先,打开在/etc/apt/sources.list文件(使用vim或者gedit均可);
根据具体的环境在sources.list中加入如下相应语句,并保存:
1 2 3 4 5 6 7 #Remastersys Precise deb http://www.remastersys.com/ubuntu precise main #Remastersys Quantal deb http://www.remastersys.com/ubuntu quantal main #Remastersys Squeeze deb http://www.remastersys.com/debian squeeze main #Remastersys Wheezy deb http://www.remastersys.com/debian wheezy main
更新数据源: 在终端中输入:sudo apt-get update
更新完成后,安装remastersys: sudo apt-get install remastersys
安装成功后,输入sudo remastersys会出现remastersys Examples,根据这些命令行提示你可以实现不同功能,此处需要输入命令: sudo remastersys dist 然后等待完成,此时会在终端窗口所提示的目录下生成ISO文件及MD5文件,如果需要刻盘只需要验证MD5就可以了。
ubuntu14.04忽然不能登录 ubuntu14.04忽然不能登录,输入密码一直返回登录界面 解决方法:
ctrl + alt + F1进入命令终端
重装gdm,sudo apt-get install gdm
修改启动顺序:dpkg -reconfigure gdm
重启reboot可登录。
编辑/etc/profile要使用的命令应该这样写:
1 2 /usr/bin/vim /etc/profile
正常状态下重启使用:sudo reboot
当然现在也不行,要使用
1 2 /usr/bin/sudo /sbin/reboot
参考这里:http://blog.163.com/shao_yuru/blog/static/130517606201010310581842/
参考 Android官网