Python SL4A Development

Good. I feel like a frustrated idiot. I want to say that in advance.

I am trying to configure Python / Android so that I can develop Python applications for Android. I have both SL4A and the Python interpreter installed on my Android device, and you can write an application on the phone that works.

The problem is how I can continue development on my PC and interact with my Android device. I unpacked the add-on package and put it in $ PYTHONPATH / site-packages /. I enabled 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 go to Python through the CLI and click

 import android 

I get the following output

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

Any help or primer will be greatly appreciated.

I know that I have to do something wrong, because I see that others are being tuned, what appears is relative ease.

Thanks in advance.

+8
python android sl4a
source share
1 answer

1. Start the server

On device

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

 SL4A -> Interpreters -> Menu -> Start Server 

Private is preferred.

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

From PC

Alternatively, you can start the server from a PC using adb using a specific port (r5 required to install 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 the connection

Now you need to forward your port using adb (assuming the search value is 51943):

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


3. Start the script

After that, you can run the script locally:

 $ python my_script.py 


Wifi connection

If you want to go over Wi-Fi, you do not need to forward the port using adb . Instead, you should use a public server and optionally specify your host:

 $ export AP_HOST=192.168.0.100 


References

For more information, see the Wiki page that addresses this section .

+8
source share

All Articles