amwebexpert / poc-mobile-python

Python multi-platform app using the KivyMD framework, integrating Artificial Intelligence features.
MIT License
8 stars 3 forks source link

Create the iOS build distribution #1

Closed Andre-the-Viking closed 11 months ago

Andre-the-Viking commented 1 year ago

Create the iOS package App Store (IPA) solution

Contributors are welcome!

Tasks:

Optional task(s):

costa-rica commented 1 year ago

Hi @Andre-the-Viking, I'm on this.

I'm new to contributing so not sure how/when to submit/push stuff to your repo. In the meantime here's what I started https://github.com/costa-rica/Open-Mindset-iOS.

amwebexpert commented 1 year ago

Hi Nick!

Glad to see you onboard 😅 We are all learning on many ways (Github, Python, Kivy...) so no worries. If that's your very first pull request on an opensource project, I think this post is going to help you for the whole process from creating your branch till the pull request creation:

From there we will review and merge into main branch

costa-rica commented 1 year ago

Yes, very helpful! Thank you!

Now, back to our project, I’ve forked and branched poc-mobile-python. I think my next step should be to make a kivy_ios directory and move my work in there? Then that will house the .py, .kv, requirements.txt, assets for the iOS application, etc., Is that right?

I do see a main.py file in the root of the repo. Did you intend that connect to the work / prototype I’m building?

amwebexpert commented 1 year ago

Yes, this should be the entry point. If you find a way to move it directly as a child of the existing src/ folder and ensure the iOS build process can still be happy with that do not hesitate!

costa-rica commented 1 year ago

Oooooh ... ok, I misunderstood what was going on. You've already built the app and it works! I think I’m more "directionally" correct now.

Nice work! App looks great! I’ve got a lot to learn.

I was able to build the Xcode project. But unable to run it on the simulator. I’ve attached a screen shot of errors in Xcode project after trying to run the simulator. I just want to make sure this isn’t another thing you’ve already tackled and I’ve overlooked your progress?

If you have any suggestions about what to look into, gladly take it. Otherwise, I'll pick up here and look deeper into these errors. Doesn't seem to be a problem with your code. Looks like some of the stuff being used to convert to an Xcode is the problem.

Screenshot 2023-09-19 at 23 03 53

amwebexpert commented 1 year ago

Interesting, looks like a build issue like you said. I've documented the latest recipe for an iOS build inside the corresponding README.md - Building for iOS section, can you have a look at the steps, and perhaps something needs to be fixed in the recipe itself 🤔 ?

Otherwise, the very first step is to verify (again) the README.md getting started section so you can validate the app and it`s required dependencies can build and run on you desktop

costa-rica commented 1 year ago

Did you build this in python 3.10?

amwebexpert commented 1 year ago

Yes with Python 3.10.2 on macOS I've been able to do an iOS build that I then installed onto the iPhone Simulator.

At some point with Python 3.11 I was not able to succeed until I read your article 😅 from there on I decided to stick to 3.10.x

costa-rica commented 1 year ago

Almost there...

Is this right? Screenshot 2023-09-20 at 18 56 07

I saw kivy.network.urlrequest library in the repo and I'm guessing that is standard encryption? Honestly, I wouldn’t know how to spot proprietary or not accepted as standard encryption. Glad to get any insight on this as well?

amwebexpert commented 1 year ago

I agree, seems to me the right choice, since none of our open-source dependencies is doing non standard encryption

costa-rica commented 1 year ago

Not sure how this works usually, but I wanted to give you a status update since I've been quite for a while and in case you thought I just left the project without telling you haha... jk ... It turns out I’m having more trouble than I expected. I found two problems.

  1. Xcode Project is not consistently building to my iPhone. I think it has to do with my M1 arm64 architecture. I have also been switching between xcode14/15 for my iOS17 - not sure if there is an issue there as these have just come out. There must be either a setting, toolchain env, or something that is causing Xcode projects (that come from Python/Kivy) to not build to iPhone or in my case build inconsistently. What I mean by that is certain built projects work all the time and others do not work.

There was one Xcode project that did not work (using Xcode15beta). I deleted (Xcode15beta) and installed Xcode15(new). Then the project worked. In hopes that was the problem, I tried to rebuild a toolchain environment from scratch and run that in my new Xcode15, however, that failed. I've since tried a variety of changes to setting, environment vars, etc,. No sure what's going on.

The built Xcode projects that never work have errors of this variety:

Building for 'iOS', but linking in dylib (/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics.tbd) built for 'iOS-simulator'
Linker command failed with exit code 1 (use -v to see invocation)

My research points to these errors being related to my architecture being arm64 and something about the Xcode Project doing x86_64, but I’m not sure exactly.

I've been trying to methodically go through the Xcode project setting. Below is a text compare of Xcode Settings exported to text. Oddly, the one on the right does not build to my iPhone, while the one on the left does. Besides the names of the projects, the rest of these settings text exports are identical.

Screenshot 2023-09-26 at 12 24 51

2.Now, on the Xcode Projects that have successfully built to my iPhone, these crash immediately. It seems something to do with accessing the database. Here is everything from the terminal on these builds (startup to crash):

Available orientation: KIVY_ORIENTATION=LandscapeLeft LandscapeRight Portrait PortraitUpsideDown
Initializing python
<string>:1: DeprecationWarning: the imp module is deprecated in favour of importlib and slated for removal in Python 3.12; see the module's documentation for alternative uses
Running main.py: /private/var/containers/Bundle/Application/42FD4D2A-BBED-4DF0-B39B-02A3AFDA9B0B/openmindset.app/YourApp/main.pyc
[INFO   ] [Logger      ] Record log in /private/var/mobile/Containers/Data/Application/584FCE8B-FF9A-4EEA-B950-267FFCAD87C9/Documents/.kivy/logs/kivy_23-09-27_0.txt
[INFO   ] [Kivy        ] v2.2.1
[INFO   ] [Kivy        ] Installed at "/private/var/containers/Bundle/Application/42FD4D2A-BBED-4DF0-B39B-02A3AFDA9B0B/openmindset.app/lib/python3.10/site-packages/kivy/__init__.py"
[INFO   ] [Python      ] v3.10.10 (main, Sep 21 2023, 16:45:58) [Clang 14.0.3 (clang-1403.0.22.14.1)]
[INFO   ] [Python      ] Interpreter at "/private/var/containers/Bundle/Application/42FD4D2A-BBED-4DF0-B39B-02A3AFDA9B0B/openmindset.app/openmindset"
[INFO   ] [Logger      ] Purge log fired. Processing...
[INFO   ] [Logger      ] Purge finished!
[INFO   ] [Factory     ] 190 symbols loaded
[INFO   ] [Image       ] Providers: img_imageio, img_tex, img_sdl2 (img_dds, img_ffpyplayer, img_pil ignored)
[INFO   ] [Clipboard   ] Provider: sdl2
[INFO   ] [KivyMD      ] 1.1.1, git-Unknown, 2023-09-18 (installed at "/private/var/containers/Bundle/Application/42FD4D2A-BBED-4DF0-B39B-02A3AFDA9B0B/openmindset.app/lib/python3.10/site-packages/kivymd/__init__.py")
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Window      ] Provider: sdl2
You need UIApplicationSupportsIndirectInputEvents in your Info.plist for mouse support
[INFO   ] [GL          ] Using the "OpenGL ES 2" graphics system
[INFO   ] [GL          ] Backend used <sdl2>
[INFO   ] [GL          ] OpenGL version <b'OpenGL ES 2.0 Metal - 99'>
[INFO   ] [GL          ] OpenGL vendor <b'Apple Inc.'>
[INFO   ] [GL          ] OpenGL renderer <b'Apple A15 GPU'>
[INFO   ] [GL          ] OpenGL parsed version: 2, 0
[INFO   ] [GL          ] Shading version <b'OpenGL ES GLSL ES 1.00'>
[INFO   ] [GL          ] Texture max size <4096>
[INFO   ] [GL          ] Texture max units <8>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
Got dlopen error on Foundation: dlopen(/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation, 0x0001): tried: '/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation' (no such file), '/private/preboot/Cryptexes/OS/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation' (no such file), '/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation' (no such file, not in dyld cache)
Got fallback dlopen error on Foundation: dlopen(/Groups/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation, 0x0001): tried: '/Groups/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation' (no such file), '/private/preboot/Cryptexes/OS/Groups/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation' (no such file), '/Groups/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation' (no such file)
 Traceback (most recent call last):
   File "/Users/nick/Documents/KivyBuilds05/openmindset-ios/YourApp/main.py", line 7, in <module>
   File "/Users/nick/Documents/KivyBuilds05/openmindset-ios/YourApp/libs/main_app.py", line 33, in __init__
   File "/Users/nick/Documents/KivyBuilds05/openmindset-ios/YourApp/libs/features/settings/preferences_service.py", line 13, in __init__
   File "/Users/nick/Documents/KivyBuilds05/openmindset-ios/YourApp/libs/services/storage_service.py", line 16, in connect
 sqlite3.OperationalError: unable to open database file
cannot open file at line 46973 of [554764a6e7]
os_unix.c:46973: (2) open(/private/var/containers/Bundle/Application/42FD4D2A-BBED-4DF0-B39B-02A3AFDA9B0B/openmindset.app/YourApp/preferences.db) - No such file or directory
Application quit abnormally!
Leaving

I was able to get this build to TestFlight and it too crashes immediately when I download from TestFlight to my iPhone. I imagine it's the same reason, but not entirely sure since I've not seen any crash reports.

I first need to understand how to consistently build a Kivy app to Xcode so that I can run it on my iPhone.

Any ideas/thoughts on any of this I'd be glad to take. Otherwise, I'll keep you posted as I get more info.

costa-rica commented 1 year ago

Not sure if this is convention but I've put this on stackoverflow in case anyone might have some ideas: https://stackoverflow.com/questions/77187827/xcode-project-originally-python-kivy-not-building-to-iphone

amwebexpert commented 1 year ago

Perhaps I can try to build by following any procedure you may have documented, because my workstation has an Apple M1 Pro chip.

Also regarding File "/Users/nick/Documents/KivyBuilds05/openmindset-ios/YourApp/libs/services/storage_service.py", line 16, in connect sqlite3.OperationalError: unable to open database file

I'm surprised, because sqlite3 typically creates the db for the very 1st time (auto create the file if it does not exists) so perhaps it's a write permission issue 🤔 ... Maybe the default access to that folder is read and we have to specify we need to write as well?

Or... maybe we need to specify a sub-foder, like 'Database/xxyyzz.db' 🤔 ? You can try this within storage_service.py:

# self.conn = sqlite3.connect(self.db_name)
self.conn = sqlite3.connect(f"Database/{self.db_name}")
costa-rica commented 1 year ago

Oh man, yea that would be great if you could give it a try. I'd really like to know what you see. I started editing the readme.md, but it's getting messy.

Use this :point_right: build_ios.md I made instructions and added it to my ios_build_01 branch of the forked project.

amwebexpert commented 1 year ago

Ok will try the procedure this weekend since I have no time during the week :)

amwebexpert commented 1 year ago

Trying the procedure! 🤞 ...

Will note here things I have to do diff. from the procedure (you will LMK if that's ok or not)

Before all, I had to start a terminal in Rosetta mode

I'm still confused about why _environments/mindset needs to be created (or even if it's useful?)

At step

then got this issue:

  STDOUT:
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/certifi/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/certifi/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTT... (1544 more, please see e.stdout)

  STDERR:

Traceback (most recent call last):
  File "/Users/andre.masson/git/perso/costa-rica/poc-mobile-python/mindset/bin/toolchain", line 8, in <module>
    sys.exit(main())

this is really time-consuming stuff... 😫 perhaps will give this another try later

costa-rica commented 1 year ago

Hey,

  1. _environments/mindset

I believe when working with kivy-ios we do not want the venv inside of the project folder with the code. So I make a separate directory that holds all my environments.

All the necessary python packages should be added via toolchain.

Does that answer the question?

  1. As for your error, my instinct is it’s not pointing to the right python venv.

When you do which python3.10 do you get the python from your _environments/mindset venv?

I re-did the process this morning and made a new venv (mindset03). Here’s what mine looks like:

(mindset03) ➜  KivyBuilds10 which python3.10
/Users/nick/Documents/_environments/mindset03/bin/python3.10

Other than that did you make sure openssl is installed in brew?

brew install openssl
amwebexpert commented 1 year ago

Hi Nick, again, feel free to extract and re-organize all information from ## Building for iOS section inside the new build_ios.md

amwebexpert commented 11 months ago

Issue solved!