godot-python icon indicating copy to clipboard operation
godot-python copied to clipboard

Would this work on Android and iOS ?

Open SeleDreams opened this issue 4 years ago β€’ 11 comments

Hi, I am currently developping an application meant to work on PC and Mac as well as on Android and iOS, however for the application to work I'd need to rely on a library made in python https://github.com/r9y9/nnsvs however I can't tell if it's going to work or not that's why i'd like to know if it's possible

SeleDreams avatar Aug 10 '21 00:08 SeleDreams

Hi @SeleDreams !

Python on Android is a huge mess, see https://github.com/touilleMan/godot-python/issues/251#issuecomment-830626047 So I would advice against it (especially combined with Godot which add another layer of complexity !)

touilleMan avatar Aug 13 '21 12:08 touilleMan

Hi @SeleDreams !

Python on Android is a huge mess, see #251 (comment) So I would advice against it (especially combined with Godot which add another layer of complexity !)

i see, since my python calls would basically not need to call any godot apis and would work on their own i guess i could maybe rely on some other more general way to run python on android

SeleDreams avatar Aug 13 '21 13:08 SeleDreams

i'm thinking about using sl4a for my use case since i litterally just need to call a python script to make it generate something and get the result

SeleDreams avatar Aug 13 '21 13:08 SeleDreams

sl4a seems unmaintained, you'd better use p4a which is kind of ok if your code is pure Python (and your native dependencies are supported by p4a), but as soon as you try to do something a bit exotic (for instance trying to have a GUI in java instead of using Kivy for it) everything breaks everywhere :/

touilleMan avatar Aug 13 '21 13:08 touilleMan

Any update on this devs?

Sam2much96 avatar Aug 13 '22 14:08 Sam2much96

How would a hypothetical android export workflow be using Python-for-android?

I'm thinking that Building godot-python from master and getting dependencies from Python-for-android would work.

Any advise, any suggestions? I'm gonna fomo this issueπŸ‘€

Sam2much96 avatar Aug 13 '22 15:08 Sam2much96

I'm thinking that Building godot-python from master

Godot-Python relies on python-build-standalone to embed the python interpreter. So far python-build-standalone doesn't support Android so that's the first issue ;-)

and getting dependencies from Python-for-android would work.

I guess in theory you could create a dummy python-for-android project to do the cross-compilation of python dependencies, then extract those elements and put them into your godot project (in the godot-python site-packages folder). However you would also have to heavily modify the godot android boilerplate to include the hacks done in the python-for-android android boilerplate. Typically in android your files in the apk are not installed on disk by default, so you cannot just do import foo in python, the android boilerplate have to manually extract all the python file on disk at the first launch of the application :/

touilleMan avatar Aug 13 '22 17:08 touilleMan

Oh! I see what you mean. It would have been easier if python-build-standalone supported Android. Cloning an existing Android interpreter and then integrating it into the scons build, initializing it within Godot, integrating it into Godot-python, getting the required android dependencies, and exporting the final packages to the android APK would be very difficult and very buggy. Also, the possibility of running a separate python interpreter which may not bind successfully to Godot c++ libraries already puts the chances of failure at 90%.

I'm not building anything major in it though. Can you please share the repository link to your barely usable android build if it's available? It'll be a great starting point for me!

My test project only uses one module (requests module), to fetch data from a Simple HTTPS Python server. I should be able to make it workπŸ™

Sam2much96 avatar Aug 13 '22 18:08 Sam2much96

Can you please share the repository link to your barely usable android build if it's available?

Sorry this code is not open-source, however you should have a look at Beeware's Android support which is really great starting point

My test project only uses one module (requests module), to fetch data from a Simple HTTPS Python server. I should be able to make it workpray

If that's the case, I would advice you to replace this part by Godot's own HTTP class, this should be really simple if you don't have exotic needs ;-)

touilleMan avatar Aug 13 '22 19:08 touilleMan

First link is broken boss

https://github.com/beeware/Python-Android-support

Godot HTTP class keeps on returning an empty poolbytearray() whenever i'm running a self hosted secured server (https://) with a self signed certificate. It works fine with public api's and local hosting. Spent 2-3 days debugging, thought it's best I implement Python and the request module works seamlessly.

I'll make a pull request if I'm successful!

Sam2much96 avatar Aug 13 '22 19:08 Sam2much96

I've build CPython for android but it's python 3.7, I've also setup p4a to build the required modules for my Godot python addon. I guess i'd have to modify the Scons to build gdnative bindings for android platform. but rather than downloading CPython, it'll use pre-built CPython for andoid binaries

Sam2much96 avatar Aug 14 '22 15:08 Sam2much96