DEV Community

Girish Koundinya
Girish Koundinya

Posted on • Updated on

Go Mobile Introduction to Gomobile

This post was originally published in blog.koundinya.xyz

When someone reads about the Go programming language, they would probably come across Rob Pike’s famous 'Concurrency Is Not Parallelism' talk or they might discover that Docker and Kubernetes and many other cloud infra tools have been written in Go (Go has been dubbed 'The Language of the Cloud'). I want to write about one of Go's lesser known tool in the box - Gomobile. Gomobile is a mobile application development tool written in Go, built with the aim of developing cross-platform applications.

Why would you try Gomobile?

I can hear your collective groan, 'Not another Cross Platform Mobile Development Solution'. And I agree, and infact I would want to lend my voice to it. Sometimes the benefit of having a single codebase pales in comparison to the sub par experience provided by cross platform frameworks.

So why are we talking about Gomobile then?

Gomobile provides two strategies for development

  1. To develop an entire mobile application using -
    gomobile build

  2. To develop a library that can be used by mobile applications using -
    gomobile bind

Using Gomobile as a generator for SDKs that can be plugged into applications is very similar to how companies are Google and Dropbox are approaching cross-platform development. Google used J2OBJC in Inbox
and Dropbox has Djinni.
gomobile bind is an option if your application has a lot of business logic that you don't want to rewrite in multiple platforms.

Gomobile bind

gomobile bind generates language bindings for Java and Objective-C. A simple pattern for developing mobile applications using bind would be develop the view layer in the native language and then communicate with the generated sdk to obtain model objects.

Mobile App Architecture

There are quite a few mobile application architecture patterns in Android and iOS like MVC, MVP, MVVM, and VIPER. All of these architectural designs can be broadly represented by three layers.

![Mobile App Architecture](https://blog.koundinya.xyz/images/mobile+arch.png)
View Layer

This layer is responsible for user interaction and rendering of data. Activity and ViewController classes in Android and iOS respectively are types of classes that are normally associated with this layer.

Business Logic Layer

This layer contains the core application logic. The interactions from the view are sent to this layer, which is processed and used to make calls to the data layer.

Data Layer

The data layer controls all of the data access operations. This can be anything from accessing a local SQLite database to interacting with the network.

![Mobile App Architecture With Gomobile](https://blog.koundinya.xyz/images/mobile+go+arch.png)

With gomobile bind, the business logic and data layers can be moved to Go and shared between iOS and Android applications. This way business logic needs to be written only once and the data access protocols are similar between operating systems. You also don’t lose out on the user experience which is a common drawback in most cross platform solutions.

References

Here are some references that you might find interesting to get started with Gomobile

  1. https://godoc.org/golang.org/x/mobile/cmd/gomobile
  2. https://www.youtube.com/watch?v=ZLq0Zeoyu6Y
  3. https://medium.com/@matryer/tutorial-calling-go-code-from-swift-on-ios-and-vice-versa-with-gomobile-7925620c17a4
  4. https://medium.com/@rakyll/calling-go-from-swift-be88709942c3

Top comments (3)

Collapse
 
bssankaran profile image
Sankaran Srinivasan

Is gomobile production grade? I'm planning to develop an IOS app which might reused in android in future. I need the gomobile bind feature, but just worried if there would be enough community support.

Collapse
 
_tink3r profile image
Girish Koundinya

Hello!

Gomobile does lack the community that flutter or react native have, but i have found that the Github issues are usually attended to and you can always reach out to people on the mailing list. It does definitely lack the roadmap and vision that other cross platform solutions have.

Production grade? I am not sure I can answer that, but I do know a couple of companies using this Gomobile in production.

Hope this helps :)

Collapse
 
daleemoore profile image
Dale E. Moore

FYI your Reference to medium.com/@rakyll/calling-go-from... no longer exists. I'm getting "Error 410 The author deleted this Medium story."