I wrote only this 3 lines in python using SL4A:
import android
droid = android.Android()
droid.makeToast(u"ascc4r")
When this code runs, I get the following error:
pydev debugger: starting
Traceback (most recent call last):
File "C:\Users\Tibi\Desktop\adt-bundle-windows-x86_64-20130917\eclipse\plugins \org.python.pydev_2.8.2.2013090511\pysrc\pydevd.py", line 1446, in <module>
debugger.run(setup['file'], None, None)
File "C:\Users\Tibi\Desktop\adt-bundle-windows-x86_64-20130917\eclipse\plugins org.python.pydev_2.8.2.2013090511\pysrc\pydevd.py", line 1092, in run
pydev_imports.execfile(file, globals, locals) #execute the script
File "C:\Users\Tibi\workspace\26\src\26module.py", line 7, in <module>
droid = android.Android()
File "C:\Python26\lib\android.py", line 34, in __init__
self.conn = socket.create_connection(addr)
File "C:\Python26\lib\socket.py", line 547, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11001] getaddrinfo failed
Environment setup:
- Python 2.6.6
- set ap_port=9999
- adb forward tcp:9999 tcp:xxxx (xxxx where I started the server on the phone)
My android.py is in the Python/Lib folder.
Update:
I tried this 3 instruction in CMD and it's work, making a Toast. So I think the fault is in the ADT bundle, or Eclipse Python plugin.
What is this Errno 11001?
What is this Errno 11001?
I don't know about that error, but I suggest to use the correct syntax which is
import android
droid = android.Android()
droid.makeToast('my text to print should be inside the quotes')
see also the API Overview
Related
I've found a nice plugin for lldb that allows watching memory regions as images: https://github.com/carlodalmutto/ImageWatchLLDB
As I can see, this plugin was developed for Xcode and not for Android.
However, it is written in Python and therefore should be cross-platform.
I've found a directory c:\Users\username\.lldb\ on my hard drive. Its size is about 1 Gb.
I've created following files: c:\Users\username\.lldbinit, c:\Users\username\lldbinit, c:\Users\username\.lldb\lldbinit, c:\Users\username\.lldb\.lldbinit, c:\Users\username\.lldb\init
All of them have the similar content:
script print "script print Hi from lldb"
echo "echo Hi"
Unfortunately I don't see any output.
I can open LLDB console and issue these commands:
(lldb) script print "script print Hi from lldb"
script print Hi from lldb
(lldb) echo "Hi"
error: 'echo' is not a valid command.
error: Unrecognized command 'echo'.
This means that LLDB understands script print command.
Installation directory for Android Studio contains the subdirectory bin\lldb containing python scripts with pretty printers (file jstring_reader.py, gdb\printing.py, etc)
So, it seems possible to extend LLDB from recent NDK.
The question is: how can I add my custom plugins?
UPDATE. After some hacking I've found that LLDB commands, starting with the "script" string, are actually python commands:
(lldb) script print sys.executable
C:\Android\sdk\lldb\3.1\bin\LLDBFrontend.exe
(lldb) script print sys.version
2.7.10 (default, Feb 24 2016, 14:25:13) [MSC v.1900 64 bit (AMD64)]
(lldb) script print sys.path
['C:/Android/sdk/lldb/3.1/bin', 'C:/Android/Android Studio/bin/lldb/shared/jobject_printers', 'C:/Android/sdk/lldb/3.1/lib/site-packages', 'C:\\Android\\sdk\\lldb\\3.1\\bin\\python27.zip', 'C:\\Android\\sdk\\lldb\\3.1\\DLLs', 'C:\\Android\\sdk\\lldb\\3.1\\lib', 'C:\\Android\\sdk\\lldb\\3.1\\lib\\plat-win', 'C:\\Android\\sdk\\lldb\\3.1\\lib\\lib-tk', 'C:\\Android\\sdk\\lldb\\3.1\\bin', 'C:\\Android\\sdk\\lldb\\3.1', 'C:\\Android\\sdk\\lldb\\3.1\\lib\\site-packages', '.', 'C:\\Android\\Android Studio\\bin\\lldb\\shared\\stl_printers', 'C:\\Android\\sdk\\ndk-bundle\\prebuilt\\windows-x86_64\\share\\pretty-printers\\libstdcxx\\gcc-4.9']
(lldb) script import pip
Traceback (most recent call last):
File "<input>", line 1, in <module>
ImportError: No module named pip
The first idea of installing missing modules with pip has failed.
I update my question: Are there any official guide on writing python plugins for lldb from NDK?
UPDATE 2. Have tried creating Anaconda virtual environment with the same python version and adding it to sys.path. Also failed.
(lldb) script os.environ['PATH']+= r'C:\Anaconda\envs\ndkpy;'
(lldb) script os.environ['PATH']+= r'C:\Anaconda\envs\ndkpy\Library\bin;'
(lldb) script import numpy as np
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Anaconda\envs\ndkpy\Lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Anaconda\envs\ndkpy\Lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Anaconda\envs\ndkpy\Lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Anaconda\envs\ndkpy\Lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Anaconda\envs\ndkpy\Lib\site-packages\numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: A dynamic link library (DLL) initialization routine failed.
UPDATE 3. Have found C:\Android\Sdk\lldb\3.1\lib\lib-tk. Tried importing Tkinter, but still no luck:
(lldb) script import Tkinter
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Android\sdk\lldb\3.1\lib\lib-tk\Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
Scheme1:
Just run command script import C:\\lldb_plugins\\chisel\\fbchisellldb.py or command script import C:\\lldb_plugins\\LLDB\\lldb_commands\\dslldb.py on your lldb console in Android Studio.
Scheme2:
Create file C:\Users\username\.lldbinit and put the following content to this file:
command script import C:\\lldb_plugins\\chisel\\fbchisellldb.py
command script import C:\\lldb_plugins\\LLDB\\lldb_commands\\dslldb.py
And then, run reload_lldbinit on your lldb console in Android Studio.
New to android and wanted to do a little debugging with the systrace tool however I am unable to run the tool on the emulator (tried running the python script with python 2.0.1, 2.7.x, 3.x) as well as using ADT.
However they all produce different errors:
Developers | Systrace claims that it requires 2.x so using Python 2.x and executing python command systrace.py --help, I get:
C:\Development\Android\sdk\platform-tools\systrace>python systrace.py --help
Traceback (most recent call last):
File "systrace.py", line 286, in <module>
main()
File "systrace.py", line 60, in main
device_sdk_version = get_device_sdk_version()
File "systrace.py", line 44, in get_device_sdk_version
stderr=subprocess.PIPE)
File "C:\Reuben\Softwares\Python 2.7.6\Lib\subprocess.py", line 709, in __init__
errread, errwrite)
File "C:\Reuben\Softwares\Python 2.7.6\Lib\subprocess.py", line 957, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
C:\Development\Android\sdk\platform-tools\systrace>python systrace.py --help
File "systrace.py", line 135
css = '\n'.join(linked_css_tag % (os.path.join(src_dir, f)) for f in css_files)
^
SyntaxError: invalid syntax
But with Admin permission:
C:\Development\Android\sdk\platform-tools\systrace>systrace.py --help
File "C:\Development\Android\sdk\platform-tools\systrace\systrace.py", line 135
css = '\n'.join(linked_css_tag % (os.path.join(src_dir, f)) for f in css_files)
^
SyntaxError: invalid syntax
With ADT settings
Error dialog
Other Relevant Information:
Enabled: Android Debugging, Profile GPU rendering
Enable OpenGL traces: Systrace (Graphics)
Enable traces: Graphics,Input
Tried Other solution but got "mount: Device or resource busy"
I am trying to learn creating the android application using python. I am going through the tutorials.
when I am running the command :
adb forward tcp:9999 tcp:4321
set AP_PORT=9999
and then running the code,
import android
droid = android.Android()
droid.makeToast("Hello from my computer!")
It gives me error as :
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
droid.makeToast("Hello from my computer!")
File "C:\Python27\lib\site-packages\android.py", line 58, in rpc_call
return self._rpc(name, *args)
File "C:\Python27\lib\site-packages\android.py", line 47, in _rpc
response = self.client.readline()
File "C:\Python27\lib\socket.py", line 447, in readline
data = self._sock.recv(self._rbufsize)
error: [Errno 10053] An established connection was aborted by the software in your host machine
how can I solve the problem?
Trying to run forge run android command and getting this error even though file is present (Ubuntu 12.04). Even if I do not specify the sdk path and allow forge to download it on its own, I am still getting the same error.
2012-07-04 15:08:36,414 [ DEBUG] Exception running detached command:
/home/rockyj/Apps/android-sdk-linux/platform-tools/adb start-server:
[Errno 2] No such file or directory while running
run_android(('/home/rockyj/Workspace/Projects/greeter/development',
u'/home/rockyj/Apps/android-sdk-linux', None, True, None), {})
2012-07-04 15:08:36,417 [ ERROR] Something went wrong that we didn't expect:
2012-07-04 15:08:36,417 [ ERROR] Exception running detached command:
/home/rockyj/Apps/android-sdk-linux/platform-tools/adb start-server:
[Errno 2] No such file or directory
2012-07-04 15:08:36,417 [ DEBUG] Traceback (most recent call last):
File "/home/rockyj/Apps/forge-tools/forge/async.py", line 87, in run
result = self._target(*self._args, **self._kwargs)
File "/home/rockyj/Apps/forge-tools/forge/main.py", line 388, in run
build_to_run=build_to_run,
File "/home/rockyj/Workspace/Projects/greeter/.template/generate_dynamic/customer_goals.py",
line 120, in run_app
build_to_run.run()
File "/home/rockyj/Workspace/Projects/greeter/.template/generate_dynamic/build.py",
line 338, in run
self._run_task(func_name, args, kw)
File "/home/rockyj/Workspace/Projects/greeter/.template/generate_dynamic/build.py",
line 293, in _run_task
self.tasks[func_name](self, *args, **kw)
File "/home/rockyj/Workspace/Projects/greeter/.template/generate_dynamic/android_tasks.py",
line 588, in run_android
run_detached([path_info.adb, 'start-server'], wait=True)
File "/home/rockyj/Workspace/Projects/greeter/.template/generate_dynamic/android_tasks.py",
line 377, in run_detached
raise ShellError(message="Exception running detached command: %s"
% full_command, output=str(output))
ShellError: Exception running detached command:
/home/rockyj/Apps/android-sdk-linux/platform-tools/adb start-server:
[Errno 2] No such file or directory
Please help.
Thanks.
Per the comments, this issue was fixed by installing ia32 libs on Ubuntu.
Without emulator, is there a way to execute the scripts. as any other normal py code?
Tried to port, but /me gets :
droid = android.Android()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/android.py", line 34, in __init__
self.conn = socket.create_connection(addr)
File "/usr/lib/python2.6/socket.py", line 547, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known
Yes, you can use a remote connection to your phone and execute the script local, see RemoteControl in the SL4A Wiki.