kivy / kivy-ios

Toolchain for compiling Python / Kivy / other libraries for iOS
https://kivy.org/docs/guide/packaging-ios.html
MIT License
777 stars 240 forks source link

Custom recipes don't add the `.a` to the XCode project #642

Open meow464 opened 3 years ago

meow464 commented 3 years ago

Versions

We were able to test on those versions but it probably affects any version.

Describe the bug toolchain build myrecipe --add-custom-recipe /path/to/myrecipe builds the recipe correctly but doesn't add the .a file to the XCode project. If you drag and drop it under Frameworks then everything just works.

To Reproduce toolchain build myrecipe --add-custom-recipe /path/to/myrecipe You can use this simple recipe to test it. It's a simple Cython recipe that queries the iOS version.

Expected behavior The .a file should be automatically added under the Frameworks folder in the XCode project.

Logs

2021-09-23 14:41:06.652066-0700 myapp[46351:3595957] Available orientation: KIVY_ORIENTATION=LandscapeLeft LandscapeRight Portrait PortraitUpsideDown
2021-09-23 14:41:06.652426-0700 myapp[46351:3595957] Initializing python
2021-09-23 14:41:06.811536-0700 myapp[46351:3595957] Running main.py: /Users/tuco/Library/Developer/CoreSimulator/Devices/E34D8146-ED7A-4771-AAFE-02C4FC26464B/data/Containers/Bundle/Application/159F0B96-3B8A-4704\
-A5F1-765E7664D138/myapp.app/YourApp/main.pyc
Traceback (most recent call last):
  File "/Users/tuco/Projects/ios_recipes/myapp/.buildozer/ios/platform/kivy-ios/myapp-ios/YourApp/main.py", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_myrecipe)
2021-09-23 14:41:06.814412-0700 myapp[46351:3595957] Application quit abnormally!
2021-09-23 14:41:06.819038-0700 myapp[46351:3595957] Leaving
meow464 commented 3 years ago

The .a files are added by the update_pbxproj() function

    for recipe in Recipe.list_recipes():
        # Some code here
        pbx_frameworks.extend(recipe.pbx_frameworks)
        pbx_libraries.extend(recipe.pbx_libraries)
        libraries.extend(recipe.dist_libraries)
        frameworks.extend(recipe.frameworks)

The called function list_recipes():

    def list_recipes(cls, **kwargs):
        skip_list = kwargs.pop("skip_list", ['__pycache__'])
        recipes_dir = join(dirname(__file__), "recipes")
        for name in sorted(listdir(recipes_dir)):
            fn = join(recipes_dir, name)
            if isdir(fn) and name not in skip_list:
                yield name

As you can see, the list_recipes() function reads the recipes directly form kivy_ios/recipes and completely ignores any --add-custom-recipe argument that might have been passed.

Solution: The update command already accepts a --add-framework parameters, might as well accept --add-custom-recipe. Now the user needs to run: toolchain build myrecipe --add-custom-recipe /path/to/myrecipe AND toolchain update xcodeproj myrecipe --add-custom-recipe /path/to/myrecipe.

I will make a pull request.

meow464 commented 3 years ago

Pull request

tcaduser commented 1 year ago

it doesn't look like this was ever accepted, because I still find myself copying my recipe manually into the kivy_ios module:

$VIRTUAL_ENV/lib/python3.9/site-packages/kivy_ios/recipes/myapp/__init__.py