sofdigital / DroidPython

Python app development with SL4A in Android Studio
MIT License
55 stars 17 forks source link

Importing PyCrypto #9

Closed mehrdadmraad closed 7 years ago

mehrdadmraad commented 7 years ago

I need to import PyCrypto in my DROID-PYTHON project so I added Crypto directory to the python_extras_27.zip file (/packages/python) but could not import any modules when using the following import in my python code:

from Crypto.Cipher import ARC4

I tried putting Crypto directory in the (/packages/python/site-packages) directory but again not successful, then tried putting ARC4 directly in (/packages/python) directory and use (import ARC4) in my python code, but no success again.

Then I found a Crypto directory in (/packages/python/gdata) directory which I guess is compiled for use with android, but many of PyCrypto modules are missing in its Cipher directory i.e. ARC4 or AES!

Would you please let me know how and which PyCrypto library to add or to use so that each module of this library can be imported without any error?

Thanx

michaelrinderle commented 7 years ago

Is PyCrypto purely python? If not, you might have to re-compile it's binary files with the android-ndk.

mehrdadmraad commented 7 years ago

Thank you very much for your reply.

I've downloaded the latest PyCrypto from pypi at the following address:

https://pypi.python.org/pypi/pycrypto

which is a zip file (pycrypto-2.6.1.tar.gz) containing pure python codes (only .py files)

michaelrinderle commented 7 years ago

can you provide your logcat output when getting the error? as well as a sample of your script.

mehrdadmraad commented 7 years ago

Here are the logcat.txt and hello.py, note that without importing PyCrypto I get no errors from python script.

Thanx

logcat.txt my_python_project.zip

mehrdadmraad commented 7 years ago

P.S.

I'm able to import compiled Crypto modules from /packages/python/gdata/Crypto like RSA with no errors as follows:

from gdata.Crypto.PublicKey import RSA

So it's clear that only modules that are compiled for android can be imported, but some useful modules are missing from /packages/python/gdata/Crypto in the python_extras_27.zip which I really need to import including ARC4, AES, and SHA256!

Would you please let me know how I can find them on the net or how to recompile existing binary modules using android ndk?

Thanx so much

michaelrinderle commented 7 years ago

You can get a quick overview of compiling python for android Here. It such a painful process that its a major reason I (as well as others) have moved away from this project. I write all my mobile apps in c#/ xamarin.forms these days...

mehrdadmraad commented 7 years ago

Thank you very much and I really appreciate your help.

I read the page you introduced carefully, it seems that by doing the instruction I will have the python interpreter compiled as an executable for android.

1) But isn't it already included in DROID-PYTHON package in the file python_27.zip? 2) What about the PyCrypto library? Should I have to download and make it besides the python package before starting the cross compile Python runtime for use in Android? 3) Will the PyCrypto modules be compiled for android as well?

Sorry for too many questions but I just want to discover that is it worth to bear such a painful process and after all Will I reach to the PyCrypto modules compiled for android or not?

Thanx so much

mehrdadmraad commented 7 years ago

P.S.

Is it OK to use QPython for Android instead of the compiled python included in python_27.zip?

There is already a PyCrypto package working for QPython: https://drive.google.com/file/d/0B9cgr9L98QxzR0t3S0VoUWxQeTg/view?usp=drivesdk

Regards

michaelrinderle commented 7 years ago

I'm not sure. I haven't tried it, but as along as it's compiled for the android architecture I don't see why it wouldn't work.