Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python SL4A Development

Ok - I'm feeling like a frustrated idiot. I want to state that upfront.

I'm trying to get a Python/Android setup going so I can develop Python applications for Android. I've got both SL4A and the Python interpreter installed on my Android device and can write an application on the phone that runs.

The issue is how can I continue with development on my PC and interact with my Android device. I've unzipped the extras package and put it in $PYTHONPATH/site-packages/. I've integrated Ecplise with PyDev and Android packages and set the AP_PORT and AP_HOST environment variables.

When I run the following code:

import android
droid = android.Android()
droid.makeToast("Hello")

I get errors in Eclipse that include "com.googlecode.android_scripting.rpc.RpcError: Unknown RPC." to bad magic numbers.

When I drop into Python via CLI and type

import android

I get the following output

com.googlecode.android_scripting.rpc.RpcError: Unknown RPC.

Any help or beginners tutorial would be greatly appreciate.

I know I must be doing something wrong because I see others getting set up with, what appears, relative ease.

Thanks in advance.

like image 269
Paul Avatar asked May 31 '12 19:05

Paul


1 Answers

1. Start Server

On Device

First, connect your device with USB. Then for remote debugging, you need to start a server on your device:

SL4A -> Interpreters -> Menu -> Start Server

The private one is preferable.

Then you can look up the port for the server in the Android notification area (with SL4A r5 you can specify a fixed port in settings).

From PC

Alternatively, you can start a server from the PC with adb using a specific port (r5 required for setting the port):

$ adb shell am start -a com.googlecode.android_scripting.action.LAUNCH_SERVER \
  -n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher \
  --ei com.googlecode.android_scripting.extra.USE_SERVICE_PORT 51943


2. Specify connection

Now you need to forward your port with adb (assuming the looked up value is 51943):

$ adb forward tcp:51943 tcp:51943
$ export AP_PORT=51943


3. Start script

Afterwards you should be able to run your script locally:

$ python my_script.py


Wifi connection

If you want to go via wifi, you don't need to forward your port with adb. Instead you have to use a public server and specify your host additionally:

$ export AP_HOST=192.168.0.100 


References

For more help see the Wiki page addressing this topic.

like image 160
schlamar Avatar answered Oct 13 '22 20:10

schlamar