1

I'm trying to make a project where I use TFLite in my native c++ code through NDK inside my android application. So far I've build and tested TFLite on my pure c++ linux project. Now I want to build and run it on my Android project which uses a somewhat similar code base as my pure linux project, with an android UI on top. It should be on an ARM64 architecture

I was following the official docs (the non-docker part) which asked me to run ./configure on my tensorflow file which I got from extracting the 2.11 release from it's github repo.

My first question is how do I properly set this up and compile everything? Currently I'm following this question which seems like a decent option but I would rather follow an official set of instructions (although as long as it works I'm fine).

My real question is this: Do I have to use NDK < 21? My project currently (because of other dependencies) only supports NDK > 22 which as you can tell creates a problem for me. Is there a way to build TFLite for NDK versions above 22?

When I run ./configure and say yes to configuring ./WORKSPACE I get this output:

WARNING: The NDK version in /home/user/Android/Sdk/ndk/25.1.8937393 is 25, which is not supported by Bazel (officially supported versions: [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]). Please use another version. Compiling Android targets may result in confusing errors.

Traceback (most recent call last):
  File "/home/user/Desktop/Android_build/tensorflow-2.11.0/./configure.py", line 1362, in <module>
    main()
  File "/home/user/Desktop/Android_build/tensorflow-2.11.0/./configure.py", line 1335, in main
    create_android_ndk_rule(environ_cp)
  File "/home/user/Desktop/Android_build/tensorflow-2.11.0/./configure.py", line 653, in create_android_ndk_rule
    get_ndk_api_level(environ_cp, android_ndk_home_path))
  File "/home/user/Desktop/Android_build/tensorflow-2.11.0/./configure.py", line 746, in get_ndk_api_level
    api_levels = sorted(os.listdir(platforms))
FileNotFoundError: [Errno 2] No such file or directory: '/home/user/Android/Sdk/ndk/25.1.8937393/platforms'

If possible, I just want to get the android compatible .so files for clang++ so I can just add that to my pure C projects cmake file and ndk can run it.

I've installed NDK though android studios interface and I'm using debian 11.

Note: Since I'm not inside a project, there is no local.properties file for me to edit and add the path. I'm trying to configure and run bazel inside the source directory I got from tensorflows github page.

Turgut
  • 711
  • 3
  • 25
  • Does [this](https://stackoverflow.com/questions/46741528/ndk-is-missing-a-platforms-directory-while-trying-to-build) answer your question? – user20716902 Feb 01 '23 at 10:29
  • @user20716902 yes and no, this may solve the missing path issue but the question of running the app on ndk 22> still remains. – Turgut Feb 01 '23 at 10:53
  • @user20716902 I've tried everything on that question but since I'm not building with a project I don't have a `local.properties` file. – Turgut Feb 01 '23 at 12:20
  • I had a different reason for not using bazel, and did manage to build static arm64 library libtensorflow-lite.a for NDK 23 using the cmake instructions on tensorflow.org. However my attempt to build arm64 shared library .so failed in several ways, only one of which was currently an unresolved issue on github. – J B Apr 10 '23 at 14:47

0 Answers0