Ubuntu16.04编译tensorflow官方Android demo

1.下载tensorflow官方代码

git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git


2.下载Android SDK和Android NDK

Android SDK下载:在安装Android Studio时进行选择,

https://developer.android.com/studio/index.html?hl=zh-cn

Android NDK

下载地址:https://developer.android.com/ndk/downloads/older_releases.html

选择NDK r12b进行下载,高版本(r14b)目前编译可能报如下错误

tensorflow/core/kernels/BUILD:4542:1: C++ compilation of rule '//tensorflow/core/kernels:android_tensorflow_kernels'
 failed: clang failed: error executing command external/androidndk/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
 -gcc-toolchain external/androidndk/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -fpic -ffunction-sections
 ... (remaining 73 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.


3.编辑tensorflow/WORKSPACE文件,取消部分注释后并填入sdk和ndk路径后如下

# Uncomment and update the paths in these entries to build the Android demo.
android_sdk_repository(
    name = "androidsdk",
    api_level = 26,
    # Ensure that you have the build_tools_version below installed in the
    # SDK manager as it updates periodically.
    build_tools_version = "25.0.2",
    # Replace with path to Android SDK on your system
    path = "/home/sc/Android/Sdk",
)
#
# Android NDK r12b is recommended (higher may cause issues with Bazel)
android_ndk_repository(
    name="androidndk",
    path="/home/sc/android-ndk-r12b",
#    # This needs to be 14 or higher to compile TensorFlow.
#    # Please specify API level to >= 21 to build for 64-bit
#    # archtectures or the Android NDK will automatically select biggest
#    # API level that it supports without notice.
#    # Note that the NDK version is not the API level.
   api_level=24)

build_tools_version参考Sdk下面build-tools文件夹名称,api_level为SDK对应的Android版本对应数字

好几分钟后,就会有编译成功的提示

Target //tensorflow/examples/android:tensorflow_demo up-to-date:
  bazel-bin/tensorflow/examples/android/tensorflow_demo_deploy.jar
  bazel-bin/tensorflow/examples/android/tensorflow_demo_unsigned.apk
  bazel-bin/tensorflow/examples/android/tensorflow_demo.apk
INFO: Elapsed time: 394.902s, Critical Path: 56.04s

生成的apk文件位于bazel-bin/tensorflow/examples/android/文件夹下
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

upDiff

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值