-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: reverse binding testdata build failed #62142
Comments
both java and xcode is installed
|
(CC @golang/android @golang/ios) |
It may be related to go module feature. The reverse binding procedure can be symplified as following:
However, when go module is enabled(step 4 is generated), step 3 is useless because gopath will be ignored so the generated sources can only be referred to |
This means that the whole reverse binding feature is broken with go modules? Is there any workaround? |
I created a test.go file with: package gomobiletest
import (
"Java/java/util/jar/JarFile"
)
func ManifestName() string {
return JarFile.MANIFEST_NAME
} and go.mod:
Then ran Output:
Temp file list:
We can see files such as Generated
It seems this could be fixed easily enough by having extra replaces/requires added for each imported Java package with the appropriate path? Or just something for "Java" ? |
This causes build to work, which is good for me: diff --git a/cmd/gomobile/bind.go b/cmd/gomobile/bind.go
index fc9f756..a05001e 100644
--- a/cmd/gomobile/bind.go
+++ b/cmd/gomobile/bind.go
@@ -226,7 +226,7 @@ func packagesConfig(t targetInfo) *packages.Config {
}
// getModuleVersions returns a module information at the directory src.
-func getModuleVersions(targetPlatform string, targetArch string, src string) (*modfile.File, error) {
+func getModuleVersions(targetPlatform string, targetArch string, src string, dir string) (*modfile.File, error) {
cmd := exec.Command("go", "list")
cmd.Env = append(os.Environ(), "GOOS="+platformOS(targetPlatform), "GOARCH="+targetArch)
@@ -289,6 +289,17 @@ func getModuleVersions(targetPlatform string, targetArch string, src string) (*m
}
}
+ for _, subdir := range []string{"Java", "ObjC"} {
+ if _, err := os.Stat(filepath.Join(dir, subdir)); err == nil {
+ if err := f.AddReplace(subdir, "", filepath.Join(dir, subdir), ""); err != nil {
+ return nil, err
+ }
+ if err := os.WriteFile(filepath.Join(dir, subdir, "go.mod"), []byte("module "+subdir+"\n"), 0644); err != nil {
+ return nil, err
+ }
+ }
+ }
+
v, err := ensureGoVersion()
if err != nil {
return nil, err
@@ -316,7 +327,7 @@ func writeGoMod(dir, targetPlatform, targetArch string) error {
}
return writeFile(filepath.Join(dir, "go.mod"), func(w io.Writer) error {
- f, err := getModuleVersions(targetPlatform, targetArch, ".")
+ f, err := getModuleVersions(targetPlatform, targetArch, ".", dir)
if err != nil {
return err
}
|
Actually it looks like this isn't fixed yet since there's a new error (but that may be because I'm on master of gomobile). That error happens with javapkg, but it doesn't happen with my own code which now works properly thanks to golang/mobile#94
|
I was able build my project with:
Is there a chance that this will be fixed and I won’t have to use this crutch? |
@MagicalTux i can build project with: |
same issue:
result:
|
Any advance on this issue? No one care about it? |
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
)?go env
OutputWhat did you do?
gomobile bind golang.org/x/mobile/bind/testdata/testpkg/javapkg
Outputgomobile bind golang.org/x/mobile/bind/testdata/testpkg/objcpkg
OutputWhat did you expect to see?
build success
What did you see instead?
android and ios both failed
The text was updated successfully, but these errors were encountered: