Android開發
ADB 使用
前言
adb,全稱 Android Debug Bridge,是 Android 的命令行調試工具,可以完成多種功能,如跟蹤系統日志,上傳下載文件,安裝應用等。
準備連接
支持兩種ADB鏈接方式:USB和網絡連接。
Windows下的 ADB 安裝
首先參照安裝 RK USB 驅動一節安裝好驅動。然后到 http://adbshell.com/download/download-adb-for-windows.html 下載 adb.zip,解壓到C:\adb以方便調用。 打開命令行窗口,輸入:
如果一切正常,就可以進入adbshell,在設備上面運行命令。
Ubuntu 下的 ADB 安裝
sudoapt-getinstallandroid-tools-adb
mkdir-p~/.androidvi~/.android/adb_usb.ini# 添加以下一行0x2207
sudovi/etc/udev/rules.d/51-android.rules# 添加以下一行:
SUBSYSTEM=="usb",ATTR{idVendor}=="2207",MODE="0666"
sudoudevadmcontrol--reload-rulessudoudevadmtrigger
sudoadbkill-serveradbstart-server
常用 ADB 命令
連接管理
列出所有連接設備及其序列號
如果有多個連接設備,則需要使用序列號來區分:
exportANDROID_SERIAL=<設備序列號>adbshellls
多設備下連接指定設備
可以通過網絡來連接 adb:
# 讓設備端的 adbd 重啟,并在 TCP
端口 5555 處監聽adbtcpip5555# 此時可以斷開 USB 連接# 遠程連接設備,設備的 IP 地址是 192.168.1.100adbconnect192.168.1.100:5555# 斷開連接adbdisconnect192.168.1.100:5555
調試
獲取系統日志 adb logcat
# 查看全部日志adblogcat# 僅查看部分日志adblogcat-sWifiStateM
achineStateMachine
運行命令 adb shell
獲取詳細運行信息 adb bugreport
adbbugreport用于錯誤報告,里面包含大量有用的信息。
adbbugreport# 保存到本地,方便用編輯器查看adbbugreport>bugreport.txt
root 權限
如果 TARGET_BUILD_VARIANT 使用的是 userdebug 模式,要獲得 root 權限,需要先運行:
讓 adb 的設備端切換到 root 權限模式,這樣 adb remount 等需要 root 權限的命令才會成功。
應用管理
安裝應用 adb install
選項包括:
-l forward-lock -r 重新安裝應用,保留原先數據 -s 安裝到
SD 卡上,而不是內部存儲
# 安裝 facebook.apkadbinstallfacebook.apk# 升級 twit
ter.apkadbinstall-rtwitter.apk
如果安裝成功,工具會返回成功提示 “Success”;失敗的話,一般是以下幾種情況:
-
INSTALL_FAILED_ALREADY_EXISTS: 此時需要用 -r 參數來重新安裝。
-
INSTALL_FAILED_SIGNATURE_ERROR: 應用的簽名不一致,可能是發布版和調試版簽名不同所致。如果確認 APK 文件簽名正常,可以用 adb uninstall 命令先卸載舊的應用,然后再安裝。
-
INSTALL_FAILED_INSUFFICIENT_STORAGE: 存儲空間不足,需要檢查設備存儲情況。
卸載應用 adb uninstall
adbuninstallcom.android.ch
rome
應用包名稱可以用以下命令列出:
運行結果是:
package:/system/app/Bluetooth.apk=com.android.bluetooth
前面是 apk 文件,后面則是對應的包名稱。
命令行幫助信息 adb help
AndroidDebugBridgeversion1.0.31-a-directsadbtolistenonallinte
rfacesforaconnec
tion-d-directscommandtotheonlyconnectedUSBdevicereturnsanerrorifmorethanoneUSBdeviceispresent.-e-directscommandtotheonlyrunningemulator.returnsanerrorifmorethanoneemulatorisrunning.-s
-directscommandtothedeviceoremulatorwiththegivenserialnumberorqualifier.OverridesANDROID_SERIALenvironmentvariable.-p-simpleproductnamelike'sooner',orarelative/absolutepathtoaproductoutdirectorylike'out/target/product/sooner'.If-pisnotspecified,theANDROID_PRODUCT_OUTenvironmentvariableisused,whichmustbeanabsolutepath.-H-Nameofadbserverhost(default:localhost)-P-Portofadbserver(default:5037)devices[-l]-listallconnecteddevices('-l'willalsolistdevicequalifiers)connect[:]-connecttoadeviceviaTCP/IPPort5555isusedbydefaultifnoportnumberisspecified.disconnect[[:]]-disconnectfromaTCP/IPdevice.Port5555isusedbydefaultifnoportnumberisspecified.UsingthiscommandwithnoadditionalargumentswilldisconnectfromallconnectedTCP/IPdevices.devicecommands:adbpush[-p]-copyfile/dirtodevice('-p'todisplaythetransferprogress)adbpull[-p][-a][]-copyfile/dirfromdevice('-p'todisplaythetransferprogress)('-a'meanscopytimestampandmode)adbsync[]-copyhost->deviceonlyifchanged(-lmeanslistbutdon't copy)(see'adb help all')adbshell-runremoteshellinteractivelyadbshell-runremoteshellcommandadbemu-runemulatorconsolecommandadblogcat[]-Viewdevicelogadbforward--list-listallforwardsocketconnections.theformatisalistoflineswiththefollowingformat:" "" ""\n"adbforward-forwardsocketconnectionsforwardspecsareoneof:tcp:localabstract:localreserved:localfilesystem:dev:jdwp:(remoteonly)adbforward--no-rebind-sameas'adb forward'butfailsifisalreadyforwardedadbforward--remove-removeaspecificforwardsocketconnectionadbforward--remove-all-removeallforwardsocketconnectionsadbjdwp-listPIDsofprocesseshostingaJDWPtransportadbinstall[-l][-r][-d][-s][--algo--key--iv]-pushthispackagefiletothedeviceandinstallit('-l'meansforward-locktheapp)('-r'meansreinstalltheapp,keepingitsdata)('-d'meansallowversioncodedowngrade)('-s'meansinstallonSDcardinsteadofinternalstorage)('--algo','--key',and'--iv'meanthefileisencryptedalready)adbuninstall[-k]-removethisapppackagefromthedevice('-k'meanskeepthedataandcachedirectories)adbbugreport-returnallinformationfromthedevicethatshouldbeincludedinabugreport.adbbackup[-f][-apk|-noapk][-obb|-noobb][-shared|-noshared][-all][-system|-nosystem][]-writeanarchiveofthedevice's data to.Ifno-foptionissuppliedthenthedataiswrittento"backup.ab"inthecurrentdirectory.(-apk|-noapkenable/disablebackupofthe.apksthemselvesinthearchive;thedefaultisnoapk.)(-obb|-noobbenable/disablebackupofanyinstalledapkexpansion(aka.obb)filesassociatedwitheachapplication;thedefaultisnoobb.)(-shared|-nosharedenable/disablebackupofthedevice'ssharedstorage/SDcardcontents;thedefaultisnoshared.)(-allmeanstobackupallinstalledapplications)(-system|-nosystemtoggleswhether-allautomaticallyincludessystemapplications;thedefaultistoincludesystemapps)(isthelistofapplicationstobebackedup.Ifthe-allor-sharedflagsarepassed,thenthepackagelistisoptional.Applicationsexplicitlygivenonthecommandlinewillbeincludedevenif-nosystemwouldordinarilycausethemtobeomitted.)adbrestore-restoredevicecontentsfromthebackuparchiveadbhelp-showthishelpmessageadbversion-showversionnumscripting:adbwait-for-device-blockuntildeviceisonlineadbstart-server-ensurethatthereisaserverrunningadbkill-server-killtheserverifitisrunningadbget-state-prints:offline|bootloader|deviceadbget-serialno-prints:adbget-devpath-prints:adbstatus-window-continuouslyprintdevicestatusforaspecifieddeviceadbremount-remountsthe/systempartitiononthedeviceread-writeadbreboot[bootloader|recovery]-rebootsthedevice,optionallyintothebootloaderorrecoveryprogramadbreboot-bootloader-rebootsthedeviceintothebootloaderadbroot-restartstheadbddaemonwithrootpermissionsadbusb-restartstheadbddaemonlisteningonUSBadbtcpip-restartstheadbddaemonlisteningonTCPonthespecifiedportnetworking:adbppp[parameters]-RunPPPoverUSB.Note:youshouldnotautomaticallystartaPPPconnection.referstothettyforPPPstream.Eg.dev:/dev/omap_csmi_tty1[parameters]-Eg.defaultroutedebugdumplocalnottyusepeerdnsadbsyncnotes:adbsync[]canbeinterpretedinseveralways:-Ifisnotspecified,both/systemand/datapartitionswillbeupdated.-Ifitis"system"or"data",onlythecorrespondingpartitionisupdated.environmentalvariables:ADB_TRACE-Printdebuginformation.Acommaseparatedlistofthefollowingvalues1orall,adb,sockets,packets,rwx,usb,sync,sysdeps,transport,jdwpANDROID_SERIAL-Theserialnumbertoconnectto.-stakespriorityoverthisifgiven.ANDROID_LOG_TAGS-Whenusedwiththelogcatoption,onlythesedebugtagsareprinted.
編譯 Android 固件
準備工作
編譯 Android 對機器的配置要求較高:
官方推薦 Ubuntu 14.04 操作系統,經測試,Ubuntu 12.04 也可以編譯運行成功,只需要滿足 http://source.android.com/source/building.html 里的軟硬件配置即可。編譯環境的初始化可參考 http://source.android.com/source/initializing.html 。
sudoapt-getinstallopenjdk-8-jdk
提示:安裝 openjdk-8-jdk,會更改 JDK 的默認鏈接,這時可用:
$ sudo update-alternatives --config
java $ sudo update-alternatives --config javac
來切換 JDK 版本。SDK 在找不到操作系統默認 JDK 的時候會使用內部設定的 JDK 路徑,因此,為了讓同一臺機器可以編譯 Android 5.1 及之前的版本,去掉鏈接更方便:
$ sudo /var/lib/dpkg/info/openjdk-8-jdk:
amd64.prerm remove
sudoapt-getinstallgitgnupgflexbisongperfbuild-essential\zipcurllibc6-devlibncurses5-dev:i386x11proto-core-dev\libx11-dev:i386libreadline6-dev:i386libgl1-mesa-glx:i386\g++-multilibmingw32tofrodosgcc-multilibia32-libs\
python-markdownlibxml2-utilsxsltproczlib1g-dev:i386\lzoplibssl1.0.0libssl-dev
sudoapt-getinstallgit-coregnupgflexbisongperflibsdl1.2-dev\libesd0-devlibwxgtk2.8-devsquashfs-toolsbuild-essentialzipcurl\libncurses5-devzlib1g-devpngcrushschedtoollibxml2libxml2-utils\xsltproclzoplibc6-devschedtoolg++-multiliblib32z1-devlib32ncurses5-dev\lib32readline-gplv2-devgcc-multiliblibswitch-perl\libssl1.0.0libssl-dev
下載 Android SDK
Android SDK 源碼包比較大,可以通過如下方式獲取Android7.1源碼包:[下載鏈接]
下載完成后先驗證一下 MD5 碼:
$ md5sum /path/to/Firefly-RK3399_Android7.1.2_git_20180126.7z 699cff05bfa39a341e7aae3857cea4a7 Firefly-RK3399_Android7.1.2_git_20180126.7z
確認無誤后,就可以解壓:
mkdir-p~/proj/firefly-rk3399cd~/proj/firefly-rk33997zx/path/to/Firefly-RK3399_Android7.1.2_git_20180126.7z-r-o./gitreset--hard
注意:解壓后務必要先更新下遠程倉庫。 以下為從 gitlab 處更新的方法:
# 進入SDK根目錄cd~/proj/firefly-rk3399# 如果沒有拉取遠程倉庫,需要先拉取對應bundle倉庫gitclonehttps://gitlab.com/TeeFirefly/rk3399-nougat-bundle.git.bundle# 更新SDK,并且后續更新不需要再次拉取遠程倉庫,直接執行以下命令即可.bundle/update# 按照提示已經更新內容到 FETCH_HEAD,同步FETCH_HEAD到firefly-rk3399分支gitrebaseFETCH_HEAD
AIO-3399JD4
產品編譯方法
./FFTools/make.sh-drk3399-firefly-aiojd4-j8-lrk3399_firefly_aiojd4_box-userdebug./FFTools/mkupdate/mkupdate.sh-lrk3399_firefly_aiojd4_box-userdebug
HDMI+lvds編譯
./FFTools/make.sh-drk3399-firefly-aiojd4-lvds-HSX101H40C-j8-lrk3399_firefly_aiojd4_lvds_box-userdebug./FFTools/mkupdate/mkupdate.sh-lrk3399_firefly_aiojd4_lvds_box-userdebug
手動編譯AIO-3399JD4
編譯前執行如下命令配置環境變量:
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
cd~/proj/firefly-rk3399/kernel/makeARCH=
arm64firefly_defconfigmake-j8ARCH=arm64rk3399-firefly-aiojd4.img
cd~/proj/firefly-rk3399/u-boot/makerk3399_box_defconfigmakeARCHV=aarch64-j8
cd~/proj/firefly-rk3399/sourcebuild/envsetup.shlunchrk3399_firefly_aiojd4_box-userdebugmake-j8./mkimage.sh
打包成統一固件 update.img
編譯完可以用Firefly官方的腳本打包成統一固件,執行如下命令:
./FFTools/mkupdate/mkupdate.shupdate
打包完成后將在rockdev/Image-rk3399_firefly_aiojd4_box/下生成統一固件:update.img
在 Windows 下打包統一固件 update.img 也很簡單,將編譯生成的文件拷貝到 AndroidTool 的 rockdev\Image 目錄中,然后運行 rockdev 目錄下的 mkupdate.bat 批處理文件即可創建 update.img 并存放到 rockdev\Image 目錄里。
燒寫分區映像
編譯的時候執行 ./mkimage.sh 會重新打包 boot.img 和 system.img, 并將其它相關的映像文件拷貝到目錄 rockdev/Image-rk3399_firefly_xxx/ 中。以下列出一般固件用到的映像文件:
-
boot.img :Android 的初始文件映像,負責初始化并加載 system 分區。
-
kernel.img :內核映像。
-
misc.img :misc 分區映像,負責啟動模式切換和急救模式的參數傳遞。
-
parameter.txt :emmc的分區信息
-
recovery.img :急救模式映像。
-
resource.img :資源映像,內含開機圖片和內核的設備樹信息。
-
system.img :Android 的 system 分區映像,ext4 文件系統格式。
-
trust.img :休眠喚醒相關的文件
-
rk3399_loader_v1.08.106.bin :Loader文件
-
uboot.img :uboot文件
請參照 如何升級固件 一文來燒寫分區映像文件。
如果使用的是 Windows 系統,將上述映像文件拷貝到 AndroidTool (Windows 下的固件升級工具)的 rockdev\Image 目錄中,之后參照升級文檔燒寫分區映像即可,這樣的好處是使用默認配置即可,不用修改文件的路徑。
update.img 方便固件的發布,供終端用戶升級系統使用。一般開發時使用分區映像比較方便。
定制 Android 固件
前言
定制 Android 固件,有兩種方法:
-
改源碼,然后編譯生成固件。
-
在現有固件的基礎上進行裁剪。
前一種方法,可以從各個層面去定制 Android,自由度大,但對編譯環境和技術要求比較高,參見《編譯 Android 固件》一文。現在介紹后一種方法,分為解包、定制和打包三個階段。主機操作系統為 Linux,采用的工具為開源軟件。
固件格式
統一固件 release_update.img,內含啟動加載器 loader.img 和真正的固件數據 update.img
release_update.img |- loader.img `- update.img
update.img 是個復合文件,內含多個文件,由 package-file 描述。一個典型的 package-file 為:
# NAME Relative path package-file package-file bootloader Image/MiniLoaderAll.bin parameter Image/parameter.txt trust Image/trust.img uboot Image/uboot.img misc Image/misc.img resource Image/resource.img kernel Image/kernel.img boot Image/boot.img recovery Image/recovery.img system Image/system.img backup RESERVED #update-script update-script #recover-script recover-script
-
package-file
-
update.img 的打包說明文件,update.img 里也含有一份 package-file。
-
Image/MiniLoaderAll.bin
-
啟動加載器,即 bootloader。
-
Image/parameter.txt
-
參數文件,可以設定內核啟動參數,里面有重要的分區信息。
-
Image/trust.img,trust.img 是U-Boot作為二級loader 的打包。
-
Image/misc.img
-
misc 分區的映像,用來控制 Android 是正常啟動,還是進入急救模式(Recovery Mode)。
-
Image/kernel.img
-
Android 內核。
-
Image/resource.img
-
資源映像,內有內核開機圖片和內核設備樹信息(Device Tree Blob)。
-
Image/boot.img
-
Android 內核的內存啟動盤(initrd),是內核啟動后最先加載的根文件系統,包含重要的初始化動作,一般不需要改動。
-
Image/recovery.img
-
Android 急救模式的映像,內含內核和急救模式的根文件系統。
-
Image/system.img
-
對應于 Android 的 /system 分區,是以下的定制對象。
解包,就是提取 release_update.img 里的 update.img, 然后解壓出內含 package-file 所聲明的多個文件。打包,則是個逆過程,將 package-file 將所列的多個文件合成 update.img,加進 loader.img,最終生成 release_update.img 。
工具準備
gitclonehttps://github.com/TeeFirefly/rk2918_tools.gitcdrk2918_toolsmakesudocpafptoolimg_unpackimg_makermkkrnlimg/usr/local/bin
解包
$ cd /path/to/your/firmware/dir $ img_unpack Firefly-RK3399_20161027.img img rom version: 6.0.1 build time: 2016-10-27 14:58:18 chip: 33333043 checking md5sum....OK
$ cd img $ afptool -unpack update.img update Check file...OK ------- UNPACK ------- package-file 0x00000800 0x00000280 Image/MiniLoaderAll.bin 0x00001000 0x0003E94E Image/parameter.txt 0x00040000 0x00000350 Image/trust.img 0x00040800 0x00400000 Image/uboot.img 0x00440800 0x00400000 Image/misc.img 0x00840800 0x0000C000 Image/resource.img 0x0084C800 0x0003FE00 Image/kernel.img 0x0088C800 0x00F5D00C Image/boot.img 0x017EA000 0x0014AD24 Image/recovery.img 0x01935000 0x013C0000 Image/system.img 0x02CF5000 0x2622A000 RESERVED 0x00000000 0x00000000 UnPack OK!
$ cd update/ $ tree . ├── Image │ ├── boot.img │ ├── kernel.img │ ├── MiniLoaderAll.bin │ ├── misc.img │ ├── parameter.txt │ ├── recovery.img │ ├── resource.img │ ├── system.img │ ├── trust.img │ └── uboot.img ├── package-file └── RESERVED 1 directory, 12 files
這樣,固件就解包成功了,下面就開始定制吧。
定制
定制 system.img
system.img 是個 ext4 文件系統格式的映像文件,可以直接掛載到系統進行修改:
sudomkdir-p/mnt/systemsudomount-oloopImage/system.img/mnt/systemcd/mnt/system# 修改里面的東西,注意剩余空間,不能添加太多的 APK# 修改完畢,要卸載cd/sudoumount/mnt/system
注意,該 system.img 的剩余空間基本為 0, 如果不是刪除文件,就需要對 system.img 進行擴容,并根據最后的文件大小,相應地調整 parameter 文件里的分區設置。以下是如何擴展空間的示例,在擴展前,先運行 mount 來查看系統掛載情況,確保 system.img 已經卸載:
# 增加 128M 的空間ddif=/dev/zerobs=1Mcount=128>>Image/system.img# 擴展文件系統信息e2fsck-fImage/system.imgresize2fsImage/system.img
打包
首先要檢查一下 system.img 的大小,對照 parameter 文件的分區情況(可參考文檔Parameter 文件格式,作必要的大小調整。例如,parameter.txt 文件里的 system 分區大小,可以找到 CMDLINE 一行,然后找到 system 字符串:
0x00200000@0x000B0000(system)
@ 前面就是分區的大小,單位是 512 字節,這樣該 system 分區的大小就是:
$ echo $(( 0x00200000 * 512 / 1024 / 1024))M 1024M
只要 system.img 的大小不超過 1024M,parameter 文件就不用更改。如果分區不用更改,可以直接用燒寫工具將新的 system.img 燒寫到開發板的 system 分區上做試驗。否則,需要制作新固件并燒寫后再行測試。以下是打包成統一固件 update.img 所需要的步驟:
# 當前的目錄仍然為 update/ ,內有 package-file, package-file 所列的文件均存在 # 將參數文件拷貝一份到 paramter, 因為 afptool 默認要用到 $ cp Image/parameter.txt parameter $ afptool -pack . ../update_new.img ------ PACKAGE ------ Add file: ./package-file Add file: ./Image/MiniLoaderAll.bin Add file: ./Image/parameter.txt Add file: ./Image/trust.img Add file: ./Image/uboot.img Add file: ./Image/misc.img Add file: ./Image/resource.img Add file: ./Image/kernel.img Add file: ./Image/boot.img Add file: ./Image/recovery.img Add file: ./Image/system.img Add file: ./RESERVED Add CRC... ------ OK ------ Pack OK!
$ img_maker -rk33 loader.img update_new.img release_update_new.img generate image... append md5sum... success!
release_update_new.img 即為最終生成的可燒寫的統一固件文件。
常見問題
固件的版本在哪設置
在 parameter 文件中找到下行并修改即可,注意版本號為數字,中間兩個點號不能省略。
聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。
舉報投訴
相關推薦
Android開發
ADB 使用
前言
adb,全稱 Android Debug Bridge,是 Android 的命令行調試工具,可以完成多種功能,如跟蹤系統日志,上傳下載文
發表于 12-17 16:30
?1741次閱讀
FAQs
HDMI無法4K顯示?
AIO-3399JD4默認出廠固件是支持HDMI顯示,HDMI分辨率最高4K。如果HDMI無法支持4K分辨率可以重新燒寫默認固件,或者重新編譯內核
發表于 12-17 16:40
?1470次閱讀
AIO-3399JD4 開發板上的 AD 接口有兩種
發表于 12-17 16:49
?3606次閱讀
AIO-3399JD4 有靈活的啟動方式。
發表于 12-17 17:01
?1830次閱讀
Core-3399-JD4核心板采用Rockchip高性能六核64位處理器RK3399,板載AI神經網絡處理器NPU SPR2801S,
發表于 12-18 14:11
?1765次閱讀
電子發燒友網站提供《Core 3399 JD4工具AndroidTool Release v2.38文件包.rar》資料免費下載
發表于 09-02 10:28
?4次下載
電子發燒友網站提供《Core 3399 JD4工具AndroidTool Release v2.54文件包.zip》資料免費下載
發表于 09-02 10:27
?3次下載
電子發燒友網站提供《Core 3399 JD4工具AndroidTool Release v2.63文件包.rar》資料免費下載
發表于 09-02 10:25
?0次下載
電子發燒友網站提供《Core 3399 JD4工具AndroidTool Release v2.65文件包.rar》資料免費下載
發表于 09-02 10:15
?5次下載
電子發燒友網站提供《Core 3399 JD4工具AndroidTool Release v2.71文件包.zip》資料免費下載
發表于 09-02 10:14
?2次下載
電子發燒友網站提供《Core 3399 JD4 V2工具upgrade tool for Android8.1.zip》資料免費下載
發表于 09-16 10:21
?0次下載
電子發燒友網站提供《Core 3399 JD4 V2工具AndroidTool Release v2.38.rar》資料免費下載
發表于 09-16 10:36
?10次下載
電子發燒友網站提供《Core 3399 JD4 V2工具AndroidTool Release v2.54.zip》資料免費下載
發表于 09-16 10:17
?3次下載
電子發燒友網站提供《Core 3399 JD4 V2工具AndroidTool Release v2.65.rar》資料免費下載
發表于 09-16 10:13
?3次下載
電子發燒友網站提供《Core 3399 JD4 V2工具AndroidTool Release v2.71.zip》資料免費下載
發表于 09-16 10:31
?4次下載
評論