コマンドなしでぼくはAndroid開発できない話

 コマンドなしでぼくはAndroid開発できない話

コマンドなしでぼくはAndroid開発できない話
文字起こし
https://github.com/operando/DroidKaigi/blob/master/2017/no_command_no_life/README.md

DroidKaigi 2017 Day2
https://droidkaigi.github.io/2017/timetable.html#session-60

E77b6a5f919f7366d94f21eee9a014f5?s=128

operandoOS

March 10, 2017
Tweet

Transcript

  1. ίϚϯυͳ͠Ͱ
 ΅͘͸Android։ൃ
 Ͱ͖ͳ͍࿩ DroidKaigi 2017 Day2

  2. About Me Shinobu Okano @operandoOS Mercari, Inc. Souzoh, Inc.

  3. ࢿྉ಺ͷίϚϯυʹ packageName
 ͱॻ͔Ε͍ͯΔ෦෼͸
 ΞϓϦͷύοέʔδ໊ʹ
 ஔ͖׵͓͑ͯࢼ͍ͩ͘͠͞ʂ

  4. ࣭໰౳͋Ε͹ https://github.com/ operando/DroidKaigi ʹissueͱ্͔͍͛ͯͩ͘͞ʂ

  5. AndroidͰίϚϯυʁ

  6. AndroidͰίϚϯυ
 ࢖͑ΔΑ͏ʹͳΓͨʔ͍

  7. Ͱ͖·͢

  8. ࢖͑ΔΑ͏ʹͳΔͨΊʹ • Android SDK·ΘΓʹͪΐͬͱPathΛ
 ௨͚ͩ͢ • جຊɺͦΕ͚ͩʂ

  9. • sdk/tools • sdk/tools/bin • sdk/platform-tools • sdk/build-tools/<version> • sdk/platform-tools/systrace

    (͓·͚) Android SDKपΓͷ
 Ͳ͜ʹPath௨ͤ͹͍͍ͷ͔
  10. ίϚϯυ
 ࢖͍΍͘͢͢Δͧ

  11. adb-peco • ෳ਺ͷAndroid୺຤Λಉ࣌ܨ͍ͰΔ࣌ʹศར • alias adb='adb-peco' • https://github.com/tomorrowkey/adb-peco

  12. adb-peco • ෳ਺ͷAndroid୺຤Λಉ࣌ʹͭͳ͍Ͱ
 ࠔͬͯ·ͤΜ͔ʁͦΕadb-pecoͰબ୒Ͱ͖ΔΑʂ • http://techlife.cookpad.com/entry/ 2014/09/09/172449

  13. adb-peco • adb-pecoΛॻ͖௚͠·ͨ͠ by tomorrowkey • http://tomorrowkey.hatenablog.jp/entry/ 2016/07/31/adb-peco %E3%82%92%E6%9B%B8%E3%81%8D %E7%9B%B4%E3%81%97%E3%81%BE

    %E3%81%97%E3%81%9F
  14. աڈʹ࢖ͬͨίϚϯυΛ
 ΠϯλϥΫςΟϒʹௐ΂ͯ࢖͏ https://gist.github.com/operando/ 250da59cc97d89c33337fe5b129e09f5 peco select adb history

  15. adb

  16. adb Android Debug Bridge

  17. adb https://developer.android.com/ studio/command-line/adb.html

  18. ࣮ػͱΤϛϡϨʔλͰ͸
 ࣮ߦͰ͖ΔίϚϯυ͸ҧ͏ • ࣮ػʹ͸ͳ͍͚ͲΤϛϡϨʔλʹ͸
 ೖͬͯΔίϚϯυ͸ͦͦ͋͜͜Δ • ηΩϡϦςΟ্ͷཧ༝ͳͷ͔ͳʁ

  19. ωοτϫʔΫӽ͠ͰίϚϯυΛ ࣮ߦ͢Δ • adb shell ip addr show wlan0 |

    grep 'inet ' | cut -d' ' -f6|cut -d/ -f1 • ip෦෼͚ͩऔΓग़͢ • adb tcpip 5555 • adb connect ip:5555
  20. AndroidWiFiADB • Android StudioͷPlugin • https://github.com/pedrovgs/ AndroidWiFiADB • ·͋ͬͪ͜ͷํָ͕

  21. input

  22. input text จࣈೖྗΊͬͪΌ؆୯ʹͳΔ ࠷ڧίϚϯυ✨

  23. input text adb shell input text droidkaigi2017

  24. input keyevent Key eventΛൃߦͰ͖Δ

  25. input keyevent • adb shell input keyevent KEYCODE_POWER • ిݯΩʔԡ͢

    • adb shell input keyevent KEYCODE_SLEEP • εΫϦʔϯOFF
  26. adb shell inputͷίʔυ http://tools.oesf.biz/android-7.1.1_r1.0/ xref/frameworks/base/cmds/input/src/ com/android/commands/input/Input.java

  27. reboot • ࠶ىಈίϚϯυ • adb shell reboot

  28. am

  29. am start • ActivityΛελʔτͤ͞Δ΋ͷ • adb shell am start 


    -a android.intent.action.VIEW 
 -d https://google.com
  30. am broadcast BroadcastΛ࣮ߦ͢ΔίϚϯυ

  31. am broadcast • adb shell am broadcast -a com.android.systemui.BATTERY_LEVEL_TEST •

    ి஑࢒ྔ0ʙ100%ͷը૾ΛΞχϝʔγϣϯ
 Ͱ֬ೝͰ͖Δʂ • ࢖Θͳ͍ͩΖʔ
  32. am hang • ࠓ΍Βͳ͍Α͏ʹͶ͆ • hang͢ΔͷͰ • hangͯ͠Ͳ͏͠Α͏΋ͳ͘ͳͬͨΒ
 adb shell

    rebootͰ͢Αʂ
  33. am Source Code • http://tools.oesf.biz/android-7.1.1_r1.0/xref/ frameworks/base/cmds/am/src/com/ android/commands/am/Am.java • http://tools.oesf.biz/android-7.1.1_r1.0/xref/ frameworks/base/services/core/java/com/

    android/server/am/ ActivityManagerShellCommand.java
  34. pm

  35. pm PackageManager

  36. pm path • ࢦఆͨ͠ύοέʔδ໊ͷapkͷ৔ॴΛ
 ڭ͑ͯ͘ΕΔ • adb shell pm path

    packageName
  37. pm clear • ΞϓϦέʔγϣϯͷσʔλΛΫϦΞ͢Δ • adb shell pm clear packageName

  38. pm list • adb shell pm list packages • adb

    shell pm list packages -e • adb shell pm list packages -d • adb shell pm list packages -s • adb shell pm list packages -3
  39. pm source code • http://tools.oesf.biz/android-7.1.1_r1.0/xref/ frameworks/base/cmds/pm/src/com/ android/commands/pm/Pm.java • http://tools.oesf.biz/android-7.1.1_r1.0/xref/ frameworks/base/services/core/java/com/

    android/server/pm/ PackageManagerShellCommand.java
  40. dumpsys

  41. dumpsys • γεςϜαʔϏεͷঢ়ଶΛμϯϓ • ৭ʑؚΊͯಈ࡞νΣοΫ͍ͨ࣌͠ʹΊͬͪΌ ศར

  42. dumpsys • adb shell dumpsys -l • ͜ΕͰsystem serviceͷҰཡ͕ݟ͑Δ •

    ؾʹͳΔSystem ServiceΛ୳͢
  43. dumpsys activity • Activityͷ৘ใΛdump͢Δ • adb shell dumpsys activity

  44. dumpsys activity top • adb shell dumpsys activity top •

    ࠓදࣔͯ͠ΔActivityͷ৘ใ͕ݟ͑Δʂ • ϨΠΞ΢τͷߏ଄΋ݟΕΔʂ • FragmentManagerͷ৘ใ΋dump͞ΕΔ
  45. dumpsys activity top • ৽͍͠ϓϩδΣΫτ΍ݟ஌Β͵ίʔυΛಡΉ࣌ʹ໾ཱͭ • ͜ͷը໘ͬͯͲͷActivity? ͲͷFragment? 
 Έ͍ͨͳ͜ͱΛௐ΂Δͷʹ࠷ద

    • ਓ༷ͷΞϓϦͷViewͷߏ଄Λௐ΂Δͷʹ࠷ద
  46. dumpsys usagestats • adb shell dumpsys usagestats

  47. adb shell dumpsys dbinfo • adb shell dumpsys dbinfo •

    adb shell dumpsys dbinfo packageName • ࣮ߦͨ͠SQLͱ͔ͷཤྺ͕ݟ͑Δ • ςʔϒϧߏ଄ؙད໰୊
  48. log

  49. log • logcatʹ೚ҙͷlogΛଧͪࠐΉ • shell log DroidKaigi2017΍ͬͯͧ͘ʂ • ͱ͋Δૢ࡞ͷൣғͷlogcatΛݟ͍ͨ࣌ͳͲʹ
 ૢ࡞ͷ࢝ΊͱऴΘΓʹlogΛଧͭͱ͔ʹศར

  50. run-as

  51. run-as • ࣮ߦ͢ΔϓϩηεΛม͑Δ? • adb shell run-as packageName • /data/data/packageName഑؅ͷϑΝΠϧΛ

    ݟ͍ͨ࣌ʹศར
  52. run-as source code http://tools.oesf.biz/android-7.1.1_r1.0/ xref/system/core/run-as/

  53. bugreport

  54. bugreport adb bugreport

  55. bugreportz✨

  56. bugreportz • adb shell bugreportz • bugreportΛzipԽͨ͠΋ͷ͕࡞ΕΔ • bugreport͸΋ͷ͘͢͝Ͱ͔͍

  57. bugreportz • ҎԼʹॻ͖ग़͞ΕΔ • /data/user_de/0/com.android.shell/files/ bugreports • OK:/data/user_de/0/com.android.shell/files/ bugreports/bugreport- NPG05D-2017-03-10-07-41-37.zip

    • ੜ੒͞ΕͨΒadb pullͯ͠औΓग़͢
  58. bugreportz Source Code https://android.googlesource.com/platform/ frameworks/native/+/refs/heads/master/ cmds/bugreportz/

  59. adb uninstall • adb uninstall packageName • ΞϓϦΛΞϯΠϯετʔϧ͢Δ

  60. σʔλͱΩϟογϡΛ
 ࢒ͨ͠··ΞϯΠϯετʔϧ͢Δ • adb shell cmd package uninstall -k packageName

  61. ͦͷଞ͍ͬͺ͍͋Γ·͢Αʂ

  62. ίϚϯυԠ༻͍ͯͧ͘͠

  63. ಛఆͷΞϓϦͷSettingը໘Λ
 ίϚϯυͰҰൃͰग़͢!! • shell am start -a android.settings.APPLICATION_DETAILS_SE TTINGS -d

    package:packageName
  64. Πϯετʔϧ͞Ε͍ͯΔ
 ύοέʔδ໊Λιʔτͯ͠ग़͢ʂ • adb shell pm list packages | sed

    's@^package:@@g' | sort
  65. apkҾͬ͜ൈ͘͜ͱʹ
 શྗΛਚͨ͘͠ʂ • adb shell dumpsys activity activities | 


    grep apkΛվ଄ͯ͠pecoͱ߹Θͤͯ
 બ୒ͯ͠pull͢Δ΍ͭ࡞Δ
  66. apkҾͬ͜ൈ͘͜ͱʹ
 શྗΛਚͨ͘͠ʂ • adb shell dumpsys activity activities | grep

    apk | sed -e 's/ *baseDir=//g' | peco | xargs adb pull
  67. apkҾͬ͜ൈ͘͜ͱʹ
 શྗΛਚͨ͘͠ʂ • dumpsys activity activitiesͱpecoͰΰχϣΰ χϣͯ͠୺຤͔ΒapkΛ؆୯ʹҾͬ͜ൈ͘ • http://qiita.com/operandoOS/items/ 6fa77037560e52d11352

  68. dryrun • gem install dryrun • dryrun ϦϙδτϦͷURL

  69. dryrun https://github.com/ cesarferreira/dryrun

  70. ίϚϯυपΓͷsource code • http://tools.oesf.biz/android-7.0.0_r1.0/xref/ frameworks/base/cmds/ • http://tools.oesf.biz/android-7.0.0_r1.0/xref/ system/core/

  71. ίϚϯυͷ࣮ମΛௐ΂Δํ๏ • logcatΛݟΔ • ίϚϯυͷग़ྗ݁Ռ͔Βݻఆ஋ͬΆ͍΋ͷΛ ݟ͚ͭͯɺͦΕΛग़ྗͯ͠ΔॲཧΛ୳͢ • ͔ͦ͜ΒͲΜͲΜ۷ΓԼ͍͛ͯ͘ • ιʔείʔυ͔Βؤுͬͯ୳͢ʂ

  72. ίϚϯυϥΠϯπʔϧΛ
 ৭ΜͳݴޠͰ࡞ΔͨΊͷૉࡐ • DeviceAPI-Android • https://github.com/bbc/device_api-android • ruby • adbkit

    • https://github.com/openstf/adbkit • node.js
  73. Android Command Note https://github.com/operando/ Android-Command-Note ঺հͨ͠ίϚϯυͱ͔·ͱΊͯ·͢ʂ

  74. Thanks!!