【发布时间】:2021-03-24 10:43:00
【问题描述】:
我有一个相当简单的应用程序,理论上应该使用 Android Java API 来获取位置(灵感来自 this 答案):
package main
import (
"Java/android/content/Context"
"Java/android/location/LocationManager"
"fyne.io/fyne/app"
"fyne.io/fyne/widget"
)
func GetLocation() string {
locationManager := ctx.GetSystemService(Context.LOCATION_SERVICE)
location := locationManager.GetLastKnownLocation(LocationManager.GPS_PROVIDER)
lat := location.GetLatitude()
lng := location.GetLongitude()
return fmt.Sprintf("%f:%f", lat, lng)
}
func main() {
a := app.New()
w := a.NewWindow("Location")
loc := widget.NewLabel("Location defined " + GetLocation())
w.SetContent(widget.NewVBox(
loc,
))
w.ShowAndRun()
}
但我无法以fyne package -os android -appID com.user.fynedemo -icon icon.png 的形式使用构建命令 - 它失败并出现错误:
fyne package -os android -appID com.jdevelop.fynedemo -icon 1x1-00000000.png
go build -buildmode=c-shared -o /tmp/gomobile-work-028676736/lib/armeabi-v7a/libfynedemo.so fynedemo failed: exit status 1
a.go:3:8: package Java/android/content/Context is not in GOROOT (/usr/lib/go/src/Java/android/content/Context)
a.go:4:8: package Java/android/location/LocationManager is not in GOROOT (/usr/lib/go/src/Java/android/location/LocationManager)
在我看来,Go->Java 绑定似乎没有生成,所以我想知道要让它工作的第一步是什么?
【问题讨论】: