Does anybody know how does gomobile build (not bind) support FileSystem? I was able to use the asset package for opening and reading files as discussed in this discussion .
But not sure how I can create an write to new files in an APK file generated by gomobile I am able to run the following ample code in Go and verify that the "testFile.txt" is created with the provided message.
message := []byte("Hello, testing!")
err := ioutil.WriteFile("testFile.txt", message, 0777)
if err != nil {
fmt.Println(err)
}
But after generating APK file and running it on a tablet (Android) I get the file access error as below and the "testFile.txt" is not created.
I/GoLog: open testFile.txt: read-only file system
Any hint is appreciated.
$ go version
go version go1.16.3 windows/amd64
NA
Windows 10 Pro
go env Output
$ go env
set GO111MODULE=auto
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\instu\AppData\Local\go-build
set GOENV=C:\Users\instu\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\instu\OneDrive\Desktop\go-workSpace\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\instu\OneDrive\Desktop\go-workSpace
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Projects\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Projects\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16.3
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\instu\OneDrive\Desktop\go-workSpace\src\Minicloud\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\instu\AppData\Local\Temp\go-build2510967962=/tmp/go-build -gno-record-gcc-switches
Described in original question section, but in summary I need to add a function which is able to write logs into an installed micro-SD card on the Samsung S6 lite tablet. Here is the sample code i followed to write a file in Go. it works when i run go, but i experience the read-only error message after generating and installing APK file on Tablet
Expect that Android app (installed as an APK file generated by gomobile build) is able to create a file and write to the created file
read-only error message.
I/GoLog: open testFile.txt: read-only file system
This sample code works for me (to write to internal storage):
func storeLog(fileDir string, fileName string, msg string) {
msgByte := []byte(msg)
file, err := os.Create(fileDir + fileName)
if err != nil
fmt.Printf(err)
defer file.Close()
numB, err := file.Write(msgByte)
if err != nil
fmt.Printf(err)
enter code here
fmt.Printf("wrote %d bytes\n", numB)
}
Just need to make sure to :
adb -s <deviceID> shell echo $EXTERNAL_STORAGE
adb devices
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.