- install the android ndk: https://developer.android.com/studio/projects/install-ndk
- install java 11:
brew tap homebrew/cask-versions
brew install --cask temurin11
mkdir demo
cd demo
go mod init github.com/fdelbos/demo
In this package create a demo.go
file with the following:
package demo
type (
Demo interface {
Hello(string) string
}
srv struct{}
)
func NewDemo() Demo {
return &srv{}
}
func (s *srv) Hello(name string) string {
return "Hello " + name
}
- get the mobile tooling:
go get golang.org/x/mobile/bind
- build:
mkdir -p build && \
gomobile bind \
-o build/demo.aar \
-target=android \
-androidapi 30 \
github.com/fdelbos/demo
You should get the following:
ls -lah build/
total 5
drwxr-xr-x 4 fred staff 128B Apr 20 12:39 .
drwxr-xr-x 6 fred staff 192B Apr 20 12:39 ..
-rw-r--r-- 1 fred staff 5.7K Apr 20 12:39 demo-sources.jar
-rw-r--r-- 1 fred staff 4.8M Apr 20 12:39 demo.aar
- Add the dependency in the ** app / libs ** folder
- In an existing project, click on: File > Project Structure > Dependencies
- set the AAR path
- In Graddle you should have a new line for your dependency:
- Now you can update your code to use the new library:
- Check on the emulator