Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you bind multiple packages into a single Java AAR file using gomobile?

I'm getting the error message no exported names in the package when trying to run the command gomobile bind -target=android github.com/nknorg/nkn-sdk-go github.com/nknorg/ncp-go.

The goal is to generate a .aar file from the Go libraries nkn-sdk-go and ncp-go so that the .aar file can be imported into an Android project. I was able to generate the .aar files for each library individually by downloading the repos, moving into their root directories, and running the command gomobile bind -target=android .. However, when trying to run the command for multiple packages (locally or externally) or from outside of the downloaded library's directory (e.g. gomobile bind -target=android nkn-sdk-go), I get the above error message.

I'm running Go version 1.15.5 with NDK version 21.3.6528147 on Windows 10. Any ideas on what the issue could be?

like image 897
block orchid Avatar asked Oct 30 '25 02:10

block orchid


1 Answers

The issue was caused by not running the command within a directory that had been initialised as a go module. I solved the problem by performing the following steps:

  1. Create a directory anywhere outside of the $GOPATH/src directory.

mkdir <my-module>

  1. Move into the newly created directory.

cd <my-module>

  1. Initialise the directory as a go module.

go mod init <my.module.identifier>

  1. Bind the packages to generate the .aar file.

gomobile bind -target=android <github.com/package1> <github.com/package2> ...

like image 120
block orchid Avatar answered Oct 31 '25 18:10

block orchid