Skip to content

Commit

Permalink
android: we can actually build an gomobile aar now
Browse files Browse the repository at this point in the history
  • Loading branch information
d4l3k committed Sep 22, 2017
1 parent 2a44a3e commit 341bda7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
2 changes: 2 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.jar
*.aar
2 changes: 1 addition & 1 deletion android/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.PHONY: build
build:
gomobile bind -target=android github.com/luk-ai/lukai/bindable
gomobile bind -x -v -target=android -ldflags="-extldflags=-L$(shell pwd)" github.com/luk-ai/lukai/bindable
51 changes: 50 additions & 1 deletion android/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,53 @@
This is the home of the android client library. It's mostly generated bindings
via gomobile.

To build you need to install android-ndk-r12b and build [Tensorflow for android](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/android).
## Dependencies

* android-sdk (and related tools)
* android-ndk-r14b
* android-platform-23

To build you need to install android and build
[Tensorflow for android](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/android).
You'll need to use the
[luk-ai/tensorflow fork](https://github.com/luk-ai/tensorflow)
and then run the commands below. Other versions of the NDK may work, but are
untested.

Commands to build Android dependencies:

### Arm
```
sed -i 's/api_level=21,/api_level=15,/g' WORKSPACE
bazel build -c opt --verbose_failures //tensorflow/contrib/android:libtensorflow_inference.so --crosstool_top=//external:android/crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=armeabi-v7a
mkdir -p $GOPATH/pkg/gomobile/lib/arm
cp $ANDROID_NDK_HOME/platforms/android-15/arch-arm/usr/lib/* $GOPATH/pkg/gomobile/lib/arm/
cp -f bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so $GOPATH/pkg/gomobile/lib/arm/libtensorflow.so
```

### Arm64
```
sed -i 's/api_level=15,/api_level=21,/g' WORKSPACE
bazel build -c opt --verbose_failures //tensorflow/contrib/android:libtensorflow_inference.so --crosstool_top=//external:android/crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=arm64-v8a
mkdir -p $GOPATH/pkg/gomobile/lib/arm64
cp $ANDROID_NDK_HOME/platforms/android-21/arch-arm64/usr/lib/* $GOPATH/pkg/gomobile/lib/arm64/
cp -f bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so $GOPATH/pkg/gomobile/lib/arm64/libtensorflow.so
```

### x86
```
sed -i 's/api_level=21,/api_level=15,/g' WORKSPACE
bazel build -c opt --verbose_failures //tensorflow/contrib/android:libtensorflow_inference.so --crosstool_top=//external:android/crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=x86
mkdir -p $GOPATH/pkg/gomobile/lib/386
cp $ANDROID_NDK_HOME/platforms/android-15/arch-x86/usr/lib/* $GOPATH/pkg/gomobile/lib/386/
cp -f bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so $GOPATH/pkg/gomobile/lib/386/libtensorflow.so
```

### x86_64
```
sed -i 's/api_level=15,/api_level=21,/g' WORKSPACE
bazel build -c opt --verbose_failures //tensorflow/contrib/android:libtensorflow_inference.so --crosstool_top=//external:android/crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=x86_64
mkdir -p $GOPATH/pkg/gomobile/lib/amd64
cp $ANDROID_NDK_HOME/platforms/android-21/arch-x86_64/usr/lib/* $GOPATH/pkg/gomobile/lib/amd64/
cp -f bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so $GOPATH/pkg/gomobile/lib/amd64/libtensorflow.so
```

0 comments on commit 341bda7

Please sign in to comment.