Bug 2209147 - Fails when targeting Android after go 1.20 upgrade (upstream patch available)
Summary: Fails when targeting Android after go 1.20 upgrade (upstream patch available)
Keywords:
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: golang-x-mobile
Version: 38
Hardware: All
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Robert-André Mauchin 🐧
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-05-22 20:46 UTC by Andrew Gunnerson
Modified: 2023-05-22 20:46 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: ---
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Andrew Gunnerson 2023-05-22 20:46:42 UTC
When targeting Android, gomobile fails with:

    ../../../../go/pkg/mod/golang.org/x/mobile.0-20230427221453-e8d11dd0ba41/bind/java/context_android.go:9:10: fatal error: jni.h: No such file or directory
        9 | //#include <jni.h>
          |          ^~~~~~~

This was fixed by upstream commit: https://github.com/golang/mobile/commit/406ed3a7b8e44dc32844953647b49696d8847d51 (bug report: https://github.com/golang/go/issues/56292).

Would it be possible to update golang-x-mobile to the latest commit to include the fix?

Reproducible: Always

Steps to Reproduce:
I made the smallest possible "hello world" reproducer to test this:

1. git clone https://gist.github.com/chenxiaolong/704f194de17acfd264d0f7e7b8f3d7fa.git
2. cd 704f194de17acfd264d0f7e7b8f3d7fa
3. gomobile bind -target=android
Actual Results:  
❯ gomobile bind -target=android  
gomobile: /usr/bin/gobind -lang=go,java -outdir=/tmp/gomobile-work-462524014 reproducer failed: exit status 1
unable to import bind/java: [-: # golang.org/x/mobile/bind/java
/home/chenxiaolong/go/pkg/mod/golang.org/x/mobile.0-20230427221453-e8d11dd0ba41/bind/java/context_android.go:9:10: fatal error: jni.h: No such file or directory
    9 | //#include <jni.h>
      |          ^~~~~~~
compilation terminated.]


Expected Results:  
Successfully builds.

Simply updating the version to the latest solves the problem as the fix commit mentioned above was already merged. Locally, I tested by applying the following patch to spec file:

diff --git a/golang-x-mobile.spec b/golang-x-mobile.spec
index f7046a6..681e1c9 100644
--- a/golang-x-mobile.spec
+++ b/golang-x-mobile.spec
@@ -4,7 +4,7 @@
 # https://github.com/golang/mobile
 %global goipath         golang.org/x/mobile
 %global forgeurl        https://github.com/golang/mobile
-%global commit          8578da9835fd365e78a6e63048c103b27a53a82c
+%global commit          e8d11dd0ba418c197516129aa6810a4ce81dc365
 
 %gometa
 
@@ -40,6 +40,9 @@ BuildRequires:  pkgconfig(openal)
 %generate_buildrequires
 %go_generate_buildrequires
 
+# The tests fail due to unexpanded $GOPATH when it is set
+sed -i 's,\$GOPATH,{{.GOPATH}},g' cmd/gomobile/build_test.go
+
 %build
 for cmd in cmd/* ; do
   %gobuild -o %{gobuilddir}/bin/$(basename $cmd) %{goipath}/$cmd
@@ -61,7 +64,7 @@ install -m 0755 -vp %{gobuilddir}/bin/* %{buildroot}%{_bindir}/
 
 %files
 %license PATENTS LICENSE
-%doc doc example AUTHORS CONTRIBUTING.md README.md CONTRIBUTORS exp/README
+%doc doc example CONTRIBUTING.md README.md exp/README
 %{_bindir}/*
 
 %gopkgfiles


Note You need to log in before you can comment on or make changes to this bug.