-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Webview bootstrap. Where to start? [$100] #700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'd take the SDL2 bootstrap as a reference for the python unpacking etc, but strip out the SDL2 stuff and replace it with a webview. I'm not sure how threading will need to work with the python interpreter (maybe it will already), so I might start by running flask in a service.
I'll probably try this sometime if nobody else does first. |
Actually, I've been making a project that is a wrapper above Kivy, wxPython, etc. specifically for the purpose of creating cross-platform apps that use Web UI. You can check it out here: Follow the Getting Started section and let me know if you see any issues. Even if it doesn't work for you, the pew/kivy_pew/webview.py module can show you a start on how to do it yourself. |
I think Pyeverywhere is already too much for our purpose. But thanks for the link. Perhaps it can help in the future. I had a look to strip out the sdl stuff but I really don't know whats still needed in the java classes and so on. @inclement, could you try that? The only thing which is needed as a connection between the two components is to provide a URL for the Webview to display. thanks a lot |
Sorry, I wasn't suggesting just pulling the whole project into Kivy. Feel free to just integrate the code I wrote to get the Android WebView loaded into Kivy if it works for your purposes. It's mostly just some pyjnius code. There shouldn't be any licensing issues between the projects but if there are, let me know and I'll give permission to license it under Kivy's license. The main part of it is here: https://github.com/kollivier/pyeverywhere/blob/master/src/pew/kivy_pew/webview.py PEWWebViewClientInterface does rely on some Java code for callbacks, but you can either just delete that part or incorporate the Java code too (ideally the latter if I'm to use this on my project :). Having Kivy just start a WebView and not have to load SDL is what I want as well so I'd be more than happy to remove this code from my project if Kivy worked that way instead. I'm somewhat new to Kivy so I am just not at the point of knowing how to make that happen. Also, I'm working on an iOS version of this approach as well that uses pyobjus and WKWebView (which unfortunately runs afowl of pyojbus #124 so it won't be ready until that is tackled), and honestly I'd love to see a Kivy solution for this that works for both desktop (maybe using pyCEF / pyobjc) and mobile platforms. |
Surely you don't want to use kivy at all if you're just displaying a webview? |
What I need is a Python toolkit that lets me build apps for mobile that use a Web UI but lets me run various Python modules for data analysis and machine learning. While I don't currently need Kivy's UI controls, the fact that it lets me build mobile apps out of the box, load and use native UI controls via Python wrappers, and integrate popular Python libraries is a real time-saver for me. I know I could go lower-level with P4A and other tools and "build my own" but I have a Nov. deadline for my project so I need to be able to spend as much time as possible building my awesome app rather than building an optimized custom mobile Python dev toolchain that lets me build that awesome app. :) I'm open to other solutions, of course, but in my experimenting with what's out there this has given me the best results so far. |
its agnostic but i run my apps off a multi processed bottle framework using a thin event layer between javascript and python. webviews are handled by bottle. sl4a is integrated so you have ability to call to the native android api as well. this approach works very well for me and i have an app currently used by a company that is quite happy with the performance so far after 6 months in production... |
This branch contains a basic, working webview bootstrap that displays a webview without including Kivy or SDL2. I intend to tidy it up and do a PR within the next few days, but it shouldn't be anything very complicated. I'll also try to make pyjnius work with it. |
Hey @inclement, your branch looks promising. It seems that the webview_includes folder is not created when the dist is built. I get the following error when trying to build an apk.
If I then create the folder manually, I can build apks afterwards. After building your testapps/testapp_flask/ apk I get the following error in adb logcat:
What could be the reason for this? Is this the same as in #234? |
Looks like the webview_includes one is just me forgetting to check something into git. I'm not sure what's going on with pyjnius but it could be related (I made some unfinished changes), I'll look at it at the weekend. The main thing left to do right now is have java load the flask site once the server is running, which is giving me some weird problems but can't be that hard. |
Could that perhaps be done from python via jnius to get the webview and then load a URL. I can't just test this as I still can't get pyjnius to build (I tried with different sdk and ndk versions). It is a little bit strange, now I did a clean_all don't get the webview_includes error. (I tried in two different environments), but the jnius error is still there. On the other pc it is still a problem. I am currently building the app with the following commands, is that correct?
When I build commit b4fac4f I can run the apk, but it crashes after some clicks. When I connect with Chrome to localhost:5000 it does not crash.
This could be related to http://stackoverflow.com/questions/12591760/flask-broken-pipe-with-requests but the strange thing is it seems to work with chrome. |
Yes (although due to threading it probably needs a callback to the main thread), but it would need the user to insert this into their python code and I'd like to avoid this since it shouldn't be hard to just make java do it.
This seems to be a problem with flask master, but I have no idea what's going on. In my up to date branch (I'm not sure if I pushed it all here) I'm using the most recent flask release, which apparently doesn't have this problem. Your build command looks fine, though I haven't tried that arch or such a new android api. I'll be looking at this again in the next couple of days, and once I fix the java threading problem I'll make sure I can build using the clean branch as pushed here. That should hopefully fix it for everyone and then it can be merged. |
I've now fixed the problems I had and pushed everything to the branch, so it should probably work now. There was some unpushed stuff relating to pyjnius which would explain your problem there. |
Everything seemed to work in a clean p4a environment, so I've merged the webview bootstrap. Testing and new additions welcome! |
I just tested your pushed changes and they look good. The flask I just pushed some changes to a537d74 to make it possible to load a URL from java and python code. |
Hey @inclement, the webview_dist problem still exists. Even in the IRC someone else had this problem right now. Do you know, how to make sure the folder is created correctly? |
Uh oh!
There was an error while loading. Please reload this page.
I would like to have a python4android application which just starts a simple webview and accesses a local python webframework, like flask.
What is the recommended way to start.
Should I take the sdl2 bootstrap and generate a new stripped down version or should I start with the empty bootstrap?
Is there anything already done in that direction?
How can the webview be started? Should it be initialized by a java class or is it ok to use pyjnius like in the following gist?
https://gist.github.com/tito/6118172
Did you help close this issue? Go claim the $100 bounty on Bountysource.
The text was updated successfully, but these errors were encountered: