zoukankan      html  css  js  c++  java
  • [原创]Nexus5 源码下载、编译、真机烧录过程记录

    asop使用清华镜像源https://mirror.tuna.tsinghua.edu.cn/help/AOSP/

    一开始使用每月初始化包的方式因为无法搞定版本的问题,没能通过编译,无奈,老老实实一点点下载吧

    repo回退当前分支下所有仓库到指定日期前的最新代码版本

    repo forall -c 'commitID=`git log --before "2017-03-17 07:00" -1 --pretty=format:"%H"`; git reset --hard $commitID'

    1、源码下载

    mkdir aosp
    cd aosp
    repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-6.0.1_r1
    sh myrepo.sh

    版本号,一定要选对,不然就要来回折腾,因为虽然都是android6.0,但有的版本并不支持nexus5,版本信息参考:http://blog.csdn.net/arxi/article/details/52292291

    MMB29Q     android-6.0.1_r11     Marshmallow     Nexus 5, Nexus 5X, Nexus 6, Nexus 6P, Nexus 7 (flo/deb)
    MMB29T     android-6.0.1_r10     Marshmallow     Nexus Player
    MMB29S     android-6.0.1_r9     Marshmallow     Nexus 5, Nexus 6, Nexus 9 (volantis/volantisg)
    MMB29P     android-6.0.1_r8     Marshmallow     Nexus 5X, Nexus 6P
    MMB29O     android-6.0.1_r7     Marshmallow     Nexus 7 (flo/deb)
    MXB48K     android-6.0.1_r5     Marshmallow     Pixel C
    MXB48J     android-6.0.1_r4     Marshmallow     Pixel C
    MMB29M     android-6.0.1_r3     Marshmallow     Nexus 6P, Nexus Player
    MMB29K     android-6.0.1_r1     Marshmallow     Nexus 5, Nexus 5X, Nexus 6, Nexus 7 (flo/deb), Nexus 9 (volantis/volantisg)

    顺便提醒下,一般版本支持的型号越多,相应的体积越大。曾经就下错过版本,导致烧录后进入normal模式一直卡在开机动画上。关于源码体积这里给个简单的参考:

    android-6.0.1_r1 67G     android-6.0.1_r3 54G

    源码体积比较大,建议下载前一定要保证硬盘分区足够大,如果既要下载又要编译,建议存放源码分区不小于120G

    myrepo.sh是为避免repo失败过程,对repo sync 重试过程进行的封装,见下方

    #!/bin/sh
    repo sync -j4
    while [ $? -ne 0 ]
    do
    repo sync -j4
    done

     同步过程出现 curl: (22) The requested URL returned error: 404 Not Found Server does not provide clone.bundle; ignoring. 直接无视即可

    2、添加驱动

          在代码完全同步之后,实际时缺少vendor目录的,是没有相应的驱动,编译出的镜像只能运行在模拟器上,下载相关的驱动

    https://developers.google.com/android/drivers#hammerheadmmb29k,实际是三个shell 脚本

    依次执行这三个脚本文件,这里要注意,三个脚本文件的作用是生成驱动文件,但是在执行操作前,它会让你阅读相关协议,你必须一直按enter键一行一行往下读,更不能一键摁到底,因为程序在最后会让你输入“I ACCEPT”,如果你一键摁到底,也就是说最后一步也摁enter键的话它就会执行默认操作,即不接受此协议,那生成驱动文件的操作就不会执行。这里有个小窍门,一直摁住enter,注意命令行中闪过的协议项,当读到第八项时可以放慢速度,一下一下的摁enter键了,最后慢慢的到最后一步,输入I ACCEPT即可。这三个文件都是这样的操作流程。上图展示了在执行完脚本文件后生成的驱动文件目录。

    参考:http://blog.csdn.net/liu1075538266/article/details/51272398

    3、编译环境配置

    python:http://blog.csdn.net/fang_chuan/article/details/60958329

    java:https://www.cnblogs.com/dinphy/p/5995597.html?mType=Group (deepin)

    LinuxMint18的安装源已经默认没有openjdk7了,所以要自己手动添加仓库,如下:

    sudo add-apt-repository ppa:openjdk-r/ppa  
    sudo apt-get update   
    sudo apt-get install openjdk-7-jdk
    更改java 版本
    sain@Linux:/usr/bin$ update-alternatives --list java
    /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
    /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
    sain@Linux:/usr/bin$ sudo update-alternatives --config java

    sudo update-alternatives --config javac
    [sudo] sain 的密码: 有 2 个候选项可用于替换 java (提供 /usr/bin/java)。 选择 路径 优先级 状态 ------------------------------------------------------------ * 0 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 自动模式 1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 手动模式 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 手动模式

    改变优先级
     sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1091

    选择 路径 优先级 状态
    ------------------------------------------------------------
    0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1091 自动模式
    * 1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1091 手动模式
    2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 手动模式

     添加和删除环境变量  http://blog.csdn.net/aguangg_6655_la/article/details/53245642

    4、编译

    export USE_CCACHE=1
    prebuilts/misc/linux-x86/ccache/ccache -M 50G
    source build/envsetup.sh 
    
    ninjame@ubuntu1604:~/aosp$ lunch
    
    ------------------------------
    You're building on Linux
    
    Lunch menu... pick a combo:
         1. aosp_arm-eng
         2. aosp_arm64-eng
         3. aosp_mips-eng
         4. aosp_mips64-eng
         5. aosp_x86-eng
         6. aosp_x86_64-eng
         7. aosp_deb-userdebug
         8. aosp_flo-userdebug
         9. full_fugu-userdebug
         10. aosp_fugu-userdebug
         11. mini_emulator_arm64-userdebug
         12. m_e_arm-userdebug
         13. mini_emulator_mips-userdebug
         14. mini_emulator_x86_64-userdebug
         15. mini_emulator_x86-userdebug
         16. aosp_flounder-userdebug
         17. aosp_angler-userdebug
         18. aosp_bullhead-userdebug
         19. aosp_hammerhead-userdebug
         20. aosp_hammerhead_fp-userdebug
         21. aosp_shamu-userdebug
    
    Which would you like? [aosp_arm-eng] 19
    
    ------------------------
    
    make -j8

    最终编译耗时 1h 22min

    Creating filesystem with parameters:
        Size: 1073741824
        Block size: 4096
        Blocks per group: 32768
        Inodes per group: 8192
        Inode size: 256
        Journal blocks: 4096
        Label: system
        Blocks: 262144
        Block groups: 8
        Reserved block group size: 63
    Created filesystem with 1511/65536 inodes and 93478/262144 blocks
    Install system fs image: out/target/product/hammerhead/system.img
    out/target/product/hammerhead/system.img+out/target/product/hammerhead/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p maxsize=1096212480 blocksize=135168 total=367728881 reserve=11083776
    
    #### make completed successfully (01:12:44 (hh:mm:ss)) ####
    
    ninjame@ubuntu1604:~/aosp$ du -sh out/
    22G    out/

    编译问题记录:

    问题1:
    pp frameworks/base/tools/aidl/aidl_language_y.y build/core/binary.mk:609: recipe for target 'out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp' failed make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp] 断开的管道 make: *** 正在等待未完成的任务.... Lex: aidl <= frameworks/base/tools/aidl/aidl_language_l.l frameworks/base/tools/aidl/aidl_language_l.l:55: warning, 无法匹配规则 flex-2.5.39:严重内部错误,exec of /usr/bin/m4 failed build/core/binary.mk:646: recipe for target 'out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp' failed make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp] Error 1 make: *** Deleting file 'out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp' 注: 某些输入文件使用或覆盖了已过时的 API。 注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。 注: 某些输入文件使用了未经检查或不安全的操作。 注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。 解决办法:

    1 更换软件源为阿里云

    为了更快的安装软件,我们需要更换软件源为国内的软件源,这里推荐使用Ubuntu官方指定的国内软件源阿里云,具体方法是:

    sudo gedit /etc/apt/sources.list 

    在文件最前面加入下面代码:

    deb http://mirrors.aliyun.com/ubuntu/ quantal main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ quantal-security main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ quantal-updates main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ quantal-proposed main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ quantal-backports main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ quantal main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ quantal-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ quantal-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ quantal-proposed main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ quantal-backports main restricted universe multiverse

    2 安装依赖

    sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386 
    sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib 
    sudo apt-get install tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 
    sudo apt-get install dpkg-dev libsdl1.2-dev libesd0-dev
    sudo apt-get install git-core gnupg flex bison gperf build-essential  
    sudo apt-get install zip curl zlib1g-dev gcc-multilib g++-multilib 
    sudo apt-get install libc6-dev-i386 
    sudo apt-get install lib32ncurses5-dev x11proto-core-dev libx11-dev 
    sudo apt-get install lib32z-dev ccache
    sudo apt-get install libgl1-mesa-dev libxml2-utils xsltproc unzip m4

    Ubuntu 16.04请务必使用上面的依赖,Ubuntu 16.04需要的依赖和Ubuntu 14.04所需要的依赖是不同的

    问题2:

    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    build/core/host_shared_library_internal.mk:51: recipe for target 'out/host/linux-x86/obj/lib/libart.so' failed
    make: *** [out/host/linux-x86/obj/lib/libart.so] Error 1
    make: *** 正在等待未完成的任务....
    据说这个错误只在ubuntu16.04 上出现

    修改源码

    修改 mydroid/art/build/Android.common_build.mk 文件,定位到75行,注释掉75-78:

     75 #ifneq ($(WITHOUT_HOST_CLANG),true)
     76   # By default, host builds use clang for better warnings.
     77 #  ART_HOST_CLANG := true
     78 #endif

    如果不修改这里,会遇到一个比较棘手的编译错误,修改的目的是把CLANG这个编译选项关掉,详见后面的编译记录,百度搜狗都无解,这个错误只会在Ubuntu16.04上遇到,Ubuntu14.04则不存在这个问题,参考 http://blog.csdn.net/fuchaosz/article/details/51487585

    问题3:

    frameworks/av/services/audioflinger/FastCapture.cpp:108:62: error: 'FCC_8' was not declared in this scope
    ALOG_ASSERT(channelCount >= 1 && channelCount <= FCC_8);
    ^
    build/core/binary.mk:706: recipe for target 'out/target/product/hammerhead/obj/SHARED_LIBRARIES/libaudioflinger_intermediates/FastCapture.o' failed
    make: *** [out/target/product/hammerhead/obj/SHARED_LIBRARIES/libaudioflinger_intermediates/FastCapture.o] Error 1
    make: *** 正在等待未完成的任务....
    target thumb C++: libaudioflinger <= frameworks/av/services/audioflinger/FastMixerDumpState.cpp

    这个简单, 变量没有定义:~/aosp/frameworks/av/services/audioflinger$ grep -r "FCC_8"

    AudioFlinger.h:// The macro FCC_8 highlights places where there are 8-channel assumptions.
    AudioFlinger.h:#define FCC_8 8 // FCC_8 = Fixed Channel Count 8

    4、刷机

    刷机过程碰到
     
    fastboot reboot
    < waiting for any device >
    
    fastboot devices
    no permissions (verify udev rules); see [http://developer.android.com/tools/device.html]    fastboot
    
    fastboot命令一直识别不了手机,一开始以为时fastboot版本的问题,后来发现不是这么回事
    
    
    需要设置usb权限
    因为ubuntu这样的系统都是默认以非root身份在运行的,要使用usb调试,需要sudo支持。
    fastboot模式下插入手机
    $ lsusb
    ninjame@ubuntu1604:~$ lsusb
    Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 001 Device 002: ID 04d9:a0cd Holtek Semiconductor, Inc. 
    Bus 001 Device 030: ID 18d1:4ee0 Google Inc. 
    Bus 001 Device 003: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    $sudo vim /etc/udev/rules.d/60-android.rules   //60-android.rules为新建的。
    加入以下内容:
    SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4ee0",MODE="0666"
    
    其中的idvendor idProduct指的是USB的ID可以使用lsusb查询得到。
    比如我的是:
    lsusb
    
    Bus 001 Device 030: ID 18d1:4ee0 Google Inc.
    
    ID 18d1 就是idVendor ,4ee0就是 idProduct
    运行命令,重启udev:
    $sudo chmod a+rx /etc/udev/rules.d/60-android.rules
    $sudo service udev restart
    (很重要)拔掉usb重新连上再执行:
    fastboot devices 
    
    ninjame@ubuntu1604:~$ fastboot devices
    0779af0143a66640    fastboot


    设置环境变量 sudo vim /etc/profile
    export ANDROID_PRODUCT_OUT="/home/ninjame/aosp/out/target/product/hammerhead"
    source /etc/profile


    ninjame@ubuntu1604:~/aosp/out/target/product/hammerhead$ fastboot -w flashall
    target reported max download size of 1073741824 bytes
    wiping userdata...
    Creating filesystem with parameters:
        Size: 13725835264
        Block size: 4096
        Blocks per group: 32768
        Inodes per group: 8144
        Inode size: 256
        Journal blocks: 32768
        Label:
        Blocks: 3351034
        Block groups: 103
        Reserved block group size: 823
    Created filesystem with 11/838832 inodes and 93654/3351034 blocks
    wiping cache...
    Creating filesystem with parameters:
        Size: 734003200
        Block size: 4096
        Blocks per group: 32768
        Inodes per group: 7472
        Inode size: 256
        Journal blocks: 2800
        Label:
        Blocks: 179200
        Block groups: 6
        Reserved block group size: 47
    Created filesystem with 11/44832 inodes and 5813/179200 blocks
    --------------------------------------------
    Bootloader Version...: HHZ12k
    Baseband Version.....: M8974A-2.0.50.2.28
    Serial Number........: 0779af0143a66640
    --------------------------------------------
    checking product...
    OKAY [  0.100s]
    sending 'boot' (9160 KB)...
    OKAY [  0.500s]
    writing 'boot'...
    OKAY [  0.785s]
    sending 'recovery' (10018 KB)...
    OKAY [  0.566s]
    writing 'recovery'...
    OKAY [  0.825s]
    erasing 'system'...
    OKAY [  1.066s]
    sending 'system' (358584 KB)...
    OKAY [ 11.452s]
    writing 'system'...
    OKAY [ 25.345s]
    erasing 'userdata'...
    OKAY [  7.935s]
    sending 'userdata' (137318 KB)...
    OKAY [  4.511s]
    writing 'userdata'...
    OKAY [  9.139s]
    erasing 'cache'...
    OKAY [  0.584s]
    sending 'cache' (13348 KB)...
    OKAY [  0.630s]
    writing 'cache'...
    OKAY [  1.067s]
    rebooting...

    finished. total time: 65.037s

    第一次开机如果卡住,只需要进到recovery模式下,执行wipe cache partition,清除系统缓存。

    整个过程比较曲折,但看到开机画面弹出时,还是挺开心的。

    编译的镜像烧入手机,比较精简,上几张图

    截图直接保存到电脑:adb shell screencap -p | sed 's/ $//' > screen.png

     第三方recovery TWRP

  • 相关阅读:
    概率dp呜呜
    树上路径问题---点分治题集
    POJ 1741 Tree
    接下来的计划
    很逗 的网络赛历程
    Codeforces Round #264 (Div. 2) D
    似乎了解了树形dp/
    先胡乱搭一个blog
    POJ 1330 (LCA)
    文件操作
  • 原文地址:https://www.cnblogs.com/hixin/p/6884160.html
Copyright © 2011-2022 走看看