安卓软件开发常用命令集合

本文首发地址 https://h89.cn/archives/180.html
最新更新地址 https://gitee.com/chenjim/chenjimblog

adb 常用命令

adb 相关命令已经抽离到单独博文 adb常用命令详解–提升开发效率利器


android 源码编译相关命令

## 创建仓库,repo 使用可参考  http://h89.cn/archives/254.html
repo init -u ssh://ha/t700_v5.1/manifest
repo sync
./build/envsetup.sh  #加载编译环境变量
lunch  cm_klimtwifi-userdebug  #设置编译的项目
make -j8    #8 cpu 编译
make otapackage -j8    #ota打包

mmm packages/apps/Browser2/  #编译模块Browser2   
make Browser2  #同上,编译模块Browser2
# 以下命令 参考 build/envsetup.sh
croot: Changes directory to the top of the tree.  
m: Makes from the top of the tree.  
mm: Builds all of the modules in the current directory, and their dependencies.  
mmm: Builds all of the modules in the supplied directories, and their dependencies.  

framework 开发相关

  • 打开 ActivityManager等模块日志
    修改 ActivityManagerDebugConfig.java 中 DEBUG_ALL 为 true
    类似很多 JAVA 和 CPP 文件头都定义了 LOG 开关,可以针对性开启

fastboot下载system.img等

adb reboot bootloader
sudo fastboot flash system '/out_roms/system.img'
sudo fastboot reboot

sideload 刷入OTA升级包

例如 刷入 build-ota—123.zip
adb reboot recovery
设备重启后选择apply update from adb
adb sideload build-ota-123.zip


tar 常用命令

  • tar 分卷压缩
    要将目录logs打包压缩并分割成多个1M的文件,可以用下面的命令
    tar cjf - logs/ |split -b 1m - logs.tar.bz2.
    完成后会产生下列文件
    logs.tar.bz2.aa, logs.tar.bz2.ab, logs.tar.bz2.ac
  • tar 分卷解压
    cat logs.tar.bz2.a* | tar xj
  • 压缩为.tar.gz的包
    tar czf hello.tar.gz hello
  • 解压.tar.gz到已存在的目录
    tar xvzf hello.tar.gz -C out.dir

Android NDK开发Crash错误定位

原文http://blog.csdn.net/xyang81/article/details/42319789

  • 方式1:使用arm-linux-androideabi-addr2line 定位出错位置
    以arm架构的CPU为例,执行如下命令:
    android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-addr2line -e hello-jni/obj/local/armeabi-v7a/libhello-jni.so 00000cf4 00000d1c
    -e:指定so文件路径
    0000cf4 0000d1c:出错的汇编指令地址

  • 方式2:使用arm-linux-androideabi-objdump 定位出错的函数信息
    android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-objdump -S -D hello-jni/obj/local/armeabi-v7a/libhello-jni.so > dump.log
    通过这种方式,也可以查出这两个出错的指针地址分别位于哪个函数中。

  • 方式3:ndk-stack 以armv7架构为例,执行如下命令:
    adb logcat | ndk-stack -sym hello-jni/obj/local/armeabi-v7a
    测试人员发现crash,用adb logcat保存日志文件,然后发给程序员通过ndk-stack命令分析
    adb logcat > crash.log
    NDK_DIR/ndk-stack -sym hello-jni/obj/local/armeabi-v7a -dump crash.log


OTA 升级,差分包制作

ota=./build/tools/releasetools/ota_from_target_files
$ota -i v2_old.zip v3_new.zip v2_3_ota.zip

//v2_old.zip和v3_new.zip是*_target_files.zip 在以下目录  
./out/target/product/项目名称/obj/PACKAGING/target_files_intermediates

//加签名的ota包
SFile=./device/mediatek/build/releasetools/mt_ota_from_target_files.py
KFile=./device/mediatek/common/security/vanzo/releasekey
$ota -s $SFile --block -k $KFile  -i v2_old.zip v3_new.zip v2_3_ota.zip 

odex去除的源码模块编译方法

build/core/dex_preopt_odex_install.mk 中添加

ifeq ($(LOCAL_MODULE),Gallery2)
LOCAL_DEX_PREOPT:=
endif

编个系统Rom版本,下载到手机。
或者在Android.mk 中添加
LOCAL_DEX_PREOPT := false
然后mmm 图库模块,adb push编译好的apk,重启设备


windows的adb自动按键测试bat脚本

adb 相关命令已经抽离到单独博文 adb常用命令详解–提升开发效率利器


MTK 按键映射dws修改

vendor/mediatek/proprietary/scripts/dct/DrvGen.exe
打开kernel-*.*/drivers/misc/mediatek/dws/mt6739/项目名称.dws


jgrep cgrep mgrep resgrep mangrep mgrep

在源码 build/envsetup.sh中有相关命令
需要执行source build/envsetup.sh将这些命令加到环境中
这些命令详细封装如下

function ggrep()
{
    find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \
        -exec grep --color -n "$@" {} +
}

function jgrep()
{
    find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \
        -exec grep --color -n "$@" {} +
}

function cgrep()
{
    find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) \
        -exec grep --color -n "$@" {} +
}

function resgrep()
{
    for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do
        find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} +
    done
}

function mangrep()
{
    find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \
        -exec grep --color -n "$@" {} +
}

function mgrep()
{
    find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o \( -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk|.*\.bp)' -o -regextype posix-extended -regex '(.*/)?(build|soong)/.*[^/]*\.go' \) -type f \
        -exec grep --color -n "$@" {} +
}

相关连接

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

清霜辰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值