我有一个相当简单的应用程序,理论上应该使用 Android Java API 来获取位置(受此答案的启发):
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()
}
但是我无法让它与 build 命令一起使用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 绑定没有生成,所以我想知道让它工作的第一步是什么?