0

Because the Numpy isn't a static library(it contains .py files, .pyc files, .so files, etc), so if I want to import it to my python code which is used in an Android phone(using CLE), I should recompile the library as a .so file. I have found that if I want to use NDK to compile it, I should have an Application.mk and an Android.mk files. But I don't know how to create these files.

How can I compile the Numpy library or anyone could give me a useful website.

Thanks a lot.

shizhen
  • 12,251
  • 9
  • 52
  • 88
Rafael Huang
  • 25
  • 1
  • 13
  • Pydroid 3 can `pip` load numpy, scipy, matplotlib, scikit-learn and jupyter. – hpaulj Oct 11 '18 at 03:42
  • @hpaulj Pydroid 3 is an application to run python code. Frankly, I want to build an application, not just run a single python code in an Android mobile phone. – Rafael Huang Oct 11 '18 at 06:33

1 Answers1

0

I should have an Application.mk and an Android.mk files.

This is the older way of Android JNI programming, the current recommended style is to use CMake for NDK development.

If you just want a working example and do modification based on it, then you can find one from here: https://github.com/russell-shizhen/JniExample

I should recompile the library as a .so file

In order to recompile, you need its source code for sure. Without source code, you can only try to link those existing static libs to form your own .so lib.

shizhen
  • 12,251
  • 9
  • 52
  • 88
  • Okay I will see it. Numpy is a dynamic library, it contains various of types of files, how can I use CMake to compile it? – Rafael Huang Oct 11 '18 at 01:43
  • I used pip to install Numpy and Now I could get its folder. Does it contain the source code? – Rafael Huang Oct 11 '18 at 01:54
  • here is the Numpy source repo on github, https://github.com/numpy/numpy, but whether it can be compiled smoothly on Android is unknown to me. – shizhen Oct 11 '18 at 01:58
  • Just in case, this link may be helpful to your research: https://stackoverflow.com/questions/39533680/can-i-run-numpy-or-other-python-packages-on-android and https://github.com/termux/termux-packages/issues/1339 – shizhen Oct 11 '18 at 02:01
  • I have tried the source code, the module could be found because it just contains .py files, however an error occurred: cannot find the attribute "Array". I guess the source code also should be compiled, but if compiled, some .so files will interrupt us to import the Numpy Lib. Do you know how to solve it? – Rafael Huang Oct 11 '18 at 06:09
  • Be aware that all the existing `.so` files that are not originally compiled using **NDK** won't work on Android properly. You need EVERYTHING to be source code and recompile those source using NDK. Usually, this is not a trivial work to do. – shizhen Oct 11 '18 at 07:10
  • Do you have ways to help me use NDK to compile the Numpy lib? I find it is really difficult to me... – Rafael Huang Oct 11 '18 at 07:18
  • Just to clarify, you do not *need* to switch from ndk-build. CMake is merely an alternative. See https://stackoverflow.com/a/39601122/632035 – Dan Albert Oct 11 '18 at 18:21
  • @DanAlbert, Yes, don't have to – shizhen Oct 12 '18 at 01:01