6

I'm trying to build an android-go example in ubuntu 16 using ../build-android.sh but I get an error,

# runtime/cgo
_cgo_export.c:2:20: fatal error: stdlib.h: No such file or directory
 #include <stdlib.h>
                    ^

https://github.com/xlab/android-go/tree/master/examples/minimal

Does anyone have any suggestions? I've already double checked lib6c header libraries.

The full build log is

../build-android.sh 
+ : 26
+ : /home/jsper/Downloads
+ : /home/jsper/Downloads/ndk-bundle
+ export ANDROID_API ANDROID_HOME ANDROID_NDK_HOME
+ /home/jsper/Downloads/tools/bin/sdkmanager --update
[=======================================] 100% Computing updates...             
+ /home/jsper/Downloads/tools/bin/sdkmanager ndk-bundle
[=======================================] 100% Computing updates...             
+ rm -rf android/toolchain
+ /home/jsper/Downloads/ndk-bundle/build/tools/make_standalone_toolchain.py --install-dir=android/toolchain --arch=arm --api=26 --stl=libc++
+ rm -rf android/toolchain/sysroot/usr
+ cp -r /home/jsper/Downloads/ndk-bundle/platforms/android-26/arch-arm/usr android/toolchain/sysroot/usr
+ mkdir -p android/app/src/main/jniLibs/armeabi-v7a
+ GOOS=android
+ GOARCH=arm
+ GOARM=7
+ go get -d
+ CC=/home/jsper/go/src/github.com/xlab/android-go/examples/minimal/android/toolchain/bin/arm-linux-androideabi-gcc
+ CXX=/home/jsper/go/src/github.com/xlab/android-go/examples/minimal/android/toolchain/bin/arm-linux-androideabi-g++
+ CGO_ENABLED=1
+ CGO_CFLAGS=-march=armv7-a
+ GOOS=android
+ GOARCH=arm
+ GOARM=7
+ go build -i -buildmode=c-shared -o android/app/src/main/jniLibs/armeabi-v7a/libgomain.so
# runtime/cgo
_cgo_export.c:2:20: fatal error: stdlib.h: No such file or directory
 #include <stdlib.h>
                    ^
compilation terminated.
shwick
  • 4,277
  • 6
  • 21
  • 28
  • Make sure you have the `$ANDROID_HOME` environment variable set to the Android SDK root. default is `$HOME/android-sdk` – vardius Mar 06 '18 at 02:51
  • Look at the comments of https://stackoverflow.com/q/47944741/6309: are you using the right NDK? (https://github.com/xlab/android-go#android-) – VonC Mar 06 '18 at 07:55
  • I tried ANDROID_API=23 ../build-android.sh, didn't work also tried downloading ndk bundle 10e pointing to it and that didn't work – shwick Mar 06 '18 at 20:31

3 Answers3

13

Did you install the build-essential package? As I have read, the lib is sometimes not installed properly. So a reinstall could help.

Please try:

sudo apt-get update
sudo apt-get install build-essential
mbuechmann
  • 5,413
  • 5
  • 27
  • 40
  • thanks but I'm getting build-essential is already the newest version (12.1ubuntu2). – shwick Feb 16 '18 at 12:16
  • It could be that the package is not installed properly. In this case you could reinstall it with `sudo apt-get install --reinstall build-essential`. Or you could remove it and install it again. Could you try that out? – mbuechmann Feb 16 '18 at 13:52
  • Tried reinstall build, remove build, install build, unfortunately didn't work all same error – shwick Feb 16 '18 at 14:12
4

The https://github.com/xlab/android-go/tree/master/examples/minimal uses:

compileSdkVersion = 25
buildToolsVersion = '25.0.0'

in https://github.com/xlab/android-go/blob/master/examples/minimal/android/app/build.gradle

You are using 26

/home/jsper/Downloads/ndk-bundle/build/tools/make_standalone_toolchain.py --install-dir=android/toolchain --arch=arm --api=26 --stl=libc++

you need to install NDK with the correct version

HaBaLeS
  • 1,809
  • 3
  • 16
  • 26
  • I tried running ANDROID_API=25 ../build-android.sh and am getting "could not find android-25" so I installed android-25 with sdkmanager but that didn't fix it, it didn't install it to ndk folder so now I'm trying to find how to install ndk version 25, but it doesn't exist for the ndk im using – shwick Mar 07 '18 at 15:46
1

I got the same issue, and i fixed it by :

set CGO_LDFLAGS=--sysroot=%NDK_ROOT%/platforms/android-21/arch-arm
set CC=arm-linux-androideabi-gcc --sysroot=%NDK_ROOT%\platforms\android-21\arch-arm
ejin
  • 13
  • 3