Android_ADB_自動操作_エラー対応

Androidの自動操作を試行中。

スマホスクリーンショットを撮らせたく実行したところ次々エラー。

こんなのは日常茶飯事なので粛々とググってトライアルアンドエラー。

 

# テスト実行
”プロジェクト”\android-auto-play-opencv-master>python ./sample.py

## エラーが発生
ModuleNotFoundError: No module named 'android_auto_play_opencv'

# エラー解消
”プロジェクト”\android-auto-play-opencv-master>pip install android-auto-play-opencv

# エラー発生_ADBが見つからない_パスに置いてくる
”プロジェクト”\android-auto-play-opencv-master>python ./sample.py
adb.exe が見つかりません。(..\platform-tools\adb.exe)

# 実行時エラーが発生する
”プロジェクト”\android-auto-play-opencv-master>python ./sample.py
* daemon not running; starting now at tcp:5037
* daemon started successfully
8a776e95
画面キャプチャ
error: device unauthorized.
This adb server's $ADB_VENDOR_KEYS is not set
Try 'adb kill-server' if that seems wrong.
Otherwise check for a confirmation dialog on your device.
Traceback (most recent call last):
  File "”プロジェクト”\android-auto-play-opencv-master\sample.py", line 11, in <module>
    main()
  File "”プロジェクト”\android-auto-play-opencv-master\sample.py", line 9, in main
    aapo.screencap()
  File "C:\Users\"ユーザ名"\AppData\Local\Programs\Python\Python39\lib\site-packages\android_auto_play_opencv\AapoManager.py", line 39, in screencap
    self.adbl.screencap()
  File "C:\Users\"ユーザ名"\AppData\Local\Programs\Python\Python39\lib\site-packages\android_auto_play_opencv\Adblib.py", line 56, in screencap
    self.screenImg = subprocess.check_output([self.adbpath + 'adb', '-s', self.device, 'exec-out', 'screencap', '-p'])
  File "C:\Users\"ユーザ名"\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 420, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "C:\Users\"ユーザ名"\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 524, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['..\\platform-tools\\adb', '-s', '8a776e95', 'exec-out', 'screencap', '-p']' returned non-zero exit status 4294967295.

 

■下記のエラーはググったところ原因がよくわからないようでいろいろと説が交錯していた。

error: device unauthorized.
This adb server's $ADB_VENDOR_KEYS is not set
Try 'adb kill-server' if that seems wrong.

解決を試す

adbでdevice unauthorizedになって実機デバッグできない場合 - Crieit

 

windowsの場合は次でよいようだ。

1. 下の画像で選択しているファイルを削除する

2. ADBサーバを停止、起動する

次のコマンドを実行する

# adbの停止
adb kill-server
# adbを起動
adb start-server

 

You'll have to bear with me because I'm not familiar with Mac file structure.

I would start from scratch. Do all these before trying to run adb again.
On your computer:
-Delete adbkey & adbkey.pub from the .android folder (I'm not sure where that is on a Mac, Home\.android?).
-I'm not sure if Macs have a device manager, but check that your phone is correctly recognized and the drivers are installed properly.
On your phone:
-Ensure you've got developer features unlocked
-Double check that you've got usb debugging enabled.
-Tap the "Revoke USB Debugging Authorizations" button below USB debugging in developer options.
-When you're plugged in be sure to set your connection to Internet >>Ethernet (you'll see the debugging icon in the notification bar if it's connected right).

I know a lot of that is basic and redundant but if it's all done correctly then it should work. If it doesn't work it gives us a good starting point to troubleshoot.

If you want to test it open terminal, change directory to the bts folder in the ioroot folder and start adb (adb start-server), with everything done right you should get the rsa window on your phone right now. Type "adb devices" and see what comes back.

[SOLVED] Unable to access with ADB/No RSA Fingerprint Key Window | XDA Forums

 

3. エラー発生

"プロジェクトパス"\android-auto-play-opencv-master>adb
'adb' は、内部コマンドまたは外部コマンド、
操作可能なプログラムまたはバッチ ファイルとして認識されていません。

[Windows10] adbコマンドを使用できるようにする方法。内部コマンドまたは外部コマンド、操作可能…と言われ困った話 | こんぶろ

 

4. ADBを使えるようにする

[Windows10] adbコマンドを使用できるようにする方法。内部コマンドまたは外部コマンド、操作可能…と言われ困った話 | こんぶろ

Cドライブにplatform-toolsフォルダを置いて、システム環境変数にパスを追加する。

 

 → これで実行に関するエラーは解消した。

プログラミング記事は、とにかく前提の省略が多いな。