Setting targetSdkVersion and compileSdkVersion for bazel, android tensorflow

让人想犯罪 __ 提交于 2021-02-16 21:07:21

问题


I need help in how to set the target and compile Sdk versions separately for bazel.

I want to run tensorflow on the phone following this tutorial. After editing WORKSPACE for bazel as follows:

android_sdk_repository(
    name = "androidsdk",
    api_level = 24,
    build_tools_version = "24.0.1",
    path = "/home/Android/Sdk",
)

android_ndk_repository(
    name="androidndk",
    path="/home/Android/Sdk/ndk-bundle",
    api_level=21)

I get PARSE ERROR on the phone upon apk installing:

adb install -r bazel-bin/tensorflow/examples/android/tensorflow_demo.apk

I have usb debugging and 3rd party apk installation enabled. The phone uses Android 4.4.4 so I changed WORKSPACE configuration to match it (tools and API installed by SDK manager properly) as:

android_sdk_repository(
    name = "androidsdk",
    api_level = 19,
    build_tools_version = "19.1.0",
    path = "/home/Android/Sdk",
)

android_ndk_repository(
    name="androidndk",
    path="/home/Android/Sdk/ndk-bundle",
    api_level=21)

Upon building as:

bazel build //tensorflow/examples/android:tensorflow_demo

I end up with few errors of that type:

Error at 5 : /tmp/android_resources_tmp7060220119759636814/merged_resources/values-v21/values.xml:5: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material.Light'.

Following this answer, I should build for compile API version > 21 but at the same time target API version 19. It can be easily set for gradle. However I have not found any clue how to do that for bazel. Any suggestions are appreciated!


回答1:


If you want to target a lower Android API level, the file you want to edit is actually tensorflow/examples/android/AndroidManifest.xml. Leave the WORKSPACE file settings at the highest API level you have installed via your sdk (APIs can be installed with $ANDROID_HOME/tools/android).

You can lower the min API level to 19 in AndroidManifest.xml, but be aware you will encounter runtime errors on your phone running the demo unless you replace the demo code that interfaces with the camera2 api (which was added with API level 21) with analogous android.hardware.camera code.



来源:https://stackoverflow.com/questions/41478820/setting-targetsdkversion-and-compilesdkversion-for-bazel-android-tensorflow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!