您的位置:首页 > 移动开发 > Android开发

android编译user版本,如何启用user版本的adb

2014-05-13 09:50 423 查看
今天需要编译一个android4.2.2 的user版本来测试;

android编译相关的东西在源码的build目录下,全编前需要执行

. build/envsetup.sh

执行上面的shell脚本会include一些其他目录下的shell脚本,以及声明一些命令函数,比如说接下来执行的choosecombo命令;
1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13


function choosecombo()
{
    choosetype $1
    echo
    echo
    chooseproduct $2
    echo
    echo
    choosevariant $3
    echo
    set_stuff_for_environment
    printconfig
}


choosecombo release msm8960 eng;

release表示的是Build type;(choose type) type有release和debug两个选项

msm8960表示的是product;(choose product) product有genric和msm8960,当然product根据项目不同是有不同选项的;

eng表示的是版本类型;(choose variant) variant有user,userdebug,eng三个选项

通过adb shell中执行getprop persist.sys.usb.config,可以看到系统usb的相关选项,persist.sys.usb.config显示的就是当前系统关于usb选项的系统配置;

diag,serial_smd,serial_tty,rmnet_bam,mass_storage,adb

全编脚本中make命令会调用build/core/**main.mk**,在里面可以看到一段关于debuggable的编译选项,赋值ADDITIONAL_DEFAULT_PROPERTIES;
1
2
3
4
5
6
7
8
9


ifeq (true,$(strip $(enable_target_debugging)))
  # Target is more debuggable and adbd is on by default
  ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1
  # Include the debugging/testing OTA keys in this build.
  INCLUDE_TEST_OTA_KEYS := true
else # !enable_target_debugging
  # Target is less debuggable and adbd is off by default
  ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0
endif # !enable_target_debugging


并且
1


include $(BUILD_SYSTEM)/Makefile


在build/core/Makefile中的
1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18


# default.prop
INSTALLED_DEFAULT_PROP_TARGET := $(TARGET_ROOT_OUT)/default.prop
ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_DEFAULT_PROP_TARGET)
ADDITIONAL_DEFAULT_PROPERTIES := 
    $(call collapse-pairs, $(ADDITIONAL_DEFAULT_PROPERTIES))
ADDITIONAL_DEFAULT_PROPERTIES += 
    $(call collapse-pairs, $(PRODUCT_DEFAULT_PROPERTY_OVERRIDES))
ADDITIONAL_DEFAULT_PROPERTIES := $(call uniq-pairs-by-first-component, 
    $(ADDITIONAL_DEFAULT_PROPERTIES),=)
$(INSTALLED_DEFAULT_PROP_TARGET):
    @echo Target buildinfo: $@
    @mkdir -p $(dir $@)
    $(hide) echo "#" > $@; 
            echo "# ADDITIONAL_DEFAULT_PROPERTIES" >> $@; 
            echo "#" >> $@;
    $(hide) $(foreach line,$(ADDITIONAL_DEFAULT_PROPERTIES), 
        echo "$(line)" >> $@;)
    build/tools/post_process_props.py $@


执行**post_process_props.py**脚本文件,**post_process_props.py会根据main.mk中的ro.debuggable指定的值来生成default.prop的persist.sys.usb.config;**

** 不过打开之后,对于user 版本adb shell 开启的还是shell 权限,而不是root 权限,如果您需要root 权限,需要再改一下system/core/adb/adb.c 里面的should_drop_privileges()
这个函数,在#ifndef ALLOW_ADBD_ROOT 时return 0; 而不是return 1; 即可。

**

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14


# If ro.debuggable is 1, then enable adb on USB by default
  # (this is for userdebug builds)
  if prop.get("ro.debuggable") == "1":
    val = prop.get("persist.sys.usb.config")
    if val == "":
      val = "adb"
    else:
      val = val + ",adb"
    prop.put("persist.sys.usb.config", val)
  # UsbDeviceManager expects a value here.  If it doesn't get it, it will
  # default to "adb". That might not the right policy there, but it's better
  # to be explicit.
  if not prop.get("persist.sys.usb.config"):
    prop.put("persist.sys.usb.config", "none");


如果想要编译user版本的时候打开adb,修改
1


prop.put("persist.sys.usb.config", "none");



1


prop.put("persist.sys.usb.config", "adb");


即可;

eng版本的default.prop
1
2
3
4
5
6
7


#
# ADDITIONAL_DEFAULT_PROPERTIES
#
ro.secure=0
ro.allow.mock.location=1
ro.debuggable=1
persist.sys.usb.config=adb


默认user版本default.prop

**

**
1
2
3
4
5
6
7


#
# ADDITIONAL_DEFAULT_PROPERTIES
#
ro.secure=1
ro.allow.mock.location=1
ro.debuggable=0
persist.sys.usb.config=none


以上结论经过自己验证可行,如有错误之处,希望能够指出;

另外,针对user版本上无法进行usb debug,可以在settings-About phone-Build number上点击N次,然后就会提示“No need,you are already a developer”,这时,settings中

就会出现Develper options选项,进去就可以打开usb debug了;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: