golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.04k stars 17.67k forks source link

x/mobile: reverse binding not working anymore? #50608

Open timcooijmans opened 2 years ago

timcooijmans commented 2 years ago

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

$ go version
go version go1.17.6 linux/amd64

$ gomobile version
golang.org/x/mobile/cmd/gomobile@latest

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
 go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/root/sdk/go1.17.6"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/root/sdk/go1.17.6/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/build2/go.mod"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2412464046=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Create a file in a module that uses reverse binding:

package gomobiletest

import (
        "log"
        "Java/android/content"
)

func Test(androidctx content.Context)  {
        apkPath := androidctx.GetPackageResourcePath()
        log.Println(appPath)
}

and run

gomobile bind

What did you expect to see?

A successful compile

What did you see instead?

A successful compile with the method ignored.

heschi commented 2 years ago

cc @hyangah

gtf35 commented 2 years ago

There was a demo before ( https://github.com/golang/mobile/tree/37c5126484a7fd3b7987809e9f68f1ba4e7a5341/example/reverse), but it was build with gradle plugin,

It was removed because it couldn't have stable access to the xml layout in Android, but more often, we just want to call some Java methods (for some reasons, I have to do this, such as get android id in go)

Android Studio support language C , but not support Golang, IDEA support Golang, but not support C :(

So I don't want to use CGo(jni) to done it

I'm out of options now

sll00 commented 1 year ago

I also need this, and was dishearted to see it ghosted.