gomobile: 命令未找到

huangapple go评论75阅读模式
英文:

gomobile: command not found

问题

我有一些用golang编写的代码,编译成aar并通过gomobile在Android应用程序中作为库使用。在我的Windows机器上,一切都正常工作,因为我已经正确配置了一切。现在我正在尝试使用GitHub Action自动化构建过程,并且在使用ubuntu时设置它时遇到了问题。我认为我遇到的问题与在ubuntu上设置PATH有关。

这是构建项目的工作流程:

on:
  push:
    branches:
      - main
      - actions

name: "Build & Release"
jobs:
  generate:
    name: Generate codes
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-go@v3
        with:
          go-version: '1.18'

      - uses: actions/setup-java@v2
        with:
          distribution: 'zulu'
          java-version: '11'

      - name: Installing go server dependencies
        working-directory: server
        run: |
                    go install

      - name: setup-android-tools
        uses: maxim-lobanov/setup-android-tools@v1
        with:
          packages: ndk;19.2.5345600

      - name: Build aar
        working-directory: server
        run: |
          go get -d golang.org/x/mobile/cmd/gomobile
          gomobile init
          gomobile bind -v -o ../client/app/libs/server.aar -target=android ./lib          

      - name: Push aar to release
        uses: ncipollo/release-action@v1
        with:
          artifacts: "${{ matrix.dir }}/client/app/libs/*aar"
          tag: v1.0.${{ github.run_number }}
          token: ${{ secrets.GITHUB_TOKEN }}


以下是由setup-go打印的Go环境变量:

  GO111MODULE=""
  GOARCH="amd64"
  GOBIN=""
  GOCACHE="/home/runner/.cache/go-build"
  GOENV="/home/runner/.config/go/env"
  GOEXE=""
  GOEXPERIMENT=""
  GOFLAGS=""
  GOHOSTARCH="amd64"
  GOHOSTOS="linux"
  GOINSECURE=""
  GOMODCACHE="/home/runner/go/pkg/mod"
  GONOPROXY=""
  GONOSUMDB=""
  GOOS="linux"
  GOPATH="/home/runner/go"
  GOPRIVATE=""
  GOPROXY="https://proxy.golang.org,direct"
  GOROOT="/opt/hostedtoolcache/go/1.18.2/x64"
  GOSUMDB="sum.golang.org"
  GOTMPDIR=""
  GOTOOLDIR="/opt/hostedtoolcache/go/1.18.2/x64/pkg/tool/linux_amd64"
  GOVCS=""
  GOVERSION="go1.18.2"
  GCCGO="gccgo"
  GOAMD64="v1"
  AR="ar"
  CC="gcc"
  CXX="g++"
  CGO_ENABLED="1"
  GOMOD="/dev/null"
  GOWORK=""
  CGO_CFLAGS="-g -O2"
  CGO_CPPFLAGS=""
  CGO_CXXFLAGS="-g -O2"
  CGO_FFLAGS="-g -O2"
  CGO_LDFLAGS="-g -O2"
  PKG_CONFIG="pkg-config"
  GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1913149098=/tmp/go-build -gno-record-gcc-switches"

以下是执行gomobile时出现的实际错误:

go: downloading golang.org/x/mobile v0.0.0-20220518205345-8578da9835fd
go: downloading golang.org/x/mod v0.4.2 go: downloading
golang.org/x/tools v0.1.8-0.20211022200916-316ba0b74098 go:
downloading golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
go: upgraded golang.org/x/mobile v0.0.0-20220504144722-50dca8fc073d =>
v0.0.0-20220518205345-8578da9835fd
/home/runner/work/_temp/8ee34a1b-b28d-4781-9668-9aa41d593cce.sh: line
2: gomobile: command not found

如何成功使用GitHub Action构建aar?任何帮助将不胜感激。

这是该项目的GitHub存储库

英文:

I have some codes written in golang which is compiled to aar and used as library in android app via gomobile. On my windows machine everything works well as I have everything configured correctly. Now I am trying to automate the build process using GitHub action and having trouble setting it up using ubuntu. The problems I am having I believe they are associated with setting PATH which on ubuntu.

Here is my workflow for building my project

on:
  push:
    branches:
      - main
      - actions

name: "Build & Release"
jobs:
  generate:
    name: Generate codes
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-go@v3
        with:
          go-version: '1.18'

      - uses: actions/setup-java@v2
        with:
          distribution: 'zulu'
          java-version: '11'

      - name: Installing go server dependencies
        working-directory: server
        run: |
                    go install

      - name: setup-android-tools
        uses: maxim-lobanov/setup-android-tools@v1
        with:
          packages: ndk;19.2.5345600

      - name: Build aar
        working-directory: server
        run: |
          go get -d golang.org/x/mobile/cmd/gomobile
          gomobile init
          gomobile bind -v -o ../client/app/libs/server.aar -target=android ./lib          

      - name: Push aar to release
        uses: ncipollo/release-action@v1
        with:
          artifacts: "${{ matrix.dir }}/client/app/libs/*aar"
          tag: v1.0.${{ github.run_number }}
          token: ${{ secrets.GITHUB_TOKEN }}


The following is Go ENV as printed by setup-go

  GO111MODULE=""
  GOARCH="amd64"
  GOBIN=""
  GOCACHE="/home/runner/.cache/go-build"
  GOENV="/home/runner/.config/go/env"
  GOEXE=""
  GOEXPERIMENT=""
  GOFLAGS=""
  GOHOSTARCH="amd64"
  GOHOSTOS="linux"
  GOINSECURE=""
  GOMODCACHE="/home/runner/go/pkg/mod"
  GONOPROXY=""
  GONOSUMDB=""
  GOOS="linux"
  GOPATH="/home/runner/go"
  GOPRIVATE=""
  GOPROXY="https://proxy.golang.org,direct"
  GOROOT="/opt/hostedtoolcache/go/1.18.2/x64"
  GOSUMDB="sum.golang.org"
  GOTMPDIR=""
  GOTOOLDIR="/opt/hostedtoolcache/go/1.18.2/x64/pkg/tool/linux_amd64"
  GOVCS=""
  GOVERSION="go1.18.2"
  GCCGO="gccgo"
  GOAMD64="v1"
  AR="ar"
  CC="gcc"
  CXX="g++"
  CGO_ENABLED="1"
  GOMOD="/dev/null"
  GOWORK=""
  CGO_CFLAGS="-g -O2"
  CGO_CPPFLAGS=""
  CGO_CXXFLAGS="-g -O2"
  CGO_FFLAGS="-g -O2"
  CGO_LDFLAGS="-g -O2"
  PKG_CONFIG="pkg-config"
  GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1913149098=/tmp/go-build -gno-record-gcc-switches"

And the following is the actual error I get when executing gomobile

> go: downloading golang.org/x/mobile v0.0.0-20220518205345-8578da9835fd
> go: downloading golang.org/x/mod v0.4.2 go: downloading
> golang.org/x/tools v0.1.8-0.20211022200916-316ba0b74098 go:
> downloading golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
> go: upgraded golang.org/x/mobile v0.0.0-20220504144722-50dca8fc073d =>
> v0.0.0-20220518205345-8578da9835fd
> /home/runner/work/_temp/8ee34a1b-b28d-4781-9668-9aa41d593cce.sh: line
> 2: gomobile: command not found

How can I successifully build aar using github action. Any help will be appreciated.

Here is GitHub repository for this project.

答案1

得分: 1

我建议在设置好Go语言环境后,使用以下步骤配置gomobile

- name: 安装 Gomobile
  run: |
      go install golang.org/x/mobile/cmd/gomobile@latest
      go install golang.org/x/mobile/cmd/gobind@latest
      go get golang.org/x/mobile/cmd/gobind
      go get golang.org/x/mobile/cmd/gomobile
      gomobile init      
   env:
      GOPROXY: https://proxy.golang.org,direct
      GO111MODULE: "on"

如果这样还不起作用,我很乐意进一步研究并在您的 GitHub 存储库中提出修复方案 gomobile: 命令未找到

英文:

I would recommend using this step to configure gomobile once you setup Go on your runner:

- name: Install Gomobile
  run: |
      go install golang.org/x/mobile/cmd/gomobile@latest
      go install golang.org/x/mobile/cmd/gobind@latest
      go get golang.org/x/mobile/cmd/gobind
      go get golang.org/x/mobile/cmd/gomobile
      gomobile init      
   env:
      GOPROXY: https://proxy.golang.org,direct
      GO111MODULE: "on"

If it doesn't work out, I would be happy to look into this further and raise a fix on your GitHub repository itself gomobile: 命令未找到

答案2

得分: 0

请从这里(https://go.dev/dl/)下载并安装go
打开命令提示符,输入go install golang.org/x/mobile/cmd/gomobile@latest
下载完成后,执行gomobile init命令。

英文:

download & install go from here ( https://go.dev/dl/ )
open cmd type go install golang.org/x/mobile/cmd/gomobile@latest
after download gomobile init work.

huangapple
  • 本文由 发表于 2022年5月29日 17:43:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/72422550.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定