Ubuntu16.04编译Android源码并导入AS

Posted by Chris on July 8, 2019

下载源码

  • 安装git工具和repo工具

    sudo -i
    cd /home
    apt-get install git
    git config --global user.name "test"
    git config --global user.email "test@test.com"
       
    下载工具
    git clone https://aosp.tuna.tsinghua.edu.cn/git-repo/  
    chmod a+x git-repo/repo
    
  • 配置repo环境变量和修改源

    vim  /etc/profile
    添加环境变量
    export PATH=/home/git-repo:$PATH
    source /etc/profile
    修改源
    vim /home/git-repo/repo 
    (REPO_URL = 'https://mirrors.tuna.tsinghua.edu.cn/git/git-repo')
    
  • 新建源码目录并同步源码

    mkdir ~/AndroidSource
    cd ~/AndroidSource 
    repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-9.0.0_r1
    repo sync 
    

安装依赖

sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib 
sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386 
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 libgl1-mesa-dev libxml2-utils xsltproc unzip m4
sudo apt-get install lib32z-dev ccache
#下面两个看着加
sudo apt-get install libswitch-perl
sudo apt-get install git-core gawk

出现的问题:libesd0-dev这个找不到的解决方案:

在etc/apt   的sources.list 添加镜像源
deb http://archive.ubuntu.com/ubuntu/ trusty main universe restricted multiverse
然后 sudo apt-get update  接着继续使用该命令安装就可以了

编译

  • 进入根目录,导入脚本

    source build/envsetup.sh
    
  • 选择

    lunch
    45
    
  • 编译开始

    make -j8
    
  • 出错清除

    make clobber
    

Ubuntu16 编译Android 6

文件路径 /home/snake/workspace/bsp/art/build/Android.common_build.mk 搜索,把ART_HOST_CLANG := true注销 改为如下

ART_HOST_CLANG := false
ifneq ($(WITHOUT_HOST_CLANG),true)
 # By default, host builds use clang for better warnings.
 #ART_HOST_CLANG := true
endif
make clean 

make update-api

make

编译SDK

source build/envsetup.sh
lunch sdk-eng
make sdk

模块编译

mmm packages/apps/Launcher2/

emulator

美化过装终端,坑过自己

单编模块

mmm   模块路径

mma   模块路径

make snod 重新打包system.img

导入As

mmm development/tools/idegen/

development/tools/idegen/idegen.sh

过滤一些模块

如果把Android所有的源码全部导入到Android Studio里面去,工程将会非常大,而且会很耗时间,那么我们就可以把不需要的模块给过滤掉。 打开android.iml文件,加入以下代码,修改excludeFolder的配置:

<excludeFolder url="file://$MODULE_DIR$/.repo"/>
<excludeFolder url="file://$MODULE_DIR$/abi"/>
<excludeFolder url="file://$MODULE_DIR$/frameworks/base/docs"/>
<excludeFolder url="file://$MODULE_DIR$/art"/>
<excludeFolder url="file://$MODULE_DIR$/bionic"/>
<excludeFolder url="file://$MODULE_DIR$/bootable"/>
<excludeFolder url="file://$MODULE_DIR$/build"/>
<excludeFolder url="file://$MODULE_DIR$/cts"/>
<excludeFolder url="file://$MODULE_DIR$/dalvik"/>
<excludeFolder url="file://$MODULE_DIR$/developers"/>
<excludeFolder url="file://$MODULE_DIR$/development"/>
<excludeFolder url="file://$MODULE_DIR$/device"/>
<excludeFolder url="file://$MODULE_DIR$/docs"/>
<excludeFolder url="file://$MODULE_DIR$/external"/>
<excludeFolder url="file://$MODULE_DIR$/hardware"/>
<excludeFolder url="file://$MODULE_DIR$/kernel-3.18"/>
<excludeFolder url="file://$MODULE_DIR$/libcore"/>
<excludeFolder url="file://$MODULE_DIR$/libnativehelper"/>
<excludeFolder url="file://$MODULE_DIR$/ndk"/>
<excludeFolder url="file://$MODULE_DIR$/out"/>
<excludeFolder url="file://$MODULE_DIR$/pdk"/>
<excludeFolder url="file://$MODULE_DIR$/platform_testing"/>
<excludeFolder url="file://$MODULE_DIR$/prebuilts"/>
<excludeFolder url="file://$MODULE_DIR$/rc_projects"/>
<excludeFolder url="file://$MODULE_DIR$/sdk"/>
<excludeFolder url="file://$MODULE_DIR$/system"/>
<excludeFolder url="file://$MODULE_DIR$/tools"/>
<excludeFolder url="file://$MODULE_DIR$/trusty"/>
<excludeFolder url="file://$MODULE_DIR$/vendor"/>