I'm trying to import file with buildozer but I can't know how
what I'm doing : in main.py there is
import xmpp
And it's should import this from file named : xmpp
it's working 100% but when I'm trying to make it an android app it isn't working
What should I do?
Related
I am following a tutorial on how to switch pages in flutter so I know that my code isn't necessarily wrong, however I keep getting an error with the way I am importing my classes. I have 2 pages and i'm not sure how to properly import them
The way the tutorial says to import it is: " import 'package:overflown/page2.dart'; "
but I get the error: Target of URI doesn't exist: 'package:overflown/page2.dart'. When I try to do it this way.
Any help would be great.
In package:overflown/page2.dart',
overflown is the name of your project you find in the pubspec.yaml
page2.dart is the path to the page named page2.dart.
have to modify the import path to that to your page path.
Example
You have a project with name testproject and a folder structure
lib
main.dart
page1.dart
The import should be
'package:testproject/page1.dart'
I am getting this error while trying to use jnius's autoclass to get the android webview inside Kivy app. What could be the fix?
Thanks
My code looks like this:
import kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.utils import platform
from kivy.uix.widget import Widget
from kivy.clock import Clock
from jnius import autoclass
#from android.runnable import run_on_ui_thread
WebView = autoclass('android.webkit.WebView')
WebViewClient = autoclass('android.webkit.WebViewClient')
activity = autoclass('org.renpy.android.PythonActivity').mActivity
class Wv(Widget):
def __init__(self, **kwargs):
super(Wv, self).__init__(**kwargs)
# Clock.schedule_once(self.create_webview, 0) `
# #run_on_ui_thread
# def create_webview(self, *args):
# webview = WebView(activity)
# webview.getSettings().setJavaScriptEnabled(True)
# wvc = WebViewClient();
# webview.setWebViewClient(wvc);
# activity.setContentView(webview)
# webview.loadUrl('http://www.google.com')
class ServiceApp(App):
def build(self):
return Wv()
if __name__ == '__main__':
ServiceApp().run
First, you should check if you are running the code in an Android enviroment as the android.webkit.WebView runs only under Android and not on a PC under Windows or Linux.
Recommended is an Android device and run the app using Buildozer command buildozer android debug deploy run with debugging options.
In case, you want to run it on a PC then you can install the Android VM from Kivy and follow the following steps on https://kivy.org/docs/guide/packaging-android-vm.html:
Download the Kivy / Buildozer VM, in the Virtual Machine section. The
download is 1.2GB. Extract the file and remember the location of the
extracted directory.
Download the version of VirtualBox for your machine from the VirtualBox download area and install it.
Start VirtualBox, click on “File”, “Import Appliance”.
Select the extracted directory, file should be named “Buildozer VM.ovf”
Start the Virtual machine and click on the “Buildozer” icon.
and let in run in kivy.org/docs/guide/packaging-android-vm.html
If you still face the problem of a jnius.JavaException: Class not found 'android/webkit/WebView' exception, then you have to add that jar file to the classpath:
import os
os.environ['CLASSPATH'] = 'absolute/path/file.jar'
In case of the Class not found 'android/webkit/WebView' exception you could either locate the jar on your device or download it and add the path where you store it to the classpath.
Use Pydroid3 to test your apps without compiling them
I was developing a mobile app that can send mqtt messages to AWS Iot. It needs paho-mqtt library. It can be included in buildozer.spec requirements. My problem is in the SSL part, because I need to import SSL in the code which seems to have a problem with the python version running in python-for-android, which is 2.7.2.
The code is below, which works fine on the PC, but on th phone it is not working.
from kivy.lang import Builder
from kivy.app import App
from kivy.uix.label import Label
import paho.mqtt.publish as mqtt
import paho.mqtt.client as mqttclient
#
class MqttTest(App):
def build(self):
topic = "topic1"
my_ca_cert = "RootCA.pem"
my_pri_cert = "my.cert.pem"
my_key_cert = "my.private.key"
try:
import ssl
mqttc = mqttclient.Client("Python_Ex_Pub")
mqttc.tls_set(my_ca_cert,
certfile=my_pri_cert,
keyfile=my_key_cert,
cert_reqs=ssl.CERT_REQUIRED,
tls_version=ssl.PROTOCOL_TLSv1_2,
ciphers=None)
mqttc.connect("myaddress", 8883)
mqttc.publish(topic, "This is a test pub from Python.")
return Label(text="Hi it works!")
except Exception as e:
import traceback
a=traceback.format_exc()
try:
f1=open("/storage/emulated/0/Download/err.txt","w")
f1.write(str(a))
f1.close()
except:
pass
return Label(text=str (a))
if __name__ == '__main__':
MqttTest().run()
without adding anything related to SSL in buildozer.spec requirements, I get the following error:
no module named _ssl
If I added openssl as one of the requirements, then I get the following error:
'module' object has no attribute 'PROTOCOL_TLSv1_2'
As noted PROTOCOL_TLSv1_2 was added in later Python 2 version than p4a provides.
You can try to build apk with Python 3:
Change your buildozer's requirements line replacing python2 with python3crystax
Download and unpack crystax ndk here
Change your buildozer's android.ndk_path to point unpacked crystax ndk directory
Run buildozer android debug
If you're lucky enough you'll be able to build apk with Python 3 without any other actions.
I encountered the similar issue. I am trying to import pydrive without doing anything at first. Below is from logcat.
I tried 3 os environment, osx, ubuntu, bulldozer vm. All give me the same error.
I/python (13323): File "/Users/macuser/test/.buildozer/android/platform/build/dists/myapp/private/lib/python2.7/site-packages/httplib2/init.py", line 960, in
I/python (13323): AttributeError: 'module' object has no attribute 'HTTPSConnection'
In httplib.py, i found below code.
try:
import ssl
except ImportError:
pass
else:
class HTTPSConnection(HTTPConnection):
"This class allows communication via SSL."
So I suspect ssl not import successfully. Then, check ssl.py and found PROTOCOL_SSLv3 cannot import successfully.
from _ssl import PROTOCOL_SSLv3, PROTOCOL_SSLv23, PROTOCOL_TLSv1
Until here i am not able to proceed further. I am using python3crystax and it still not work as claim in this post.
Since buildozer will download all library separately, i suspect python automatically downloaded by bulldozer is a python version that doesn't include ssl3 support.
I have developed a simple client server android application. I have created the application to work on all versions of android. So I have given this code on androidmanifest.xml file.
<uses-sdk android:minSdkVersion="10"
android:targetSdkVersion="16"/>
For establishing connectivity I have used this jar file (ksoap2-android-assembly-2.5.8-jar-with-dependencies) in my application. The problem now is that the application works fine and error free on android versions upto gingerbread. But when I try to run it on versions above that, the app does not work, not even tries to send data to the server, whereas on gingerbread and below, it client and server communication works fine. What is the possible problem for this error. Is it because of the jar file which I'm using. For establishing the client server communication I have imported the following in my project.
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
Use of AsyncTask in my application solved it. Or else you can use the following code in your mainactivity below setcontentview
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
This is not a recommended way of solving this kind of errors in android, but at times when you are needy, you can use it. But I would not recommend doing this.
I never had a problem compiling my kivy applications before(done it many times) but i have one now : it throws the application normally on my Phone but when i open it it freezes on the presplash icon and gives me a message : "could not extract public data". i thought it was my sqlite3 file.
So i have changed its name and added to ./distribute.sh -m "sqlite3 kivy" and still have the problem.my build.py looks like this:
./build.py --dir /home/toufic/Desktop/Pay4 --name "Lebanese PayCalc" --package org.demo.PayCalc --version 1.2.4 --icon /home/toufic/Desktop/Pay4/lp.png --presplash /home/toufic/Desktop/Pay4/onmyown.png --permission INTERNET --permission WRITE_EXTERNAL_STORAGE --window debug installd
if i try to compile it with buildozer i have the following error :
File "/usr/lib/python2.7/bsddb/__init__.py", line 270, in <lambda>
return _DeadlockWrap(lambda: self.db[key]) # self.db[key]
bsddb.db.DBPageNotFoundError: (-30985, 'DB_PAGE_NOTFOUND: Requested page not found')
in my main.py file i have the following dependencies:
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ObjectProperty
from net_pay_oop import * # it's a class i have written and using its instance in my code
from kivy.uix.popup import Popup
from kivy.uix.label import Label
import sqlite3
import datetime
import os
import math
import smtplib
from kivy.core.window import Window
from kivy.uix.screenmanager import ScreenManager,Screen
import sys
long story short i need the right way to compile it either with python-for-android or the Buildozer utility(i'm new to this). can anyone please help according to the modules that i am using or is there a way to debug the build and know where the problem hides?
Edit: so I kind of made the app open but SMTP services at not working. Should I do ./distribute.sh "openssl sqlit3 kivy"?
the solution to smtp services to be enabled was to includ in distribute.sh the openssl option but still the error dispayed by my device : "could not extract public data" was not solved. i guess it is an sqlite3 issue but the thing is that this only happens upon first installation and my application loads normally afterwards and displays all saved data and browses them normally.