• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15# ==============================================================================
16set -e
17set -x
18
19TMPDIR=`mktemp -d`
20trap "rm -rf $TMPDIR" EXIT
21
22VERSION=1.0
23
24BUILDER=bazel
25BASEDIR=tensorflow/lite
26CROSSTOOL="//external:android/crosstool"
27HOST_CROSSTOOL="@bazel_tools//tools/cpp:toolchain"
28
29BUILD_OPTS="-c opt"
30CROSSTOOL_OPTS="--crosstool_top=$CROSSTOOL --host_crosstool_top=$HOST_CROSSTOOL"
31
32test -d $BASEDIR || (echo "Aborting: not at top-level build directory"; exit 1)
33
34function build_basic_aar() {
35  local OUTDIR=$1
36  $BUILDER build $BUILD_OPTS $BASEDIR/java:tensorflowlite.aar
37  unzip -d $OUTDIR $BUILDER-bin/$BASEDIR/java/tensorflowlite.aar
38  # targetSdkVersion is here to prevent the app from requesting spurious
39  # permissions, such as permission to make phone calls. It worked for v1.0,
40  # but minSdkVersion might be the preferred way to handle this.
41  sed -i -e 's/<application>/<uses-sdk android:targetSdkVersion="25"\/><application>/' $OUTDIR/AndroidManifest.xml
42}
43
44function build_arch() {
45  local ARCH=$1
46  local CONFIG=$2
47  local OUTDIR=$3
48  mkdir -p $OUTDIR/jni/$ARCH/
49  $BUILDER build $BUILD_OPTS $CROSSTOOL_OPTS --cpu=$CONFIG \
50    $BASEDIR/java:libtensorflowlite_jni.so
51  cp $BUILDER-bin/$BASEDIR/java/libtensorflowlite_jni.so $OUTDIR/jni/$ARCH/
52}
53
54rm -rf $TMPDIR
55mkdir -p $TMPDIR/jni
56
57build_basic_aar $TMPDIR
58build_arch arm64-v8a arm64-v8a $TMPDIR
59build_arch armeabi-v7a armeabi-v7a $TMPDIR
60build_arch x86 x86 $TMPDIR
61build_arch x86_64 x86_64 $TMPDIR
62
63AAR_FILE=`realpath tflite-${VERSION}.aar`
64(cd $TMPDIR && zip $AAR_FILE -r *)
65echo "New AAR file is $AAR_FILE"
66
67