androidpythonadbsl4a

Android Errno -2


I have a script that I want to run on my Android phone using the ADB and SL4A. This script worked fine on my Windows machine but when I've tried it from Linux I get the following error:

Traceback (most recent call last):
    File "test_device.py", line 12, in <module>
        droid = android.Android()
    File "device/android.py", line 34, in __init__
        self.conn = socket.create_connection(addr)
    File "/usr/lib/python2.7/socket.py", line 553, in create_connection
        for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known

The script I'm running is:

import sys
import random
import time
import redis

sys.path.append("lib")
sys.path.append("device")

import android
import instructions

droid = android.Android()
rdb = redis.Redis()
data = []

It fails when I try to setup the droid. Any help would be appreciated.


Solution

  • The issue was in how I set up the environment. Normally, on Windows I would do:

    set AP_PORT = 99999
    adb forward tcp:99999 tcp:99999
    

    and then I would be able to use the SL4A. However, because the system was Linux, not Windows, I had to do this:

    export AP_PORT=99999
    adb forward tcp:99999 tcp:99999
    

    The associated documentation was very helpful: https://books.google.com/books?id=uYEmWet7QtsC&pg=PA50&lpg=PA50&dq=linux+ap_port+variable&source=bl&ots=iYo_Hkn5Nm&sig=Rx2EtkTr1o5ygN9b4DJpF5RfENs&hl=en&sa=X&ved=0ahUKEwjCwcKA6f3NAhXnyoMKHUvKANsQ6AEIHDAA#v=onepage&q=linux%20ap_port%20variable&f=false