DEV Community

Girish Koundinya
Girish Koundinya

Posted on

1

A Three Step Recipe for using Gomobile

This post was originally published in blog.koundinya.xyz

In my earlier post, we saw different ways in which we can use Gomobile. In this post I'll try illustrating how to incorporate Gomobile into a mobile application using the bind command.

Prerequisites

  1. Ensure that you've setup Go and Gomobile in your machine

  2. Install NDK (If you are generating a Android library)

Three Step Recipe

Step 1 - Write a Go Package
  1. Create a go package in $GOPATH/src/github.com/$username/gomobile_contact

  2. Create the following files

In the above linked files I've made a network request, parsed the response and unmarshalled it into a Contact object and returned the first Contact's name. This is an example of a simple business logic component that can be written in Go and ported as a library.

Step 2 - Generate libraries

Use the following commands to generate libraries for iOS / Android applications

    gomobile bind --target=ios #ios
    gomobile bind --target=android #android
```

`


#####  Step 3 - Import library into Application

Gomobile generates a .aar/jar for Android and .Framework for iOS

Import the packages into your application and call the `FetchContactName()` method which returns the first contact's name.

Voilà! You've succesfully generated a library using Go and integrated into your application :)

<br>
Enter fullscreen mode Exit fullscreen mode

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay