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: Gomobile gives error as "no exported names in the package" even though there are exported names #37961

Closed
purva-agarwal opened this issue Mar 20, 2020 · 5 comments

Comments

@purva-agarwal
Copy link

@purva-agarwal purva-agarwal 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.

@andybons andybons changed the title Gomobile gives error as "no exported names in the package" even though there are exported names x/mobile: Gomobile gives error as "no exported names in the package" even though there are exported names Mar 23, 2020
@gopherbot gopherbot added this to the Unreleased milestone Mar 23, 2020
@gopherbot gopherbot added the mobile label Mar 23, 2020
@andybons
Copy link
Member

@andybons andybons commented Mar 23, 2020

@andybons
Copy link
Member

@andybons andybons commented Mar 23, 2020

Duplicate of #37960

@andybons andybons marked this as a duplicate of #37960 Mar 23, 2020
@andybons andybons closed this Mar 23, 2020
@hanayashiki
Copy link

@hanayashiki hanayashiki commented Jun 27, 2020

for me, moving the entire project under $GOPATH/src solves the problem

@turtletramp
Copy link

@turtletramp turtletramp commented Aug 13, 2020

I think the error message is confusing because for me the issue was solved by initializing go modules with go mod init example.com/test

@Guang1234567
Copy link

@Guang1234567 Guang1234567 commented Aug 14, 2020

@turtletramp

thanks your reply.

@other

The detail for other newcome golang-android learner :

# make `gomobile` works fine with `go module` mode 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/libs/mobile.aar -target=android ./libmobile/src/go/mobile

# 5.1) my project structure

╰─> tree .
.
├── app
│   ├── libs
│   │   ├── 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")
}
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.