Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android4.2添加自己的產品分支及video的拷貝方法

Android4.2添加自己的產品分支及video的拷貝方法

編輯:關於Android編程

1、rk3168_v4.2\frameworks\base\data\videos下面的mp4的拷貝方法!

a、其實在我們的原始情況下這個目錄的東西並沒有拷貝到xxx/system/media/video下面,但是看到sounds目錄卻有拷貝為啥~

sounds目錄下有個AllAudio.mk,這個文件是怎麼調用的呢?

我在建產品分支的時候無意發現,加載其實很簡單~

b、資料收集:

http://blog.csdn.net/gchww/article/details/7838947

http://blog.csdn.net/tdstds/article/details/25823641

http://blog.csdn.net/stevenliyong/article/details/5285334

http://lhc180.blog.51cto.com/316940/774227/

c、拷貝文件的兩種方法(都在源碼內測試):

第一種、Android.mk

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := bootanimation
LOCAL_SRC_FILES := bootanimation.zip
LOCAL_MODULE_PATH := $(TARGET_OUT)/media
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX:= .zip
#LOCAL_MODULE_SUFFIX:= .txtfile
LOCAL_CERTIFICATE:= PRESIGNED
LOCAL_PRELINK_MODULE := false
include $(BUILD_PREBUILT)


第二種 1、在Z:\Backup\rk3168_v4.2\build\target\product\full_base.mk中添加:

# Get some sounds
$(call inherit-product-if-exists, frameworks/base/data/sounds/AllAudio.mk)

#add by hcm
#Get some videos
$(call inherit-product-if-exists, frameworks/base/data/videos/AllVideo.mk)

2、在Z:\Backup\rk3168_v4.2\frameworks\base\data\videos中新建:AllVideo.mk

$(call inherit-product, frameworks/base/data/videos/VideoPackage1.mk)
$(call inherit-product, frameworks/base/data/videos/VideoPackage2.mk)


分析流程包含在產品分支添加中:

1、當我們編譯Android源碼是執行下面兩條看到如下信息:

root@david-desktop:/home/hcm/Backup/rk3168_v4.2# . ./build/envsetup.sh
including device/generic/armv7-a-neon/vendorsetup.sh
including device/generic/armv7-a/vendorsetup.sh
including device/generic/mips/vendorsetup.sh
including device/generic/x86/vendorsetup.sh
including device/rockchip/rk30sdk_bnd/vendorsetup.sh
including device/rockchip/rk30sdk_hcm/vendorsetup.sh

including device/rockchip/rk30sdk/vendorsetup.sh

including sdk/bash_completion/adb.bash

從上面的信息我們可以看出,配置環境變量,在envsetup.sh 最重要是去包含了vendorsetup.sh,

root@david-desktop:/home/hcm/Backup/rk3168_v4.2# lunch

You're building on Linux

Lunch menu... pick a combo:
1. full-eng
2. full_x86-eng
3. vbox_x86-eng
4. full_mips-eng
5. mini_armv7a_neon-userdebug
6. mini_armv7a-userdebug
7. mini_mips-userdebug
8. mini_x86-userdebug
9. rk30sdk_bnd-eng
10. rk30sdk_hcmx-eng
11. rk30sdk-eng


Which would you like? [full-eng]

我們看到lunch命令輸出了一個Lunch菜單,該菜單列出了當前Android源碼支持的所有設備型號及其編譯類型。例如,第一項“full-eng”表示的設備“full”即為模擬器,並且編譯類型為“eng”即為工程機


一、調用流程:envsetup.sh --------> including device/xxx/xxx/vendorsetup.sh

lunch ---------> check_product()->get_build_var()-> build/core/main.mk -> build/core/config.mk

-> build/core/envsetup.mk -> build/core/product_config.mk

在build/core/product_config.mk 中編譯系統首先調用 build/core/product.mk中定義的函數get-all-product-makefiles ,來遍歷整個vendor 的子目錄, 找到vendor下所有的 AndroidProducts.mk, 再由 AndroidProducts.mk找到Z:\source\rk3168_v4.2\device\rockchip\rk30sdk_bnd\rk30sdk_bnd.mk 中定義了不同的 PRODUCT_NAME, PRODUCT_DEVICE 等信息,(我們也可以通過 打開build/core/product_config.mk 中的#$(dump-products) 語句使控制台編譯的時候輸出所有product 的信息) , 接著build/core/product_config.mk 會調用resolve-short-product-name 將TARGET_PRODUCT匹配的AndroidProducts.mk 中定義的 PRODUCT_DEVICE 賦值給TARGET_DEVICE。

有了這個TARGET_DEVICE, 再回到 build/core/config.mk,

會include $(TARGET_DEVCIE)/BoardConfig.mk

board_config_mk := /
$(strip $(wildcard /
$(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)/BoardConfig.mk /
vendor/*/$(TARGET_DEVICE)/BoardConfig.mk /
))

include $(board_config_mk)

而這個配置文件BoardConfig.mk 決定了目標系統編譯屬性,比如使用ALSA還是不是 GENERIC_AUDIO 等等

另外在這裡TARGET_DEVICE 宏也決定了TARGET_DEVICE_DIR, 因為TARGET_DEVICE_DIR 取的是上面提到的BoardConfig.mk 的路徑。

TARGET_DEVICE_DIR := $(patsubst %/,%,$(dir $(board_config_mk)))

當然Android 的Ob目標輸出也是由TARGET_DEVICE決定,見build/core/envsetup.mk

TARGET_OUT_ROOT_release := $(OUT_DIR)/target
TARGET_OUT_ROOT_debug := $(DEBUG_OUT_DIR)/target
TARGET_OUT_ROOT := $(TARGET_OUT_ROOT_$(TARGET_BUILD_TYPE))

TARGET_PRODUCT_OUT_ROOT := $(TARGET_OUT_ROOT)/product

PRODUCT_OUT := $(TARGET_PRODUCT_OUT_ROOT)/$(TARGET_DEVICE)

再回到 build/core/main.mk, 編譯系統接著做的一個件事情是,遍歷所有字目錄,找到所有Android.mk文件,並將這些Android.mk文件include 進來

#
# Typical build; include any Android.mk files we can find.
#

subdir_makefiles := /
$(shell build/tools/findleaves.py --prune=out --prune=.repo --prune=.git $(subdirs) Android.mk)

include $(subdir_makefiles)

我們再來看其中的

./build/target/board/Android.mk

,對了它引用了

include $(TARGET_DEVICE_DIR)/AndroidBoard.mk

由上面TARGET_DEVICE_DIR的定義,這下又進入了

vendor 下TARGET_DEVICE指向的目錄了,這個mk文件中定義了特定Product需要編譯和安裝app 和 script.

二、Android lunch調用關系

1. 調用流程圖:

\

2. 調用關系分析

在編譯Android產品的時候我們首先會導入. build/envsetup.sh ,然後lunch,這時候我們可以看到幾個基本的產品版本。

從現象回推,首先查看envsetup.sh文件中的lunch函數:

具體分析見:lunch函數分析

在envsetup.sh中,有幾個比較重要的函數。Lunch(),check_product(),print_lunch_menu(),get_build_var(),gettop,add_lunch_combo(),set_stuff_for_environment(),set_java_home(),findmakefile()。

1) lunch

[plain] view plaincopy
  1. functionlunch()
  2. {
  3. local answer
  4. if [ "$1" ] ; then
  5. # lunch後面直接帶參數
  6. answer=$1
  7. else
  8. # lunch後面不帶參數,則打印處所有的target product和variant菜單提供用戶選擇
  9. print_lunch_menu
  10. echo -n "Which would you like?[generic-eng] "
  11. read answer
  12. fi
  13. local selection=
  14. if [ -z "$answer" ]
  15. then
  16. # 如果用戶在菜單中沒有選擇,直接回車,則為系統缺省的generic-eng
  17. selection=generic-eng
  18. elif [ "$answer" ="simulator" ]
  19. then
  20. # 如果是模擬器
  21. selection=simulator
  22. elif(echo -n $answer | grep -q -e "^[0-9][0-9]*{1}quot;)
  23. then
  24. # 如果answer是選擇菜單的數字,則獲取該數字對應的字符串
  25. if [ $answer -le${#LUNCH_MENU_CHOICES[@]} ]
  26. then
  27. selection=${LUNCH_MENU_CHOICES[$(($answer-$_arrayoffset))]}
  28. fi
  29. # 如果 answer字符串匹配 *-*模式(*的開頭不能為-)
  30. elif (echo -n $answer | grep -q -e"^[^\-][^\-]*-[^\-][^\-]*{1}quot;)
  31. then
  32. selection=$answer
  33. fi
  34. if [ -z "$selection" ]
  35. then
  36. echo
  37. echo "Invalid lunch combo:$answer"
  38. return 1
  39. fi
  40. # special case the simulator
  41. if [ "$selection" ="simulator" ]
  42. then
  43. # 模擬器模式
  44. export TARGET_PRODUCT=sim
  45. export TARGET_BUILD_VARIANT=eng
  46. export TARGET_SIMULATOR=true
  47. export TARGET_BUILD_TYPE=debug
  48. else
  49. # 將 product-variant模式種的product分離出來
  50. local product=$(echo -n $selection |sed -e "s/-.*$//")
  51. # 檢查product,調用關系 check_product()->get_build_var()->build/core/config.mk
  52. check_product $product
  53. if [ $? -ne 0 ]
  54. then
  55. echo
  56. echo "** Don't have a productspec for: '$product'"
  57. echo "** Do you have the rightrepo manifest?"
  58. product=
  59. fi
  60. # 將 product-variant模式種的variant分離出來
  61. local variant=$(echo -n $selection | sed-e "s/^[^\-]*-//")
  62. # 檢查之,看看是否在 (user userdebug eng) 范圍內
  63. check_variant $variant
  64. if [ $? -ne 0 ]
  65. then
  66. echo
  67. echo "** Invalid variant:'$variant'"
  68. echo "** Must be one of${VARIANT_CHOICES[@]}"
  69. variant=
  70. fi
  71. if [ -z "$product" -o -z"$variant" ]
  72. then
  73. echo
  74. return 1
  75. fi
  76. export TARGET_PRODUCT=$product
  77. export TARGET_BUILD_VARIANT=$variant
  78. export TARGET_SIMULATOR=false
  79. export TARGET_BUILD_TYPE=release
  80. fi # !simulator


  81. 2) Check_product:

    [plain] view plaincopy
    1. functioncheck_product()
    2. {
    3. T=$(gettop)
    4. if [ ! "$T" ]; then
    5. echo "Couldn't locate the top ofthe tree. Try setting TOP.">&2
    6. return
    7. fi
    8. CALLED_FROM_SETUP=trueBUILD_SYSTEM=build/core \
    9. TARGET_PRODUCT=$1 TARGET_BUILD_VARIANT=\
    10. TARGET_SIMULATOR= TARGET_BUILD_TYPE= \
    11. TARGET_BUILD_APPS= \
    12. get_build_varTARGET_DEVICE > /dev/null
    13. # hide successful answers, but allow theerrors to show
    14. } 檢查指定的TARGET_PRODUCT是否允許,默認的有sim和generic。如果不允許,則輸出錯誤信息,允許則不顯示

      3) Print_lunch_menu()

      [plain] view plaincopy
      1. functionprint_lunch_menu()
      2. {
      3. local uname=$(uname)
      4. echo
      5. echo "You're building on" $uname
      6. echo
      7. echo "Lunch menu... pick acombo:"
      8. local i=1
      9. local choice
      10. #循環查找LUNCH_MENU_CHOICES中的版本
      11. for choice in ${LUNCH_MENU_CHOICES[@]}
      12. do
      13. echo " $i. $choice"
      14. i=$(($i+1))
      15. done
      16. echo
      17. } 該函數負責打印已經定義的版本

        4) Get_build_var()

        [plain] view plaincopy
        1. functionget_build_var()
        2. {
        3. T=$(gettop)
        4. if [ ! "$T" ]; then
        5. echo "Couldn't locate the top ofthe tree. Try setting TOP.">&2
        6. return
        7. fi
        8. CALLED_FROM_SETUP=trueBUILD_SYSTEM=build/core \
        9. make --no-print-directory -C"$T" -f build/core/config.mk dumpvar-$1
        10. } 列出make腳本中某變量的值,當前為build/core/config.mk

          5) Gettop()

          [plain] view plaincopy
          1. function gettop
          2. {
          3. local TOPFILE=build/core/envsetup.mk
          4. if [ -n "$TOP" -a -f"$TOP/$TOPFILE" ] ; then
          5. echo $TOP
          6. # 如果TOP不為空,並且envsetup.mk存在,函數直接返回TOP對應路徑
          7. else
          8. # 否則(指找不到envsetup.mk)如下處理
          9. if [ -f $TOPFILE ] ; then
          10. # The following circumlocution(repeated below as well) ensures
          11. # that we record the true directoryname and not one that is
          12. # faked up with symlink names.
          13. PWD= /bin/pwd
          14. else
          15. # We redirect cd to /dev/null incase it's aliased to
          16. # a command that prints somethingas a side-effect
          17. # (like pushd)
          18. local HERE=$PWD
          19. T=
          20. while [ \( ! \( -f $TOPFILE \) \)-a \( $PWD != "/" \) ]; do
          21. cd .. > /dev/null
          22. T=`PWD= /bin/pwd`
          23. done
          24. cd $HERE > /dev/null
          25. if [ -f "$T/$TOPFILE" ];then
          26. echo $T
          27. fi
          28. fi
          29. fi
          30. } 返回當前android代碼樹的頂層路徑。前提是當前路徑位於android代碼樹中

            6) Add_lunch_combo()

            [plain] view plaincopy
            1. functionadd_lunch_combo()
            2. {
            3. local new_combo=$1
            4. local c
            5. for c in ${LUNCH_MENU_CHOICES[@]} ; do
            6. if [ "$new_combo" ="$c" ] ; then
            7. return
            8. fi
            9. done
            10. LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
            11. } 向環境變量LUNCH_MENU_CHOICES標識的列表中添加項

              7) Set_stuff_for_environment()

              [plain] view plaincopy
              1. functionset_stuff_for_environment()
              2. {
              3. settitle
              4. set_java_home
              5. setpaths
              6. set_sequence_number
              7. export ANDROID_BUILD_TOP=$(gettop)
              8. } 設置android編譯需要的環境變量

                8) Set_java_home

                [plain] view plaincopy
                1. functionset_java_home() {
                2. if [ ! "$JAVA_HOME" ]; then
                3. case `uname -s` in
                4. Darwin)
                5. exportJAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
                6. ;;
                7. *)
                8. exportJAVA_HOME=/usr/lib/jvm/java-6-sun
                9. ;;
                10. esac
                11. fi
                12. } 設置java運行環境

                  9) findmakefile

                  [plain] view plaincopy
                  1. functionfindmakefile()
                  2. {
                  3. TOPFILE=build/core/envsetup.mk
                  4. # We redirect cd to /dev/null in case it's aliased to
                  5. # a command that prints something as a side-effect
                  6. # (like pushd)
                  7. local HERE=$PWD
                  8. T=
                  9. while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD !="/" \) ]; do
                  10. T=$PWD
                  11. if [ -f "$T/Android.mk" ];then
                  12. echo$T/Android.mk
                  13. # 如果找到Android.mk,echo出來的全路徑將作為函數的返回值賦給某個變量
                  14. cd $HERE> /dev/null
                  15. return
                  16. fi
                  17. cd .. > /dev/null
                  18. done
                  19. cd $HERE > /dev/null
                  20. } 此外還有一段比較重要的代碼

                    [plain] view plaincopy
                    1. # Execute thecontents of any vendorsetup.sh files we can find.
                    2. for f in`/bin/ls vendor/*/vendorsetup.sh vendor/*/build/vendorsetup.sh device/*/*/vendorsetup.sh2> /dev/null`
                    3. do
                    4. echo "including $f"
                    5. . $f
                    6. done
                    7. unset f

                      這段代碼尋找vendor,build,device指定目錄下的vendorsetup.sh。在vendorsetup.sh中定義了各版本的產品。

                      三、通過上面分析我們如果要定制自己的lunch分支主要是添加自己的平台到Z:\source\rk3168_v4.2\device\芯片廠商名\芯片名

                      1、具體修改文件:由於執行. ./build/envsetup.sh找到vendorsetup.sh,在其中加入自己的平台版本號!

                      add_lunch_combo rk30sdk_bnd-eng

                      2、lunch---->, AndroidProducts.mk---->Z:\source\rk3168_v4.2\device\rockchip\rk30sdk_bnd\rk30sdk_bnd.mk

                      在rk30sdk_bnd.mk的關鍵部分

                      include device/rockchip/rk30sdk_bnd/BoardConfig.mk

                      #或者為$(call inherit-product, $(SRC_TARGET_DIR)/product/full_base.mk)
                      $(call inherit-product, device/rockchip/rk30sdk_bnd/device.mk)(或者將full_base.mk包含在其中)
                      full_base.mk此文件主要指定對系統語言,APP編譯配置文件,sounds的拷貝的mk文件!

                      PRODUCT_BRAND := rk30sdk_bnd
                      PRODUCT_DEVICE := rk30sdk_bnd //指定Z:\source\rk3168_v4.2\out\target\product\rk30sdk_bnd目錄名

                      //指定Z:\source\rk3168_v4.2\device\rockchip\rk30sdk_bnd目錄名

                      PRODUCT_NAME := rk30sdk_bnd //目標設備名
                      PRODUCT_MODEL := rk30sdk_bnd
                      PRODUCT_MANUFACTURER := rockchip

                      3、至於其他的根據你要引用的變量來決定如:Z:\source\rk3168_v4.2\device\rockchip\rk30sdk_bnd\BoardConfig.mk 中

                      include device/rockchip/$(TARGET_PRODUCT)/wifi_bt.mk的$(TARGET_PRODUCT)就和PRODUCT_NAME有關,因為要知道准確路徑!

                      4、注解:

                      Z:\source\rk3168_v4.2\device\rockchip\rk30sdk_bnd\BoardConfig.mk中

                      //MAX-SIZE=512M, for generate out/.../system.img 對system.img的大小進行了限制
                      BOARD_SYSTEMIMAGE_PARTITION_SIZE ?= 671088640
                      BOARD_FLASH_BLOCK_SIZE ?= 131072




  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved