Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pieterclaerhout opened this issue Aug 27, 2018 · 9 comments
Closed

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

pieterclaerhout opened this issue Aug 27, 2018 · 9 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@pieterclaerhout
Copy link

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.

@FiloSottile FiloSottile changed the title gomobile init fails when running make_standalone_toolchain.py x/mobile: init fails when running make_standalone_toolchain.py Aug 30, 2018
@gopherbot gopherbot added this to the Unreleased milestone Aug 30, 2018
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Aug 30, 2018
@FiloSottile FiloSottile added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 30, 2018
@willauld
Copy link

willauld commented Oct 3, 2018

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
Copy link
Author

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

@willauld
Copy link

willauld commented Oct 3, 2018

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
Copy link
Author

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
Copy link

willauld commented Oct 4, 2018

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

@willauld
Copy link

willauld commented Oct 4, 2018

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

  • Make pieterclaerhout's change to env.go in $GOPATH/src\golang.org\x\mobile\cmd\gomobile\
  • In $GOPATH/src\golang.org\x\mobile\cmd\gomobile\ issue the command:
    go install
    to build and install the new version of gomible.exe
  • gomobile init -ndk C:\Users\auld\AppData\Local\Android\sdk1\ndk-bundle
    ndk path will be specific to the person and their android environment
  • use gomobile as you normally would

@eliasnaur
Copy link
Contributor

eliasnaur commented Oct 10, 2018

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

@pieterclaerhout
Copy link
Author

Yes, it seems to be working fine now.

@willauld
Copy link

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

@golang golang locked and limited conversation to collaborators Oct 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants