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/cmd/gomobile: fail to gomobile build
as "not a valid go package name"
#24511
Comments
https://developer.android.com/guide/topics/manifest/manifest-element.html#package
You cannot have a package named 12345 on android. |
The package name for Android is automatically generated by |
Sorry, I tried to compile a normal go package named 12345 and that failed too. So this isn't related to gomobile. From reading the spec https://golang.org/ref/spec it described that package names must start with a letter.
|
Package path |
/cc @hyangah |
gomobile build
as "not a valid go package name"gomobile build
as "not a valid go package name"
b39ed682d87b8df3698bcbc8fbaff91efbaa9d17 The package name for android is determined at |
I've created a change, diff --git a/cmd/gomobile/build_androidapp.go b/cmd/gomobile/build_androidapp.go
index a1f07cb..b4629b1 100644
--- a/cmd/gomobile/build_androidapp.go
+++ b/cmd/gomobile/build_androidapp.go
@@ -287,20 +287,15 @@ func goAndroidBuild(pkg *build.Package, androidArchs []string) (map[string]bool,
// but not exactly same.
func androidPkgName(name string) string {
var res []rune
- for i, r := range name {
+ for _, r := range name {
switch {
- case 'a' <= r && r <= 'z', 'A' <= r && r <= 'Z':
- res = append(res, r)
- case '0' <= r && r <= '9':
- if i == 0 {
- panic(fmt.Sprintf("package name %q is not a valid go package name", name))
- }
+ case 'a' <= r && r <= 'z', 'A' <= r && r <= 'Z', '0' <= r && r <= '9':
res = append(res, r)
default:
res = append(res, '_')
}
}
- if len(res) == 0 || res[0] == '_' {
+ if len(res) == 0 || res[0] == '_' || ('0' <= res[0] && res[0] <= '9') {
// Android does not seem to allow the package part starting with _.
res = append([]rune{'g', 'o'}, res...)
}
diff --git a/cmd/gomobile/build_test.go b/cmd/gomobile/build_test.go
index b09a167..e89764c 100644
--- a/cmd/gomobile/build_test.go
+++ b/cmd/gomobile/build_test.go
@@ -54,6 +54,7 @@ func TestAndroidPkgName(t *testing.T) {
{".-.", "go___"},
{"abstract", "abstract_"},
{"Abstract", "Abstract"},
+ {"12345", "go12345"},
}
for _, tc := range tests { but
🤔 |
https://go-review.googlesource.com/c/mobile/+/102576
|
It's fixed (the gobot doesn't notify this, but I think this is because my git-push way is special) |
It was because of https://go-review.googlesource.com/c/mobile/+/102576/4//COMMIT_MSG#15. |
What version of Go are you using (
go version
)?go version go1.10 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?What did you do?
Create $GOPATH/src/github.com/hajimehoshi/12345 (the last directory name is invalid as a package name)
Create $GOPATH/github.com/hajimehoshi/12345/main.go like
gomobile build github.com/hajimehoshi/12345
What did you expect to see?
Build succeed
What did you see instead?
The text was updated successfully, but these errors were encountered: