xlab / android-go

The android-go project provides a platform for writing native Android apps in Go programming language.
https://developer.android.com/ndk/index.html
MIT License
1.07k stars 80 forks source link

Can't build example project #3

Open udhos opened 7 years ago

udhos commented 7 years ago

I am reading guidelines from: https://github.com/xlab/android-go/tree/master/example

I hit this:

everton@homeubu:~/go/src/github.com/xlab/android-go/example/android$ make project
# (optional) android list targets
android update project --target android-23 --name GolangExample --path .
make: android: Command not found
Makefile:12: recipe for target 'project' failed
make: *** [project] Error 127
everton@homeubu:~/go/src/github.com/xlab/android-go/example/android$

I noticed the need for the 'android' tool. However:

everton@homeubu:~/go/src/github.com/xlab/android-go/example/android$ ~/Android/Sdk/tools/android 
The android command is no longer available.
For manual SDK and AVD management, please use Android Studio.
For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager
everton@homeubu:~/go/src/github.com/xlab/android-go/example/android$ 

How can I get past such a point?

xlab commented 7 years ago

Yeah that's pretty sad. The known workaround is to get the previous version of the sdk tools, see https://github.com/NativeScript/nativescript-cli/issues/2583#issuecomment-283712933

This was the latest March release of SDK tools that removed the android utility without providing a fallback. https://developer.android.com/studio/releases/sdk-tools.html

xlab commented 7 years ago

@udhos https://github.com/xlab/android-go/tree/master/cmd/android-project

Example: https://github.com/xlab/android-go/blob/master/example/android/Makefile#L13

longtq6195-seta-international commented 7 years ago

longtran@longtran:~/go/src/github.com/xlab/android-go/example-egl$ make mkdir -p android/jni/lib CC="/home/longtran/go/src/github.com/xlab/android-go/example-egl/toolchain/bin/arm-linux-androideabi-gcc" \ CXX="/home/longtran/go/src/github.com/xlab/android-go/example-egl/toolchain/bin/arm-linux-androideabi-g++" \ CGO_CFLAGS="-march=armv7-a" \ GOOS=android \ GOARCH=arm \ GOARM=7 \ CGO_ENABLED=1 \ go build -buildmode=c-shared -o android/jni/lib/libexample.so

runtime/cgo

/tmp/go-build017993175/runtime/cgo/_obj/gcc_android.o:gcc_android.c:function fatalf: error: undefined reference to 'stderr' /tmp/go-build017993175/runtime/cgo/_obj/gcc_libinit.o:gcc_libinit.c:function x_cgo_sys_thread_create: error: undefined reference to 'stderr' /tmp/go-build017993175/runtime/cgo/_obj/gcc_util.o:gcc_util.c:function x_cgo_thread_start: error: undefined reference to 'stderr' collect2: error: ld returned 1 exit status Makefile:13: recipe for target 'build' failed make: *** [build] Error 2

xlab commented 7 years ago

@longtq6195-seta-international unfortunately I can't reproduce, tried both Go 1.8.1 and 1.9beta2. I'm using OS X, so this may be different from your setup. Probably a bug in Go compiler on this platform

tirithen commented 7 years ago

I'm getting similar errors:

➜  example git:(master) ✗ make
mkdir -p android/jni/lib
CC="/home/tirithen/.go/src/github.com/xlab/android-go/example/toolchain/bin/arm-linux-androideabi-gcc" \
CXX="/home/tirithen/.go/src/github.com/xlab/android-go/example/toolchain/bin/arm-linux-androideabi-g++" \
CGO_CFLAGS="-march=armv7-a" \
GOOS=android \
GOARCH=arm \
GOARM=7 \
CGO_ENABLED=1 \
go build -buildmode=c-shared -o android/jni/lib/libexample.so
# runtime/cgo
/tmp/go-build521705144/runtime/cgo/_obj/gcc_android.o:gcc_android.c:function fatalf: error: undefined reference to 'stderr'
/tmp/go-build521705144/runtime/cgo/_obj/gcc_libinit.o:gcc_libinit.c:function x_cgo_sys_thread_create: error: undefined reference to 'stderr'
/tmp/go-build521705144/runtime/cgo/_obj/gcc_util.o:gcc_util.c:function x_cgo_thread_start: error: undefined reference to 'stderr'
collect2: error: ld returned 1 exit status
make: *** [Makefile:14: build] Fel 2

Go version

➜  example git:(master) ✗ go version
go version go1.8.3 linux/amd64

Oh, and my machine is running Arch Linux with the Android packages installed through AUR

kitech commented 7 years ago

try this, https://github.com/android-ndk/ndk/issues/445#issuecomment-313322546

dudochkin-victor commented 7 years ago

CFLAGS=-D__ANDROID_API__=$API worked for me. But there are other problem.

make mkdir -p android/jni/lib CC="/mnt/data/GO/src/github.com/golang-ui/nuklear/cmd/nk-android/toolchain/bin/arm-linux-androideabi-gcc" \ CXX="/mnt/data/GO/src/github.com/golang-ui/nuklear/cmd/nk-android/toolchain/bin/arm-linux-androideabi-g++" \ CGO_CFLAGS="-march=armv7-a -std=c99 -D__ANDROID_API__=21" \ GOOS=android \ GOARCH=arm \ GOARM=7 \ CGO_ENABLED=1 \ go build -tags gles3 -buildmode=c-shared -o android/jni/lib/libnkactivity.so

github.com/xlab/android-go/android In file included from ../../../../xlab/android-go/android/types.go:25:0: /mnt/data/GO/src/github.com/golang-ui/nuklear/cmd/nk-android/toolchain/sysroot/usr/include/android/tts.h:99:8: error: expected identifier or '(' before string constant extern "C" android_tts_engine_t *getTtsEngine(); ^ make: *** [Makefile:15: build] Error 2

I fixed it by removing any "#include <android/tts.h>" lines. So the libnkactivity.so compiled.