Skip to content
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

Can't build a package with bcrypt as requirement #1910

Closed
Cheaterman opened this issue Jul 9, 2019 · 15 comments
Closed

Can't build a package with bcrypt as requirement #1910

Cheaterman opened this issue Jul 9, 2019 · 15 comments

Comments

@Cheaterman
Copy link
Contributor

Everything is in the title. If you attempt to build a package with bcrypt in the requirements, you'll get an error when it tries to import the "encodings" module.

@Cheaterman
Copy link
Contributor Author

This is due to SDL2 build blacklist: /pythonforandroid/bootstraps/sdl2/build/blacklist.txt

@Cheaterman
Copy link
Contributor Author

Adding the relevant files to a custom whitelist.txt doesn't seem to solve everything however, as now it fails on hashlib. Adding pycrypto to requirements doesn't seem to help.

@Cheaterman
Copy link
Contributor Author

This possibly runs quite deep and has been going on for a long time: https://stackoverflow.com/questions/24256134/using-hashlib-with-kivy-buildozer

@Cheaterman
Copy link
Contributor Author

#1260 this told me to add openssl to requirements, which I did. Now, I get a ModuleNotFoundError: No module named 'binascii' from hostpython3/Lib/zipfile.py...

@Cheaterman
Copy link
Contributor Author

Erf. A buildozer android clean debug seems to have fixed this one. :-)

So in short, it seems the only required steps are to add openssl to requirements in buildozer.spec, and manage the whitelist.txt to revert the blacklisted encodings.

The file looks as follows:

lib-dynload/*codec*
encodings/cp*.pyo
encodings/tis*
encodings/shift*
encodings/bz2*
encodings/iso*
encodings/undefined*
encodings/johab*
encodings/p*
encodings/m*
encodings/euc*
encodings/k*
encodings/unicode_internal*
encodings/quo*
encodings/gb*
encodings/big5*
encodings/hp*
encodings/hz*

And in buildozer.spec:
android.whitelist_src = whitelist.txt

The exact name of the config entry might be different in the future, I know it has changed in the past.

@Cheaterman
Copy link
Contributor Author

Oops: ImportError: dlopen failed: "/data/data/com.digitalfactoryparis.scs.app/files/app/_python_bundle/site-packages/bcrypt/_bcrypt.so" is 64-bit instead of 32-bit

I think I'll have to build a recipe, hehe.

@Cheaterman Cheaterman reopened this Jul 9, 2019
@Cheaterman
Copy link
Contributor Author

Cheaterman commented Jul 10, 2019

Here's the recipe I created for BCrypt - it's probably not optimal by any means, but hey, WorksForMe™ so I guess it's GoodEnough™ ? :-)
("created" is an overstatement, it's basically copypasta from CryptographyRecipe hehe)

from pythonforandroid.recipe import CompiledComponentsPythonRecipe, Recipe


class BCryptRecipe(CompiledComponentsPythonRecipe):
    name = 'bcrypt'
    version = '3.1.7'
    url = 'https://github.com/pyca/bcrypt/archive/{version}.tar.gz'
    depends = ['openssl', 'cffi']
    call_hostpython_via_targetpython = False

    def get_recipe_env(self, arch):
        env = super(BCryptRecipe, self).get_recipe_env(arch)

        openssl_recipe = Recipe.get_recipe('openssl', self.ctx)
        env['CFLAGS'] += openssl_recipe.include_flags(arch)
        env['LDFLAGS'] += openssl_recipe.link_dirs_flags(arch)
        env['LIBS'] = openssl_recipe.link_libs_flags()

        return env


recipe = BCryptRecipe()

@AndreMiras
Copy link
Member

Great work 👏
Why don't you pull request it?

@Cheaterman
Copy link
Contributor Author

Cheaterman commented Jul 10, 2019 via email

@Cheaterman
Copy link
Contributor Author

Cheaterman commented Jul 10, 2019 via email

@AndreMiras
Copy link
Member

No rush, you already provided the solution in this ticket. So if people are in a urge to see it in the tree, they know what to do 😄
As for the whitelist, I think it could also just be a docstring comment in the recipe listing the modules that need to be whitelisted and pointing to this issue.
Good luck at work

@tomgold182
Copy link
Contributor

I also had the
Oops: ImportError: dlopen failed: "/data/data/com.digitalfactoryparis.scs.app/files/app/_python_bundle/site-packages/bcrypt/_bcrypt.so" is 64-bit instead of 32-bit

issue!
Trying to compile now with your new recipe

@Cheaterman
Copy link
Contributor Author

I don't think this will work with arm64-v8a builds yet, I need to fix this properly at some point, can anyone provide some feedback on this? Thanks in advance :-)

@pablodz
Copy link

pablodz commented Nov 22, 2019

I also had the
Error: dlopen failed: "/data/data/com.pablogod.eica.eica/files/app/_python_bundle/site-packages/bcrypt/_bcrypt.so" is 64-bit instead of 32-bit
How can I fix it guys?
Some useful information:
image

Please, can you explain what's a recipe and where I need to compile?

@tomgold182
Copy link
Contributor

@ZurMaD check this
https://python-for-android.readthedocs.io/en/latest/recipes/#creating-your-own-recipe
Let me know if you need more help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants