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/cmd/gomobile: gomobile bind doesn't recognize android build tag #24856
Comments
Building for iOS also fails even with |
Interestingly, adding
|
git bisect says golang/mobile@4600df5 is the cause |
CC @eliasnaur |
Yes, CL 99316 that you refer to changed gobind to be able to generate standalone bindings and changed gomobile to use that instead of its own complicated binding generator. That main benefit is that you can now avoid gomobile altogether for special needs. From the CL description: "This greatly simplifies gomobile bind, but also paves the way to skip
" Another benefit is you can now run To accomplish that without needing the Android and Xcode SDKs, gobind has to be platform neutral and as such will generate bindings without any particular GOOS or GOARCH set. If you need to vary the API, use the -tags flag to gomobile or gobind. In summary, The reason your !android example fails is that while bindings themselves are generated without GOOS/GOARCH set, they are set when gomobile builds the libraries for pkg.aar. So gobind will generate bindings for Foo, while gomobile will fail to find any Go files because GOOS=android. In summary, your exported API must be platform independent (or you can use tags to select variants), but your implementation can and will depend on GOOS/GOARCH. |
Thank you for elaborating! I'm still not sure the implementation detail, but what I needed to do is to make the lib buildable both on mobile and non-mobile? |
In further thought, your use case might still be possible. Could you try https://golang.org/cl/99777? |
Change https://golang.org/cl/99777 mentions this issue: |
Yeah, with that patch, I've succeeded the experiment in the first comment:
|
CL 99316 changed gobind to be platform independent, so standalone bindings could be generated without having the Android and Xcode SDKs installed. However, bindings that does depend on GOOS for its exported API, in particular go source files that use Cgo now only works if the exported API is extracted to platform independent files. By switching to use the source importer, importer.For("source", nil), gobind can type check the bound packages even in the presence of Cgo. The source importer in Go 1.9 and 1.10 has problems with relative imports and imports from testdata directories (issues 23092 and 24392), but works from Go 1.10.1 on. Fixes golang/go#24856 Change-Id: Icb18dce15325b7d4e58cabc1181051bc6269fc1f Reviewed-on: https://go-review.googlesource.com/99777 Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
CL 99316 changed gobind to be platform independent, so standalone bindings could be generated without having the Android and Xcode SDKs installed. However, bindings that does depend on GOOS for its exported API, in particular go source files that use Cgo now only works if the exported API is extracted to platform independent files. By switching to use the source importer, importer.For("source", nil), gobind can type check the bound packages even in the presence of Cgo. The source importer in Go 1.9 and 1.10 has problems with relative imports and imports from testdata directories (issues 23092 and 24392), but works from Go 1.10.1 on. Fixes golang/go#24856 Change-Id: Icb18dce15325b7d4e58cabc1181051bc6269fc1f Reviewed-on: https://go-review.googlesource.com/99777 Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?What did you do?
What did you expect to see?
Success to build
What did you see instead?
The text was updated successfully, but these errors were encountered: