Home | History | Annotate | Download | only in java
      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 # ==============================================================================
     16 set -e
     17 set -x
     18 
     19 TMPDIR=`mktemp -d`
     20 trap "rm -rf $TMPDIR" EXIT
     21 
     22 VERSION=1.0
     23 
     24 BUILDER=bazel
     25 BASEDIR=tensorflow/contrib/lite
     26 CROSSTOOL="//external:android/crosstool"
     27 HOST_CROSSTOOL="@bazel_tools//tools/cpp:toolchain"
     28 
     29 BUILD_OPTS="--cxxopt=--std=c++11 -c opt"
     30 CROSSTOOL_OPTS="--crosstool_top=$CROSSTOOL --host_crosstool_top=$HOST_CROSSTOOL"
     31 
     32 test -d $BASEDIR || (echo "Aborting: not at top-level build directory"; exit 1)
     33 
     34 function 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 
     44 function 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 
     54 rm -rf $TMPDIR
     55 mkdir -p $TMPDIR/jni
     56 
     57 build_basic_aar $TMPDIR
     58 build_arch arm64-v8a arm64-v8a $TMPDIR
     59 build_arch armeabi-v7a armeabi-v7a $TMPDIR
     60 build_arch x86 x86 $TMPDIR
     61 build_arch x86_64 x86_64 $TMPDIR
     62 
     63 AAR_FILE=`realpath tflite-${VERSION}.aar`
     64 (cd $TMPDIR && zip $AAR_FILE -r *)
     65 echo "New AAR file is $AAR_FILE"
     66 
     67