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: update documentation for module mode #37960

Open
rohankeskar19 opened this issue Mar 20, 2020 · 11 comments
Open

x/mobile: update documentation for module mode #37960

rohankeskar19 opened this issue Mar 20, 2020 · 11 comments

Comments

@rohankeskar19
Copy link

@rohankeskar19 rohankeskar19 commented Mar 20, 2020

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

go version go1.13.6 windows/amd64

$ go version

Does this issue reproduce with the latest release?

Yes

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

set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Rohan\AppData\Local\go-build
set GOENV=C:\Users\Rohan\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Projects\GoProjects;
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Rohan\AppData\Local\Temp\go-build891854990=/tmp/go-build -gno-record-gcc-switches```
<details><summary><code>go env</code> Output</summary><br><pre>
$ go env

</pre></details>

### What did you do?
I'm trying to generate android library using gomobile, I have this code given below, I want to generate an android library from it but Gomobile gives me error as it can't find any exported names but I think ```GetKeys``` should be considered  as an exported name

package whisper

import (
"context"
"fmt"
"log"

"github.com/ethereum/go-ethereum/whisper/shhclient"

)

func GetKeys() {
client, err := shhclient.Dial("ws://10.0.2.2:8546")
if err != nil {
log.Fatal(err)
}
keyID, err := client.NewKeyPair(context.Background())
if err != nil {
log.Fatal(err)
}

fmt.Println(keyID) // 0ec5cfe4e215239756054992dbc2e10f011db1cdfc88b9ba6301e2f9ea1b58d2
publicKey, err := client.PublicKey(context.Background(), keyID)

if err != nil {
	log.Fatal(err)
}

fmt.Println(publicKey)

}

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
-->



### What did you expect to see?
Android library generated

### What did you see instead?

gomobile: C:\Users\Rohan\go\bin\gobind.exe -lang=go,java -outdir=C:\Users\Rohan\AppData\Local\Temp\gomobile-work-181241247 github.com/rohankeskar19/whisper failed: exit status 1
no exported names in the package "github.com/rohankeskar19/whisper"
no exported names in the package "github.com/rohankeskar19/whisper"
no exported names in the package "github.com/rohankeskar19/whisper"
no exported names in the package "github.com/rohankeskar19/whisper"
unable to import bind/java: go [-e -json -compiled=true -test=false -export=false -deps=false -find=true -- golang.org/x/mobile/bind/java]: exit status 2: go: finding golang.org/x/mobile latest

runtime/cgo

gcc_android.c:6:25: fatal error: android/log.h: No such file or directory
#include <android/log.h>
^
compilation terminated.

@OneOfOne

This comment has been minimized.

Copy link
Contributor

@OneOfOne OneOfOne commented Mar 20, 2020

gcc_android.c:6:25: fatal error: android/log.h: No such file or directory I'd say your android sdk isn't installed properly or in the wrong path.

@rohankeskar19

This comment has been minimized.

Copy link
Author

@rohankeskar19 rohankeskar19 commented Mar 20, 2020

It works for another project with GO111MODULE=off

@OneOfOne

This comment has been minimized.

Copy link
Contributor

@OneOfOne OneOfOne commented Mar 20, 2020

#27234 or #37902 might be related.

@andybons andybons changed the title Gomobile gives "no exported names in the package "github.com/rohankeskar19/whisper"" x/mobile: Gomobile gives "no exported names in the package "github.com/rohankeskar19/whisper"" Mar 23, 2020
@gopherbot gopherbot added this to the Unreleased milestone Mar 23, 2020
@gopherbot gopherbot added the mobile label Mar 23, 2020
@andybons andybons added NeedsInvestigation and removed mobile labels Mar 23, 2020
@gopherbot gopherbot added the mobile label Mar 23, 2020
@andybons

This comment has been minimized.

Copy link
Member

@andybons andybons commented Mar 23, 2020

@hyangah @bcmills (for potential modules issue)

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Mar 23, 2020

https://github.com/rohankeskar19/whisper shows an empty repo, so that error message seems correct.

set GOMOD=NUL in the go env output indicates that you are working outside of a module, so commands will resolve the latest github.com/rohankeskar19/whisper from upstream (which is an empty repo). Most likely this would not compile at all using go 1.14 or newer.

See https://blog.golang.org/using-go-modules and https://golang.org/doc/code.html for tutorials on setting up a new Go project using modules. I'm not sure if there is any gobind-specific documentation on working with modules.

CC @hajimehoshi @hyangah @steeve

@rohankeskar19

This comment has been minimized.

Copy link
Author

@rohankeskar19 rohankeskar19 commented Mar 23, 2020

https://github.com/rohankeskar19/whisper shows an empty repo, so that error message seems correct.

set GOMOD=NUL in the go env output indicates that you are working outside of a module, so commands will resolve the latest github.com/rohankeskar19/whisper from upstream (which is an empty repo). Most likely this would not compile at all using go 1.14 or newer.

See https://blog.golang.org/using-go-modules and https://golang.org/doc/code.html for tutorials on setting up a new Go project using modules. I'm not sure if there is any gobind-specific documentation on working with modules.

CC @hajimehoshi @hyangah @steeve

I tried to generate bindings from my local environment, and this error occured before creating the repo, I was able to generate bindings after locally downloading all the packages required in the go-ethereum package and setting GO111MODULE=off

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Mar 23, 2020

Your go env output indicates set GO111MODULE=on, meaning that you at some point explicitly enabled module mode.

In module mode, your dependencies are determined by the main module's go.mod file, not what is in your local GOPATH.

@rohankeskar19

This comment has been minimized.

Copy link
Author

@rohankeskar19 rohankeskar19 commented Mar 23, 2020

Your go env output indicates set GO111MODULE=on, meaning that you at some point explicitly enabled module mode.

In module mode, your dependencies are determined by the main module's go.mod file, not what is in your local GOPATH.

Yeah, I know I disabled it later, And even for an package which contains a simple program as

package test

import (
	"fmt"
	
)

func SayHello() {
	fmt.Println("Inside Hello")
	
}

I get the same error as above when GO111MODULE is set on, However when it is off It seems to work fine

@hyangah

This comment has been minimized.

Copy link
Contributor

@hyangah hyangah commented Mar 23, 2020

When working with a local module, run gomobile bind in the main module where it can find the local module, so the go build system can find the local module.

I successfully ran gomobile bind in modules mode

$ tree
.
├── foo.go
├── go.mod
└── go.sum

$ cat foo.go
package foo

import (
	"fmt"
	
)

func SayHello() {
	fmt.Println("Inside Hello")
	
}

$ gomobile bind -target=ios 
$ grep SayHello ./Foo.framework/*
Binary file ./Foo.framework/Foo matches
...
@rohankeskar19

This comment has been minimized.

Copy link
Author

@rohankeskar19 rohankeskar19 commented Mar 24, 2020

When working with a local module, run gomobile bind in the main module where it can find the local module, so the go build system can find the local module.

I successfully ran gomobile bind in modules mode

$ tree
.
├── foo.go
├── go.mod
└── go.sum

$ cat foo.go
package foo

import (
	"fmt"
	
)

func SayHello() {
	fmt.Println("Inside Hello")
	
}

$ gomobile bind -target=ios 
$ grep SayHello ./Foo.framework/*
Binary file ./Foo.framework/Foo matches
...

Ok, It works now! Thanks.

@bcmills bcmills changed the title x/mobile: Gomobile gives "no exported names in the package "github.com/rohankeskar19/whisper"" x/mobile: update documentation for module mode Mar 24, 2020
@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Mar 24, 2020

Seems like we need to update the gomobile documentation (http://golang.org/wiki/Mobile?) to clarify how to use it in module mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.