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

Failed to Build for Android on Go v1.23.1 Using anet Package #7

Closed
Ja7ad opened this issue Sep 28, 2024 · 7 comments · Fixed by #8
Closed

Failed to Build for Android on Go v1.23.1 Using anet Package #7

Ja7ad opened this issue Sep 28, 2024 · 7 comments · Fixed by #8

Comments

@Ja7ad
Copy link

Ja7ad commented Sep 28, 2024

Hello, Thank you for your package.

I'm encountering a build error when attempting to compile a Go project targeting Android (GOOS=android, GOARCH=arm64) using the anet package. The following code reproduces the issue:

package main

import (
	"fmt"
	"log"
	"github.com/wlynxg/anet"
)

func main() {
	i, err := anet.Interfaces()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(i)
}

Command used:

CGO_ENABLED=0 GOOS=android GOARCH=arm64 go build -ldflags "-s -w -checklinkname=0" main.go

Error:

# command-line-arguments
./main.go:10:17: undefined: anet.Interfaces

It appears the anet.Interfaces function is not available during the build process. This issue might be related to how the package handles platform-specific code.

Environment:

  • Go version: 1.23.1
  • Target platform: Android (ARM64)
  • Package: anet (latest version)

Any insights or solutions would be appreciated.

@Ja7ad Ja7ad changed the title failed to build for android in go v1.23.1 Failed to Build for Android on Go v1.23.1 Using anet Package Sep 28, 2024
@wlynxg
Copy link
Owner

wlynxg commented Sep 29, 2024

In order to automatically obtain the Android version number, CGO is used in the Android code.
The code is at:

// #include <android/api-level.h>

@wlynxg
Copy link
Owner

wlynxg commented Sep 29, 2024

Perhaps we should support manually setting the Android version without using CGO? @bobrofon

@Ja7ad
Copy link
Author

Ja7ad commented Oct 2, 2024

In order to automatically obtain the Android version number, CGO is used in the Android code. The code is at:

// #include <android/api-level.h>

We build android version on older version of go, without any issue on build.

https://github.com/pactus-project/pactus/releases/tag/v1.4.0

Package used:

@bobrofon
Copy link
Contributor

bobrofon commented Oct 2, 2024

We build android version on older version of go, without any issue on build.

I reproduced the same build error on go 1.22.7. It doesn't seem that the go version is relevant.

@b00f
Copy link

b00f commented Oct 3, 2024

It make sense, since I can't see anet in older version of Pactus here
This way we can't support Android anymore!?

@bobrofon
Copy link
Contributor

bobrofon commented Oct 3, 2024

This way we can't support Android anymore!?

There is an open PR #8 fixing this issue.
Or you can just build Pactus with anet from this commit 4d6caa2. It should work as well.

@b00f
Copy link

b00f commented Oct 3, 2024

Thanks for the quick response and for promptly fixing the issue.

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

Successfully merging a pull request may close this issue.

4 participants