Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mobile/bind/java: fatal error: jni.h: No such file or directory #58426

Open
dpanic opened this issue Feb 9, 2023 · 10 comments
Open

x/mobile/bind/java: fatal error: jni.h: No such file or directory #58426

dpanic opened this issue Feb 9, 2023 · 10 comments
Labels
mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@dpanic
Copy link

dpanic commented Feb 9, 2023

What version of Go are you using (go version)?

$ go version
go version go1.20 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

GOHOSTARCH="amd64"
GOHOSTOS="linux"

ANDROID_NDK_HOME=/home/dpanic/development/Android/Sdk/ndk/25.2.9519653
ANDROID_HOME=/home/dpanic/development/Android/Sdk

What did you do?

Binding Go Mobile project with following command:

CGO_ENABLED=1 \
        gomobile bind \
        -androidapi 23 \
        -target=android/$TARGET \
        -ldflags="-w -s" \
        -o export_$TARGET.aar \
        -v

What did you expect to see?

On Go version 1.19.5 and lower this works.

What did you see instead?

unable to import bind/java: [-: # golang.org/x/mobile/bind/java                         
/home/dpanic/go/pkg/mod/golang.org/x/mobile@v0.0.0-20221110043201-43a038452099/bind/java
/context_android.go:9:10: fatal error: jni.h: No such file or directory                 
    9 | //#include <jni.h>                                                              
      |          ^~~~~~~                                                                
compilation terminated.]                                                                
gomobile: /home/dpanic/go/bin/gobind -lang=go,java -outdir=/tmp/gomobile-work-1953076754
 example.com/export failed: exit status 1                                            
@seankhliao seankhliao changed the title affected/package: golang.org/x/mobile/bind/java x/mobile/bind/java: fatal error: jni.h: No such file or directory Feb 9, 2023
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Feb 9, 2023
@gopherbot gopherbot added this to the Unreleased milestone Feb 9, 2023
@dr2chase
Copy link
Contributor

@hyangah can you give this a look? It has a real "this could be a lot of things" look to it.

@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 10, 2023
@hyangah
Copy link
Contributor

hyangah commented Feb 14, 2023

Is it possible to post the log when running gomobile bind with -x -v flags?

@dpanic
Copy link
Author

dpanic commented Feb 14, 2023

GOMOBILE=/home/dpanic/go/pkg/gomobile
WORK=/tmp/gomobile-work-791525417
GOOS=android CGO_ENABLED=1 $GOPATH/bin/gobind -lang=go,java -outdir=$WORK REDACTED.com/export
unable to import bind/java: [-: # golang.org/x/mobile/bind/java
/home/dpanic/go/pkg/mod/golang.org/x/mobile@v0.0.0-20221110043201-43a038452099/bind/java/context_android.go:9:10: fatal error: jni.h:
No such file or directory
    9 | //#include <jni.h>
      |          ^~~~~~~
compilation terminated.]
rm -r -f "$WORK"
gomobile: /home/dpanic/go/bin/gobind -lang=go,java -outdir=/tmp/gomobile-work-791525417 REDACTED.com/export failed: exit status 1

@leo-lox
Copy link

leo-lox commented Feb 28, 2023

had the same issue for me the environment variable in PATH => C:\Program Files\OpenJDK\jdk-19.0.2\bin was missing.

  • make sure to run gomobile init again

@yiitz
Copy link

yiitz commented Mar 1, 2023

had the same issue with go 1.20.1, while it succeeded with go 1.19.6.

@dpanic
Copy link
Author

dpanic commented Mar 6, 2023

gomobile init solves the problem!

Thank you @leo-lox

@ChenSee
Copy link

ChenSee commented Mar 31, 2023

When encountering the same problem, gomobile init does not solve the problem.

@yiitz
Copy link

yiitz commented May 14, 2023

finally solved by upgrade golang.org/x/mobile to latest version.
go get -u golang.org/x/mobile

@chenxiaolong
Copy link

After doing a git bisect, this seems to happen when using go 1.20 with a version of gomobile that's missing golang/mobile@406ed3a. Relevant bug report: #56292.

(For folks who are using the gomobile version distributed in the Fedora repositories, I created a bug report to get that updated at: https://bugzilla.redhat.com/show_bug.cgi?id=2209147)

@ignoramous
Copy link

icymi: gomobile works on go1.21 just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

9 participants