- cmd跳转到我们刚写的文件的目录如:test_linux.go
2.设置在linux的运行环境,以下命令在cmd中执行
E:\gogo\main>adb shell getprop ro.product.cpu.abi #获取安卓手机的cpu信息
arm64-v8a
E:\gogo\main>set GOARCH=arm
E:\gogo\main>set GOOS=linux
E:\gogo\main>go build -o target-android test_linux.go
- 推送文件到安卓上并且adb shell中执行
E:\gogo\main>adb push ./target-android /data/local/tmp # 推送文件
./target-android: 1 file pushed. 7.7 MB/s (1957989 bytes in 0.244s)
E:\gogo\main>adb shell chmod 777 /data/local/tmp/target-android # 授权 直接777就是这么爽
E:\gogo\main>adb shell
shell@mx5:/ $ cd /data/local/tmp
shell@mx5:/data/local/tmp $ ./target-android
go runs onlinux
shell@mx5:/data/local/tmp $
//test_linux.go
package main
import (
"fmt"
"runtime"
)
func main(){
fmt.Print("go runs on")
switch os:=runtime.GOOS;os {
case "darwin":
fmt.Println("os x")
case "linux":
fmt.Println("linux")
default:
fmt.Println("%s.",os)
}
}
有疑问加站长微信联系(非本文作者)