So I am looking into using Kivy for Android development. Defeating the jedi etc.
But I have hit a roadblock! I installed the Kivy VM image in VirtualBox, but when I try to run the test script:
# /usr/bin/kivy
__version__ = 1.0
from kivy.app import App
from kivy.uix.button import Button
class Hello(App):
def build(self):
btn = Button(text='Hello World')
return btn
Hello().run()
Using:
python main.py
I get:
Traceback (most recent call last):
File "main.py", line 3, in <module>
from kivy.app import App
ImportError: No module named kivy.app
do you have a file named kivy.py in the same folder as main.py?
try
#!/usr/bin/kivy
import kivy
print kivy.__file__
I tried just plain installing kivy as they say to on their website, and it worked.
sudo add-apt-repository ppa:kivy-team/kivy
apt-get install python-kivy
Related
In order to create the .apk file that will be able to be run on an android phone, I decided to use the kivy virtual machine to run buildozer on Linux. I was able to setup the buildozer.spec and the main.py, but when I ran buildozer android debug deploy run, it gave me this error message
Error Message
This is the buildozer.spec file
Buildozer.spec
And this is the main.py
import kivy
from kivy.app import App
import cv2
from kivy.uil.label import Label
class SimpleKivy(object):
def build(self):
return Label(text="Hello World!")
if __name__ == "__main__":
SimpleKivy().run()
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.
I want to create an application that takes photos from camera and show thumbnails of them on android. The related part of my code is:
from plyer import camera
from PIL import Image
.
.
.
def take_photo_from_camera(self, x):
filename = str(random.randint(0, 100000000000)) # create random filenames
self.camera.take_picture("/storage/sdcard0/MyApp/%s.jpg"%(filename), self.on_success_shot)
def on_success_shot(self, path):
#Create a thumbnail of taken photo here using PIL
I can use android camera without any problem.
I've added the PIL/pillow to the requirements of the kivy buildozer.spec file
requirements = kivy, openssl, futures, requests, plyer, pyjnius, pillow
When i want to create an apk with this configuration, the apk package succesfully builds but if i install apk and run on my android phone, i'm getting this error in logcat:
I/python (20188): Traceback (most recent call last):
I/python (20188): File "/home/mnrl/teknik/.buildozer/android/app/main.py", line 32, in <module>
I/python (20188): File "/home/mnrl/teknik/.buildozer/android/app/_applibs/PIL/Image.py", line 67, in <module>
I/python (20188): ImportError: dlopen failed: "/data/data/org.tokerteknik.tokerteknik/files/_applibs/PIL/_imaging.so" is 64-bit instead of 32-bit
I/python (20188): Python for android ended.
I think the problem related to architecture. I'm using ubuntu 16.04 64 bit and kivy buildozer installs 64 bit libraries with pip while installing requirements.
A similar problem here too: https://github.com/kivy/kivy/issues/4095 but there's not any solution.
Briefly how can i import PIL on android with kivy buildozer or how to install 32 bit libraries of PIL on 64 bit system?
Use pygame instead of PIL for basic image manipulation processes.
Add pygame to the buildozer requirements list, it works without any problem.
import pygame
picture = pygame.image.load(filepath)
picture = pygame.transform.scale(picture, (100, 100))
pygame.image.save(picture, "scaled_image.png")
I wrote a simple kivy app that replicates buttons
import kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
class ButtonApp(App):
def add_button(self, none):
button = Button(text='Press Me too!')
button.bind(on_press=self.add_button)
self.b.add_widget(button)
def build(self):
self.b = BoxLayout()
button = Button(text="Press me!")
button.bind(on_press=self.add_button)
self.b.add_widget(button)
return self.b
if __name__ == "__main__":
ButtonApp().run()
but when I run buildozer android debug, I get the following error
# Android SDK found at /Users/mmalkin/.buildozer/android/platform/android-sdk-21
# Android NDK found at /Users/mmalkin/.buildozer/android/platform/android-ndk-r9c
# Command failed: /Users/mmalkin/.buildozer/android/platform/android-sdk-21/tools/android list sdk -u -e
#
# Buildozer failed to execute the last command
# If the error is not obvious, please raise the log_level to 2
# and retry the latest command.
# In case of a bug report, please add a full log with log_level = 2
I've tried changing the directory to Macintosh HD, updating Java, and many other solutions suggested on this site. What am I doing wrong?
You have probably not installed build-tools. Check this on-going bug report - https://github.com/kivy/buildozer/issues/146
Summary of solution, run the Android SDK Manager and install that way.
Hi I am new to python development. I am trying to execute the code given at http://dtmilano.blogspot.in/2012/02/monkeyrunner-interacting-with-views.html but when ever i am trying to execute the code i get following error:
Traceback (most recent call last):
File "C:\Users\gur31265\workspace\MonkeyRunnerForSmartRecorder\com\test\Runner.py", line 23, in <module>
from com.dtmilano.android.viewclient import ViewClient
ImportError: No module named dtmilano
I am using eclipse with PyDev and Jython 2.5.3. I had also configured Python 32 on eclipse running on Windows 7 machine. Other Python scripts are running fine but i don't know why code given on dtmilano's blog is causing this error. I had also installed AndroidViewClient and set the ANDROID_VIEW_CLIENT_HOME in system path. Please help.
This took me a bit to work out. Make sure that you append the AndroidViewClient source directory to your path before you import MonkeyRunner.
The following will fail with ImportError: No module named dtmilano:
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
sys.path.append('/path/to/android_view_client_home/src')
from com.dtmilano.android.viewclient import ViewClient
However, it will work if you just switch the order:
sys.path.append('/path/to/android_view_client_home/src')
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
from com.dtmilano.android.viewclient import ViewClient
It seems that once it imports the com package for MonkeyRunner, it will only look in that package for dtmilano. However, if both com packages are in the path before you import anything, it will know to look in both locations.
You can find a detailed explanation about how to use PYTHONPATH and ANDROID_VIEW_CLIENT_HOME environment variables from Eclipse and PyDev and also from command line at http://dtmilano.blogspot.ca/2012/09/monkeyrunner-importing-from-pythonpath.html.
Briefly:
#!/usr/bin/env monkeyrunner
import re
import sys
import os
import java
# This must be imported before MonkeyRunner and MonkeyDevice,
# otherwise the import fails.
# PyDev sets PYTHONPATH, use it
try:
for p in os.environ['PYTHONPATH'].split(':'):
if not p in sys.path:
sys.path.append(p)
except:
pass
try:
sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass
from com.dtmilano.android.viewclient import ViewClient, View
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
Use monkeyrunner located in android SDK to run your code. For example:
to compile a file named help.py use following command:
c:>monkeyrunner help.py
same command will work on linux environment also.