zoukankan      html  css  js  c++  java
  • 单机搭建Android开发环境(四)

    单机搭建安卓开发环境,前三篇主要是磨刀霍霍,这一篇将重点介绍JDK、REPO、GIT及编译工具的安装,下载项目代码并编译。特别说明,以下操作基于64位12.04 Server版Ubuntu。若采用其他版本系统,请参考Google官方操作步骤。访问不了的同学,请找大师(蓝灯),他能助你一臂之力。

    1)安装OpenJDK 7

       sudo apt-get install openjdk-7-jdk --force-yes –y

      安装OpenJDK8
            sudo add-apt-repository ppa:openjdk-r/ppa
            sudo apt-get update
            sudo apt-get install openjdk-8-jdk --force-yes -y

    查看java的版本

      java –version

      java version "1.7.0_95"

      OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-0ubuntu0.12.04.1)

      OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)

    设置环境变量

      vim ~/.profile

    在末尾添加如下配置,保存并退出

      export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

      export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH

      export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH

    终端输入如下命令使配置生效

      source ~/.profile

    2)安装google推荐的编译工具

      sudo apt-get install gnupg flex bison gperf build-essential --force-yes -y

      sudo apt-get install zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev --force-yes -y

      sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 --force-yes -y

      sudo apt-get install libgl1-mesa-dev g++-multilib mingw32 tofrodos --force-yes -y

      sudo apt-get install python-markdown libxml2-utils xsltproc zlib1g-dev:i386 --force-yes -y

      sudo apt-get install libgl1-mesa-dri:i386 dpkg-dev --force-yes –y

    3)安装repo

    下载repo V1.22国内定制版,已处理原版在国内使用时出现如下错误提示:

      fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle

      fatal: error [Errno 101] Network is unreachable

    将repo拷贝到/bin目录下,并修改其属性

      sudo cp /home/repo /bin/

      sudo chmod a+x /bin/repo

    4)安装git

      sudo apt-get install git --force-yes –y

    配置用户邮箱及用户名

      git config --global user.email "hjb@mail.com"

      git config --global user.name "hjb"

    配置完成后可通过git config --list查看配置信息,或通过cat ~/.gitconfig查看git配置文件的详细信息。

    5)创建密钥,并添加到服务器端

      ssh-keygen -t rsa -C hjb@bonovo.com

    拷贝id_rsa.pub并重命名,然后复制到服务器

      cp /home/hjb/.ssh/id_rsa.pub /home/hjb/id_rsa.pub.hjb113

    在git服务器端登录bnv用户,并执行如下命令,

      cat /home/hjbang/id_rsa.pub.hjb113 >> /home/bnv/.ssh/authorized_keys

    6)本地创建project目录mt8735,准备下载代码

      cd ~

      mkdir mt8735

      cd mt8735

    7)同步代码

      repo init -u bnv@192.168.1.12:/home/git/MTK/lp5.1-mt8735m-mirror/bonovo/platform/manifests.git -b default

      repo sync

      repo forall -c git checkout lp5.1-mt6735m

      repo forall -c git checkout mt8735-avn401

      repo forall -c git pull

    8)安装ccache,并配置ccache

      sudo apt-get install -y ccache

    配置.bashrc

      sudo vim ~/.bashrc

    末尾添加

      export USE_CCACHE=1

    使配置及时生效

      source ~/.bashrc

    查看设置状态:

      echo $USE_CCACHE

    9)编译project

      cd ~/mt8735

      prebuilts/misc/linux-x86/ccache/ccache -M 50G

      . build/envsetup.sh

      launch 25

      make update-api

      make update-api,大概需要花18分钟,详细信息如下,

      Docs droiddoc: out/target/common/docs/doc-comment-check
    
      DroidDoc took 513 sec. to write docs to out/target/common/docs/doc-comment-check
    
      Copying current.txt
    
      Copying removed.txt
    
      Docs droiddoc: out/target/common/docs/system-api-stubs
    
      DroidDoc took 13 sec. to write docs to out/target/common/docs/system-api-stubs
    
      Copying system-current.txt
    
      Copying system-removed.txt
    
     #### make completed successfully (17:54 (mm:ss)) ####
    View Code

    编译Android5.1系统

      make –j24

    编译过程非常漫长,可以通过如下命令查看cahe使用情况,

      watch -n1 -d prebuilts/misc/linux-x86/ccache/ccache -s

      cache directory /home/hjb/.ccache
    
      cache hit (direct) 0
    
      cache hit (preprocessed) 0
    
      cache miss 43927
    
      called for link 1209
    
      preprocessor error 732
    
      unsupported source language 968
    
      unsupported compiler option 2
    
      files in cache 138583
    
      cache size 18.0 Gbytes
    
      max cache size 50.0 Gbytes

    可以看到cache大概有18GB,故使用ccache,第一次编译的时间会比不用cache更长,但之后编译速度将会有很大提升。

    经过4个半小时,第一次编译终于成功了,详细信息如下,

    Creating filesystem with parameters:
    
    Size: 1610612736
    
    Block size: 4096
    
    Blocks per group: 32768
    
    Inodes per group: 8192
    
    Inode size: 256
    
    Journal blocks: 6144
    
    Label:
    
    Blocks: 393216
    
    Block groups: 12
    
    Reserved block group size: 95
    
    Created filesystem with 2436/98304 inodes and 221139/393216 blocks
    
    Install system fs image: out/target/product/mt8735_tb_l1/system.img
    
    out/target/product/mt8735_tb_l1/system.img+out/target/product/mt8735_tb_l1/obj/PACKAGING/recovery_patch_intermediates/recovery-from-boot.p maxsize=1644331392 blocksize=4224 total=881392372 reserve=16612992
    
     
    
    #### make completed successfully (04:25:03 (hh:mm:ss)) ####
    View Code

    修改内核模块代码,重新编译系统镜像大概需要13分钟,详细信息如下,

    Creating filesystem with parameters:
    
    Size: 1610612736
    
    Block size: 4096
    
    Blocks per group: 32768
    
    Inodes per group: 8192
    
    Inode size: 256
    
    Journal blocks: 6144
    
    Label:
    
    Blocks: 393216
    
    Block groups: 12
    
    Reserved block group size: 95
    
    Created filesystem with 2436/98304 inodes and 221139/393216 blocks
    
    Install system fs image: out/target/product/mt8735_tb_l1/system.img
    
    out/target/product/mt8735_tb_l1/system.img+out/target/product/mt8735_tb_l1/obj/PACKAGING/recovery_patch_intermediates/recovery-from-boot.p maxsize=1644331392 blocksize=4224 total=881392372 reserve=16612992
    
     
    
    #### make completed successfully (13:04 (mm:ss)) ####
    View Code

    虽然在SSD上编译,这个时间会缩短到5分钟左右,但还是比较长。所以在调试内核驱动模块时,最好使用动态加载模块的方式,以提高工作效率。

    至此,Android系统编译的环境基本搭建完成,后一篇将介绍如何搭建Android应用开发的环境。

  • 相关阅读:
    设计模式学习--Abstarct Factory
    WPF使用Canvas绘制可变矩形
    离线安装 Android 4.0 SDK
    引用了System.Configuration命名空间,却找不到ConfigurationManager类
    LIBXML2库使用指南2
    Quartz任务调度实践
    FastJson 自定义Serialize、Parser
    maven安装与创建多模块项目
    Zookeeper源码调试环境踩坑记录
    Apache Dubbo时间轮HashedWheelTimer算法的实现原理
  • 原文地址:https://www.cnblogs.com/we-hjb/p/5281500.html
Copyright © 2011-2022 走看看