Compile InfluxDB v2.x for Android

Hi all,

i want to run InfluxDB on Android. To be more specific I’ve got an app where InfluxDB should be integrated. Android/Java got an interface called JNI, from which you can call native functions from shared objects (*.so). I wrote a JNI-Wrapper in C which can call the main function in main.go.

What I’ve done so far:

  1. changed/added the GNUMakefile with
export GOOS=android
export GOARCH=arm64
export CGO_ENABLED=1
export CC=/opt/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android33-clang
export CXX=/opt/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android33-clang++
  1. changed/added the main.go
import "C"

import (
[..]
)

var (
[..]
)

//export mainWrapper
func mainWrapper() int {
	main()
	return 0
}
  1. changed the build command in GNUMakefile to
$(GO_BUILD) -o $@.so -buildmode=c-shared ./cmd/$(shell basename "$@")

And then i get the following errors where I’m currently stuck

env GO111MODULE=on go install -tags 'sqlite_foreign_keys,sqlite_json,assets,noasm' -ldflags " -X main.commit=24a2b621ea -X main.version=v2.6.0" google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1
env GO111MODULE=on go install -tags 'sqlite_foreign_keys,sqlite_json,assets,noasm' -ldflags " -X main.commit=24a2b621ea -X main.version=v2.6.0" github.com/benbjohnson/tmpl
env GO111MODULE=on go install -tags 'sqlite_foreign_keys,sqlite_json,assets,noasm' -ldflags " -X main.commit=24a2b621ea -X main.version=v2.6.0" golang.org/x/tools/cmd/stringer
env GO111MODULE=on go install -tags 'sqlite_foreign_keys,sqlite_json,assets,noasm' -ldflags " -X main.commit=24a2b621ea -X main.version=v2.6.0" golang.org/x/tools/cmd/goimports
go generate -tags 'sqlite_foreign_keys,sqlite_json,assets,noasm' ./influxql/... ./models/... ./pkg/... ./storage/... ./tsdb/... ./v1/...
open types.tmpldata: no such file or directory
exitcode=2exit status 2
storage/flux/table.go:3: running "env": exit status 1
open array_cursor.gen.go.tmpldata: no such file or directory
exitcode=2exit status 2
storage/reads/gen.go:3: running "env": exit status 1
open arrayvalues.gen.go.tmpldata: no such file or directory
exitcode=2exit status 2
tsdb/cursors/gen.go:3: running "env": exit status 1
open iterator.gen.go.tmpldata: no such file or directory
exitcode=2exit status 2
tsdb/engine/tsm1/engine.go:42: running "go": exit status 1
make: *** [GNUmakefile:149: generate-sources] Error 1

So in the end i want a *.so file and a *.h from the makefile which i can then later link with the C JNI-Wrapper file to create a new *.so which can be called from the app. I know it’s a lot to ask, but if someone has a hint or anything else I would be more than grateful.

I’ve also already tried building InfluxDB on a arm64 machine unfortunately Google doesn’t offer the android-toolchain for arm64 therefore InfluxDB gets build with non android libs.