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

Closed
rohankeskar19 opened this issue Mar 20, 2020 · 13 comments
Closed

x/mobile: update documentation for module mode #37960

rohankeskar19 opened this issue Mar 20, 2020 · 13 comments
Labels
Documentation FrozenDueToAge help wanted mobile Android, iOS, and x/mobile modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@rohankeskar19
Copy link

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

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

It works for another project with GO111MODULE=off

@OneOfOne
Copy link
Contributor

#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 Android, iOS, and x/mobile label Mar 23, 2020
@andybons andybons added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed mobile Android, iOS, and x/mobile labels Mar 23, 2020
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Mar 23, 2020
@andybons
Copy link
Member

@hyangah @bcmills (for potential modules issue)

@bcmills
Copy link
Contributor

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

@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 23, 2020
@rohankeskar19
Copy link
Author

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

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.

@bcmills bcmills added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Mar 23, 2020
@rohankeskar19
Copy link
Author

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

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

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 bcmills added Documentation modules help wanted and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Mar 24, 2020
@bcmills
Copy link
Contributor

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.

@Guang1234567
Copy link

Guang1234567 commented Aug 13, 2020

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

# make `gomobile` works fine with `go module` than the old `$GOPATH` mode.

# 0) 
install   go 1.14

# 1) unset env var for shell
unset GO111MODULE
unset GOMOD 

# 2) set `go module`  to `auto` for the best compatibility
go env -w GO111MODULE=auto

# 3) restart your terminal for safe

# 4) create `go module` configuration file: `go.mod` and `go.sum`
go mod init demo_android_go_mobile

# 5) build your demo go library
gomobile bind -v  -o app/lib/mobile.aar -target=android ./libmobile/src/go/mobile

# 5.1) my project structure

╰─> tree .
.
├── app
│   ├── lib
│   │   ├── mobile-sources.jar
│   │   └── mobile.aar
│   └── src
│       └── java
├── go.mod
├── go.sum
└── libmobile
    └── src
        └── go
            └── mobile
                └── mobile.go

# 5.2) file `mobile.go`

package mobile

import "fmt"

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

func SayHelloWithParams(name string) {
      fmt.Println("Hello", name)
}

func SayHelloWithParamsAndReturn(name string) string {
      return "Hello" + name
}

func SayHelloWithParamsAndReturnAndException(name string) (string, 
error) {
      return "Hello" + name, fmt.Errorf("some error")
}

@changkun
Copy link
Member

Module mode is documented in http://golang.org/wiki/Mobile. Close as this issue is outdated.

@golang golang locked and limited conversation to collaborators Feb 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge help wanted mobile Android, iOS, and x/mobile modules 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

8 participants