|
1 | | -# Ditching GoMobile: Building Our Own Native Bridge |
| 1 | +# Hello Blog (coming soon) |
2 | 2 |
|
3 | | -For the longest time, we used `gomobile` to bridge our Go-based core with Android and iOS. It seemed like the perfect solution—generate bindings, avoid boilerplate, and focus on logic. But as **our product matured**, `gomobile` started showing its cracks. |
4 | | - |
5 | | -## Why We Used GoMobile in the First Place |
6 | | - |
7 | | -- Automatic generation of Java and Objective-C bindings |
8 | | -- Easy method export from Go |
9 | | -- Quick prototype integration for cross-platform logic |
10 | | - |
11 | | -But then reality hit. |
12 | | - |
13 | | -## The Problems |
14 | | - |
15 | | -- **Missing modern language support:** No Kotlin coroutines, no Swift async/await |
16 | | -- **Limited threading model:** Everything ran on a single locked thread |
17 | | -- **Opaque crashes:** Stack traces from `gomobile` were cryptic and unhelpful |
18 | | -- **No support for streaming, async calls, or cancellation** |
19 | | -- **Hard to debug JNI/ObjC glue code** |
20 | | - |
21 | | -Worst of all: **gomobile was abandoned**. No meaningful updates in years, yet we were depending on it. |
22 | | - |
23 | | - |
24 | | - |
25 | | -## What We Built Instead |
26 | | - |
27 | | -We now use a **custom native bridge**, powered by: |
28 | | - |
29 | | - |
30 | | - |
31 | | -- ✨ **Protobuf for typed request/response definitions** |
32 | | -- 🧵 **Cancellable async calls** (Kotlin coroutines, Swift async/await) |
33 | | -- 🔄 **Bidirectional communication** (platform ↔ core) |
34 | | -- 🧩 **Manually managed JNI and Objective-C glue code** |
35 | | -- 🔍 **Full control over threading and memory** |
36 | | - |
37 | | -The bridge consists of: |
38 | | - |
39 | | -1. A **Go core** that registers all callable methods |
40 | | -2. A **native dispatcher** on each platform that routes Protobuf messages |
41 | | -3. Typed messages and responses, fully testable |
42 | | -4. Direct hooks into Go’s panic handler (with stacktrace propagation) |
43 | | - |
44 | | -## The Benefits |
45 | | - |
46 | | -- 🔥 No more silent crashes |
47 | | -- 📱 Proper threading and cancellation |
48 | | -- 📦 Much smaller binary size |
49 | | -- 🛠 Full debugging capabilities |
50 | | -- 🚀 Faster startup and method invocation |
51 | | - |
52 | | -## Example: Calling from Kotlin |
53 | | - |
54 | | -```kotlin |
55 | | -val request = GetMediaRequest.newBuilder().build() |
56 | | -val response = nativeBridge.callGo(METHOD_GET_MEDIA, request.toByteArray()) |
57 | | -``` |
| 3 | +Coming soon! |
0 commit comments