- Prepare your machine https://www.tensorflow.org/versions/r0.11/get_started/os_setup.html#installing-from-sources
- git clone --recursive https://github.com/tensorflow/tensorflow.git
- Edit the WORKSPACE file (uncomment Android paths)
- Run ./configure script
- bazel build //tensorflow/examples/android:tensorflow_demo --fat_apk_cpu=armeabi-v7a,arm64-v8a
Copy libs to facerecognitionlibrary to compile the tensorflow so-file
- Copy all from "tensorflow/bazel-out/android-aarch64-linux-android-4.9-gnu-libstdcpp-fastbuild/genfiles/tensorflow" to "facerecognitionlibrary/jni-build/jni/genfiles/tensorflow"
- Copy all from "tensorflow/tensorflow" to "facerecognitionlibrary/jni-build/jni/include/tensorflow"
- Copy all from "tensorflow/third_party" to "facerecognitionlibrary/jni-build/jni/include/third_party"
- Copy all from "tensorflow/bazel-tensorflow/external/protobuf" to "facerecognitionlibrary/jni-build/jni/include/google/protobuf"
- Copy the files "libprotos_all_cc.a", "libandroid_tensorflow_lib.lo", "libandroid_tensorflow_lib_lite.lo", "kernels/libandroid_tensorflow_kernels.lo" from "tensorflow/bazel-out/android-aarch64-linux-android-4.9-gnu-libstdcpp-fastbuild/bin/tensorflow/core" to "facerecognitionlibrary/jni-build/jni/libs/arm64-v8a"
- Copy the files "libprotobuf.a" and "libprotobuf_lite.a" from "tensorflow/bazel-out/android-aarch64-linux-android-4.9-gnu-libstdcpp-fastbuild/bin/external/protobuf" to "facerecognitionlibrary/jni-build/jni/libs/arm64-v8a"
- Change line in Application.mk to "APP_ABI := arm64-v8a"
- Delete the lines "'-Wl,--icf=all' ", "'-march=armv7-a' " and "-Wl,--fix-cortex-a8 " in the Android.mk file
- Make, Make install
在tensorflow源代码包中运行,下面编译指令,生成libtensorflow_inference.so. 通过修改cpu=arm64-v8a,armeabi-v7a,armeabi分别生成各平台的so。
Then, to build the native TF library:
bazel build -c opt //tensorflow/contrib/android:libtensorflow_inference.so \
--crosstool_top=//external:android/crosstool \
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
--cpu=armeabi-v7a
在tensorflow源代码包中运行,下面编译指令,生成libtensorflow_demo.so. 通过修改cpu=arm64-v8a,armeabi-v7a,armeabi分别生成各平台的so。
bazel build //tensorflow/examples/android:tensorflow_demo --fat_apk_cpu=armeabi-v7a,arm64-v8a
然后将2个so库,分别放入android studio jnilibs的对于lib库文件加