golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.07k stars 17.68k forks source link

x/mobile: init fails when running make_standalone_toolchain.py #27265

Closed pieterclaerhout closed 6 years ago

pieterclaerhout commented 6 years ago

What version of Go are you using (go version)?

go version go1.11 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/pclaerhout/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/pclaerhout/gopath"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10.3/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/hb/92v_9tgd5g5f2npqwk4ztfrh0000gq/T/go-build451235970=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I'm trying to install gomobile, but the init step fails.

$ go install golang.org/x/mobile/cmd/gomobile/
$ bin/gomobile clean
$ bin/gomobile init -ndk /Library/Android/sdk/ndk-bundle
bin/gomobile: /Library/Android/sdk/ndk-bundle/prebuilt/darwin-x86_64/bin/python2.7 build/tools/make_standalone_toolchain.py --arch=arm --api=15 --install-dir=/Users/pclaerhout/Documents/shp-projects/TwixlPublisher/git/distribution-platform/pkg/gomobile/ndk-toolchains/arm failed: exit status 1
15 is less than minimum platform for arm (16)

The Android SDK version which I have installed is 18.0.4951716 rc2.

What did you expect to see?

I expected to see no error message at all.

What did you see instead?

From what I can see, the arguments specified to run the Android NDK make_standalone_toolchain.py are incorrect. When making the toolchain for either arm or x86 requires a minimum api level of 16, not 15. This can easily be fixed by updating the following file:

golang.org/x/mobile/cmd/gomobile/env.go

There, the NDK config should be updated from:

var ndk = ndkConfig{
    "arm": {
        arch:       "arm",
        abi:        "armeabi-v7a",
        platform:   "android-15",
        gcc:        "arm-linux-androideabi-4.9",
        toolPrefix: "arm-linux-androideabi",
    },
    "arm64": {
        arch:       "arm64",
        abi:        "arm64-v8a",
        platform:   "android-21",
        gcc:        "aarch64-linux-android-4.9",
        toolPrefix: "aarch64-linux-android",
    },

    "386": {
        arch:       "x86",
        abi:        "x86",
        platform:   "android-15",
        gcc:        "x86-4.9",
        toolPrefix: "i686-linux-android",
    },
    "amd64": {
        arch:       "x86_64",
        abi:        "x86_64",
        platform:   "android-21",
        gcc:        "x86_64-4.9",
        toolPrefix: "x86_64-linux-android",
    },
}

to

var ndk = ndkConfig{
    "arm": {
        arch:       "arm",
        abi:        "armeabi-v7a",
        platform:   "android-16",
        gcc:        "arm-linux-androideabi-4.9",
        toolPrefix: "arm-linux-androideabi",
    },
    "arm64": {
        arch:       "arm64",
        abi:        "arm64-v8a",
        platform:   "android-21",
        gcc:        "aarch64-linux-android-4.9",
        toolPrefix: "aarch64-linux-android",
    },

    "386": {
        arch:       "x86",
        abi:        "x86",
        platform:   "android-16",
        gcc:        "x86-4.9",
        toolPrefix: "i686-linux-android",
    },
    "amd64": {
        arch:       "x86_64",
        abi:        "x86_64",
        platform:   "android-21",
        gcc:        "x86_64-4.9",
        toolPrefix: "x86_64-linux-android",
    },
}

After patching this file manually, rebuilding the gomobile command, I was able to succesfully run bin/gomobile init -ndk /Library/Android/sdk/ndk-bundle.

willauld commented 6 years ago

I believe I am having the same problem. I've updated the env.go file but how do you rebuild gomobile at this point? I'm working on win10.

pieterclaerhout commented 6 years ago

Running the gomobile init -ndk ... command should do the rebuild.

willauld commented 6 years ago

Thanks.

Given this I tried the following and pretty much get the same result as before. So, maybe I'm still doing something wrong or my problem is different. Does the following command look correct? I've trimmed the middle of its output. Thanks, Will

powershell> gomobile init -ndk C:\Users\auld\AppData\Local\Android\sdk1\ndk-bundle -v

Installing std for android/arm.

runtime/cgo

runtime/cgo

C:\Users\auld\AppData\Local\Android\sdk1\ndk-bundle\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: cannot open crtbegin_dynamic.o: No such file or directory C:\Users\auld\AppData\Local\Android\sdk1\ndk-bundle\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: cannot open crtend_android.o: No such file or directory ... C:\Users\auld\AppData\Local\Temp\go-build552291650\b081_x010.o:gcc_util.c:function x_cgo_thread_start: error: undefined reference to '__sF' clang.exe: error: linker command failed with exit code 1 (use -v to see invocation) C:\home\auld\godev\bin\gomobile.exe: go install -gcflags=-shared -ldflags=-shared -pkgdir=C:\home\auld\godev\pkg\gomobile/pkg_android_arm -v std failed: exit status 2

pieterclaerhout commented 6 years ago

From what I can see, your problem seems to be different.

In your case it seems that the actual compilation of the Android native stuff fails:


C:\Users\auld\AppData\Local\Temp\go-build552291650\b081_x010.o:gcc_util.c:function x_cgo_thread_start: error: undefined reference to '__sF'
clang.exe: error: linker command failed with exit code 1 (use -v to see invocation)
willauld commented 6 years ago

OK, well thanks for your help, I'll keep digging.

willauld commented 6 years ago

OK here is what works for me (I'm on Win10):

eliasnaur commented 6 years ago

I believe this is fixed in the latest gomobile version. Can you confirm?

pieterclaerhout commented 6 years ago

Yes, it seems to be working fine now.

willauld commented 6 years ago

OK, I renamed my GOPATH/src/x to xold

$ go get golang.org/x/mobile/cmd/gomobile $ gomobile init $ gomobile version gomobile version +92f3b9c Wed Oct 10 16:34:05 2018 +0000 (android); androidSDK=C:\Users\auld\AppData\Local\Android\sdk1\platforms\android-27

Then I rebuilt / bind my go lib and built my android app and all works fine

Thanks, Wil